From 23bc00e1a19b7404a2b5cfb441ddf0f8eac9e4fb Mon Sep 17 00:00:00 2001 From: wmayer Date: Wed, 13 Mar 2019 13:34:45 +0100 Subject: [PATCH] PVS: V1024 The 'file' stream is checked for EOF before reading from it, but is not checked after reading. Potential use of invalid data --- src/Mod/Drawing/App/FeaturePage.cpp | 6 ++---- src/Mod/Drawing/Gui/TaskOrthoViews.cpp | 4 +--- src/Mod/Raytracing/App/LuxProject.cpp | 3 +-- src/Mod/Raytracing/App/RayProject.cpp | 3 +-- src/Mod/TechDraw/App/DrawSVGTemplate.cpp | 6 ++---- src/Mod/TechDraw/Gui/QGISVGTemplate.cpp | 3 +-- 6 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/Mod/Drawing/App/FeaturePage.cpp b/src/Mod/Drawing/App/FeaturePage.cpp index ef94d2a6ac..12f83296ed 100644 --- a/src/Mod/Drawing/App/FeaturePage.cpp +++ b/src/Mod/Drawing/App/FeaturePage.cpp @@ -155,9 +155,8 @@ App::DocumentObjectExecReturn *FeaturePage::execute(void) ostringstream ofile; string tempendl = "--endOfLine--"; - while (!file.eof()) + while (getline (file,line)) { - getline (file,line); // check if the marker in the template is found if(line.find("") == string::npos) // if not - write through @@ -259,8 +258,7 @@ std::vector FeaturePage::getEditableTextsFromTemplate(void) const { } string tline, tfrag; ifstream tfile (tfi.filePath().c_str()); - while (!tfile.eof()) { - getline (tfile,tline); + while (getline (tfile,tline)) { tfrag += tline; tfrag += "--endOfLine--"; } diff --git a/src/Mod/Drawing/Gui/TaskOrthoViews.cpp b/src/Mod/Drawing/Gui/TaskOrthoViews.cpp index e1c90e27a4..7c66665d79 100644 --- a/src/Mod/Drawing/Gui/TaskOrthoViews.cpp +++ b/src/Mod/Drawing/Gui/TaskOrthoViews.cpp @@ -88,10 +88,8 @@ void pagesize(string & page_template, int dims[4], int block[4]) try { - while (!file.eof()) + while (getline (file,line)) { - getline (file,line); - if (line.find("" diff --git a/src/Mod/Raytracing/App/LuxProject.cpp b/src/Mod/Raytracing/App/LuxProject.cpp index 62ac8c353f..61f72f1db0 100644 --- a/src/Mod/Raytracing/App/LuxProject.cpp +++ b/src/Mod/Raytracing/App/LuxProject.cpp @@ -87,8 +87,7 @@ App::DocumentObjectExecReturn *LuxProject::execute(void) ofstream ofile(tempName.c_str()); // copy the input of the resource file - while (!file.eof()) { - getline (file,line); + while (getline (file,line)) { // check if the marker in the template is found if(line.find("#RaytracingContent") == string::npos) { if(line.find("#RaytracingCamera") == string::npos) { diff --git a/src/Mod/Raytracing/App/RayProject.cpp b/src/Mod/Raytracing/App/RayProject.cpp index 302d4e1939..7af2832c40 100644 --- a/src/Mod/Raytracing/App/RayProject.cpp +++ b/src/Mod/Raytracing/App/RayProject.cpp @@ -86,8 +86,7 @@ App::DocumentObjectExecReturn *RayProject::execute(void) ofstream ofile(tempName.c_str()); // copy the input of the resource file - while (!file.eof()) { - getline (file,line); + while (getline (file,line)) { // check if the marker in the template is found if(line.find("//RaytracingContent") == string::npos) // if not - write through diff --git a/src/Mod/TechDraw/App/DrawSVGTemplate.cpp b/src/Mod/TechDraw/App/DrawSVGTemplate.cpp index 89c28b9121..2e5a8fe959 100644 --- a/src/Mod/TechDraw/App/DrawSVGTemplate.cpp +++ b/src/Mod/TechDraw/App/DrawSVGTemplate.cpp @@ -156,9 +156,8 @@ App::DocumentObjectExecReturn * DrawSVGTemplate::execute(void) //remove DrawingContent comment line //change line endings //capture TitleBlock dimensions - while (!inTemplate.eof()) + while (getline(inTemplate,line)) { - getline(inTemplate,line); // copy every line except the DrawingContent comment? if(line.find("") == string::npos) { // if not - write through @@ -287,8 +286,7 @@ std::map DrawSVGTemplate::getEditableTextsFromTemplate } string tline, tfrag; ifstream tfile (tfi.filePath().c_str()); - while (!tfile.eof()) { - getline (tfile,tline); + while (getline (tfile,tline)) { tfrag += tline; tfrag += "--endOfLine--"; } diff --git a/src/Mod/TechDraw/Gui/QGISVGTemplate.cpp b/src/Mod/TechDraw/Gui/QGISVGTemplate.cpp index 12ca62434d..ee6af24c40 100644 --- a/src/Mod/TechDraw/Gui/QGISVGTemplate.cpp +++ b/src/Mod/TechDraw/Gui/QGISVGTemplate.cpp @@ -154,9 +154,8 @@ void QGISVGTemplate::createClickHandles(void) //read all of PageResult into oStream (except the DrawingContent marker comment - why??) std::ifstream ifile (fi.filePath().c_str()); - while (!ifile.eof()) + while (std::getline(ifile,line)) { - std::getline(ifile,line); // check if the marker in the template is found if(line.find("") == std::string::npos) { // if not - write line to oStream