From 08227082424154b3fca48d5253447df97a4ed7bc Mon Sep 17 00:00:00 2001 From: eric bryant Date: Fri, 9 Jul 2021 17:16:28 -0400 Subject: [PATCH] Valgrind 7: avoid invalid reads in read_wpt ...while coping files that are empty or begin with null zero https://github.com/TravelMapping/DataProcessing/issues/248#issuecomment-877359437 --- siteupdate/cplusplus/classes/Route/read_wpt.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/siteupdate/cplusplus/classes/Route/read_wpt.cpp b/siteupdate/cplusplus/classes/Route/read_wpt.cpp index 1557a7ed..7af7f8de 100644 --- a/siteupdate/cplusplus/classes/Route/read_wpt.cpp +++ b/siteupdate/cplusplus/classes/Route/read_wpt.cpp @@ -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