Skip to content

Commit

Permalink
Valgrind 7: avoid invalid reads in read_wpt
Browse files Browse the repository at this point in the history
...while coping files that are empty or begin with  null zero
#248 (comment)
  • Loading branch information
yakra committed Jul 9, 2021
1 parent 575f444 commit 0822708
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion siteupdate/cplusplus/classes/Route/read_wpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ void Route::read_wpt(WaypointQuadtree *all_waypoints, ErrorList *el, bool usa_fl
{ for (spn = strcspn(c, "\n\r"); c[spn] == '\n' || c[spn] == '\r'; spn++) c[spn] = 0;
lines.emplace_back(c);
}
if (lines.empty())
{ delete[] wptdata;
el->add_error(filename + " is empty or begins with null zero");
}
lines.push_back(wptdata+wptdatasize+1); // add a dummy "past-the-end" element to make lines[l+1]-2 work

// process lines
for (unsigned int l = 0; l < lines.size()-1; l++)
for (unsigned int l = lines[1] < wptdata+2; l < lines.size()-1; l++)
{ // strip whitespace from end...
char* endchar = lines[l+1]-2; // -2 skips over the 0 inserted while splitting wptdata into lines
while (*endchar == 0) endchar--; // skip back more for CRLF cases, and lines followed by blank lines
Expand Down

0 comments on commit 0822708

Please sign in to comment.