diff --git a/src/FSD/FSD_BinaryFile.cxx b/src/FSD/FSD_BinaryFile.cxx index 70e24b9f21..119ff51acc 100644 --- a/src/FSD/FSD_BinaryFile.cxx +++ b/src/FSD/FSD_BinaryFile.cxx @@ -168,9 +168,8 @@ void FSD_BinaryFile::ReadChar(TCollection_AsciiString& buffer, const Standard_Si buffer.Clear(); while (!IsEnd() && (ccount < rsize)) { - fread(&c, sizeof(char),1, myStream); + ccount += fread(&c, sizeof(char),1, myStream); buffer += c; - ccount++; } } diff --git a/src/IFSelect/IFSelect_SessionFile.cxx b/src/IFSelect/IFSelect_SessionFile.cxx index 9aca3b224a..c69a136bc4 100644 --- a/src/IFSelect/IFSelect_SessionFile.cxx +++ b/src/IFSelect/IFSelect_SessionFile.cxx @@ -118,8 +118,11 @@ static int deja = 0; Standard_Boolean header = Standard_False; for(;;) { ligne[0] = '\0'; - fgets(ligne,200,lefic); - if (feof(lefic)) break; + if (fgets(ligne,200,lefic) == NULL + || feof(lefic) != 0) + { + break; + } if (ligne[0] == '\0') continue; // D abord ligne initiale ? if (!header) diff --git a/src/IFSelect/IFSelect_SessionPilot.cxx b/src/IFSelect/IFSelect_SessionPilot.cxx index 332d2dd408..1eb7e011ce 100644 --- a/src/IFSelect/IFSelect_SessionPilot.cxx +++ b/src/IFSelect/IFSelect_SessionPilot.cxx @@ -242,8 +242,11 @@ static TCollection_AsciiString nulword; char ligne[100]; if (!lefic) std::cout << theprompt.ToCString(); ligne[0] = '\0'; - fgets(ligne,100,fic); - if (feof(fic)) break; + if (fgets(ligne,100,fic) == NULL + || feof(fic) != 0) + { + break; + } if (ligne[0] == '\0') continue; // On interprete cette commande TCollection_AsciiString command(ligne); diff --git a/src/IGESFile/liriges.c b/src/IGESFile/liriges.c index 7205eaf37a..8aa063add8 100644 --- a/src/IGESFile/liriges.c +++ b/src/IGESFile/liriges.c @@ -44,7 +44,10 @@ int iges_lire (FILE* lefic, int *numsec, char ligne[100], int modefnes) ligne[0] = '\0'; if(modefnes) - fgets(ligne,99,lefic); /*for kept compatibility with fnes*/ + { + if (fgets(ligne,99,lefic) == NULL) /*for kept compatibility with fnes*/ + return 0; + } else { /* PTV: 21.03.2002 it is neccessary for files that have only `\r` but no `\n` @@ -53,7 +56,8 @@ int iges_lire (FILE* lefic, int *numsec, char ligne[100], int modefnes) { } - fgets(&ligne[1],80,lefic); + if (fgets(&ligne[1],80,lefic) == NULL) + return 0; } if (*numsec == 0 && ligne[72] != 'S' && ligne[79] == ' ') @@ -61,13 +65,17 @@ int iges_lire (FILE* lefic, int *numsec, char ligne[100], int modefnes) ligne[0] = '\0'; if(modefnes) - fgets(ligne,99,lefic);/*for kept compatibility with fnes*/ + { + if (fgets(ligne,99,lefic) == NULL) /*for kept compatibility with fnes*/ + return 0; + } else { while ( fgets ( ligne, 2, lefic ) && ( ligne[0] == '\r' || ligne[0] == '\n' ) ) { } - fgets(&ligne[1],80,lefic); + if (fgets(&ligne[1],80,lefic) == NULL) + return 0; } } diff --git a/src/OSD/OSD_File.cxx b/src/OSD/OSD_File.cxx index 01e986ed53..94a451be46 100644 --- a/src/OSD/OSD_File.cxx +++ b/src/OSD/OSD_File.cxx @@ -750,7 +750,8 @@ TCollection_AsciiString PrinterName; else sprintf(buffer,"lpr -P%s %s",PrinterName.ToCString(),aBuffer.ToCString()); - system(buffer); + if (system(buffer) != 0) + Standard_ProgramError::Raise("OSD_File::Print : No output device was available, or an error occurred"); } diff --git a/src/OSD/OSD_Process.cxx b/src/OSD/OSD_Process.cxx index 251af5e91d..f9623fd31d 100644 --- a/src/OSD/OSD_Process.cxx +++ b/src/OSD/OSD_Process.cxx @@ -36,10 +36,10 @@ OSD_Process::OSD_Process(){ } -void OSD_Process::Spawn (const TCollection_AsciiString& cmd, +Standard_Integer OSD_Process::Spawn (const TCollection_AsciiString& cmd, const Standard_Boolean /*ShowWindow*/) { - system(cmd.ToCString()); + return system(cmd.ToCString()); } @@ -206,11 +206,13 @@ OSD_Process :: OSD_Process () { } // end constructor -void OSD_Process :: Spawn ( const TCollection_AsciiString& cmd , + +Standard_Integer OSD_Process::Spawn (const TCollection_AsciiString& cmd, const Standard_Boolean ShowWindow /* = Standard_True */) { STARTUPINFO si; PROCESS_INFORMATION pi; + DWORD aRes = 0; ZeroMemory ( &si, sizeof ( STARTUPINFO ) ); @@ -229,20 +231,22 @@ void OSD_Process :: Spawn ( const TCollection_AsciiString& cmd , if (!CreateProcess ( NULL, (char *)cmd.ToCString (), NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi ) - ) + ) { _osd_wnt_set_error ( myError, OSD_WProcess ); - + aRes = myError.Error(); + } else { CloseHandle ( pi.hThread ); WaitForSingleObject ( pi.hProcess, INFINITE ); - + GetExitCodeProcess (pi.hProcess, &aRes); CloseHandle ( pi.hProcess ); } // end else + return aRes; } // end OSD_Process :: Spawn void OSD_Process :: TerminalType ( TCollection_AsciiString& Name ) { diff --git a/src/OSD/OSD_Process.hxx b/src/OSD/OSD_Process.hxx index 5095b87aa9..573b0a4279 100644 --- a/src/OSD/OSD_Process.hxx +++ b/src/OSD/OSD_Process.hxx @@ -43,7 +43,7 @@ public: //! Issues a shell command //! ShowWindow : flag to allow show/hide of the window ( only used on WNT ) - Standard_EXPORT void Spawn (const TCollection_AsciiString& cmd, const Standard_Boolean ShowWindow = Standard_True); + Standard_EXPORT Standard_Integer Spawn (const TCollection_AsciiString& cmd, const Standard_Boolean ShowWindow = Standard_True); //! Returns the terminal used (vt100, vt200 ,sun-cmd ...) Standard_EXPORT void TerminalType (TCollection_AsciiString& Name); diff --git a/src/RWStl/RWStl.cxx b/src/RWStl/RWStl.cxx index 2ef056e243..375c0ed662 100644 --- a/src/RWStl/RWStl.cxx +++ b/src/RWStl/RWStl.cxx @@ -495,7 +495,8 @@ Handle(StlMesh_Mesh) RWStl::ReadAscii (const OSD_Path& thePath, gp_XYZ aN (Atof(x), Atof(y), Atof(z)); // skip the keywords "outer loop" - fscanf(file,"%*s %*s"); + if (fscanf(file,"%*s %*s") < 0) + break; // reading vertex if (3 != fscanf(file,"%*s %80s %80s %80s\n", x, y, z)) @@ -516,10 +517,12 @@ Handle(StlMesh_Mesh) RWStl::ReadAscii (const OSD_Path& thePath, ReadMesh->AddTriangle (i1, i2, i3, aN.X(), aN.Y(), aN.Z()); // skip the keywords "endloop" - fscanf(file,"%*s"); + if (fscanf(file,"%*s") < 0) + break; // skip the keywords "endfacet" - fscanf(file,"%*s"); + if (fscanf(file,"%*s") < 0) + break; // update progress only per 1k triangles if (++iTri % IND_THRESHOLD == 0)