1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-04-10 18:51:21 +03:00

0026781: Coding rules - eliminate GCC warning -Wunused-result

Check return code of fgets() and system() within FSD_BinaryFile::ReadChar(),
IFSelect_SessionFile::ReadFile(), IFSelect_SessionPilot::ReadScript(),
OSD_File::Print(), OSD_Process::Spawn(), RWStl::ReadAscii(), iges_lire().
This commit is contained in:
rkv 2015-10-28 10:13:28 +03:00 committed by bugmaster
parent 71958f7db2
commit 9816003815
8 changed files with 42 additions and 21 deletions

View File

@ -168,9 +168,8 @@ void FSD_BinaryFile::ReadChar(TCollection_AsciiString& buffer, const Standard_Si
buffer.Clear(); buffer.Clear();
while (!IsEnd() && (ccount < rsize)) { while (!IsEnd() && (ccount < rsize)) {
fread(&c, sizeof(char),1, myStream); ccount += fread(&c, sizeof(char),1, myStream);
buffer += c; buffer += c;
ccount++;
} }
} }

View File

@ -118,8 +118,11 @@ static int deja = 0;
Standard_Boolean header = Standard_False; Standard_Boolean header = Standard_False;
for(;;) { for(;;) {
ligne[0] = '\0'; ligne[0] = '\0';
fgets(ligne,200,lefic); if (fgets(ligne,200,lefic) == NULL
if (feof(lefic)) break; || feof(lefic) != 0)
{
break;
}
if (ligne[0] == '\0') continue; if (ligne[0] == '\0') continue;
// D abord ligne initiale ? // D abord ligne initiale ?
if (!header) if (!header)

View File

@ -242,8 +242,11 @@ static TCollection_AsciiString nulword;
char ligne[100]; char ligne[100];
if (!lefic) std::cout << theprompt.ToCString(); if (!lefic) std::cout << theprompt.ToCString();
ligne[0] = '\0'; ligne[0] = '\0';
fgets(ligne,100,fic); if (fgets(ligne,100,fic) == NULL
if (feof(fic)) break; || feof(fic) != 0)
{
break;
}
if (ligne[0] == '\0') continue; if (ligne[0] == '\0') continue;
// On interprete cette commande // On interprete cette commande
TCollection_AsciiString command(ligne); TCollection_AsciiString command(ligne);

View File

@ -44,7 +44,10 @@ int iges_lire (FILE* lefic, int *numsec, char ligne[100], int modefnes)
ligne[0] = '\0'; ligne[0] = '\0';
if(modefnes) 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 else
{ {
/* PTV: 21.03.2002 it is neccessary for files that have only `\r` but no `\n` /* 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] == ' ') 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'; ligne[0] = '\0';
if(modefnes) 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 else
{ {
while ( fgets ( ligne, 2, lefic ) && ( ligne[0] == '\r' || ligne[0] == '\n' ) ) 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;
} }
} }

View File

@ -750,7 +750,8 @@ TCollection_AsciiString PrinterName;
else else
sprintf(buffer,"lpr -P%s %s",PrinterName.ToCString(),aBuffer.ToCString()); 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");
} }

View File

@ -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*/) const Standard_Boolean /*ShowWindow*/)
{ {
system(cmd.ToCString()); return system(cmd.ToCString());
} }
@ -206,11 +206,13 @@ OSD_Process :: OSD_Process () {
} // end constructor } // 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 */) { const Standard_Boolean ShowWindow /* = Standard_True */) {
STARTUPINFO si; STARTUPINFO si;
PROCESS_INFORMATION pi; PROCESS_INFORMATION pi;
DWORD aRes = 0;
ZeroMemory ( &si, sizeof ( STARTUPINFO ) ); ZeroMemory ( &si, sizeof ( STARTUPINFO ) );
@ -229,20 +231,22 @@ void OSD_Process :: Spawn ( const TCollection_AsciiString& cmd ,
if (!CreateProcess ( if (!CreateProcess (
NULL, (char *)cmd.ToCString (), NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi NULL, (char *)cmd.ToCString (), NULL, NULL, TRUE, CREATE_NEW_CONSOLE, NULL, NULL, &si, &pi
) )
) ) {
_osd_wnt_set_error ( myError, OSD_WProcess ); _osd_wnt_set_error ( myError, OSD_WProcess );
aRes = myError.Error();
}
else { else {
CloseHandle ( pi.hThread ); CloseHandle ( pi.hThread );
WaitForSingleObject ( pi.hProcess, INFINITE ); WaitForSingleObject ( pi.hProcess, INFINITE );
GetExitCodeProcess (pi.hProcess, &aRes);
CloseHandle ( pi.hProcess ); CloseHandle ( pi.hProcess );
} // end else } // end else
return aRes;
} // end OSD_Process :: Spawn } // end OSD_Process :: Spawn
void OSD_Process :: TerminalType ( TCollection_AsciiString& Name ) { void OSD_Process :: TerminalType ( TCollection_AsciiString& Name ) {

View File

@ -43,7 +43,7 @@ public:
//! Issues a shell command //! Issues a shell command
//! ShowWindow : flag to allow show/hide of the window ( only used on WNT ) //! 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 ...) //! Returns the terminal used (vt100, vt200 ,sun-cmd ...)
Standard_EXPORT void TerminalType (TCollection_AsciiString& Name); Standard_EXPORT void TerminalType (TCollection_AsciiString& Name);

View File

@ -495,7 +495,8 @@ Handle(StlMesh_Mesh) RWStl::ReadAscii (const OSD_Path& thePath,
gp_XYZ aN (Atof(x), Atof(y), Atof(z)); gp_XYZ aN (Atof(x), Atof(y), Atof(z));
// skip the keywords "outer loop" // skip the keywords "outer loop"
fscanf(file,"%*s %*s"); if (fscanf(file,"%*s %*s") < 0)
break;
// reading vertex // reading vertex
if (3 != fscanf(file,"%*s %80s %80s %80s\n", x, y, z)) 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()); ReadMesh->AddTriangle (i1, i2, i3, aN.X(), aN.Y(), aN.Z());
// skip the keywords "endloop" // skip the keywords "endloop"
fscanf(file,"%*s"); if (fscanf(file,"%*s") < 0)
break;
// skip the keywords "endfacet" // skip the keywords "endfacet"
fscanf(file,"%*s"); if (fscanf(file,"%*s") < 0)
break;
// update progress only per 1k triangles // update progress only per 1k triangles
if (++iTri % IND_THRESHOLD == 0) if (++iTri % IND_THRESHOLD == 0)