From e1b78718ca8f93c0c1b368a904fa9c9453b6b74b Mon Sep 17 00:00:00 2001 From: dpasukhi Date: Sat, 6 Apr 2024 18:09:10 +0000 Subject: [PATCH] // fix a little more warnings --- src/FSD/FSD_CmpFile.cxx | 14 ++++++-------- src/FSD/FSD_File.cxx | 25 ++++++++++--------------- src/Message/Message_Msg.cxx | 1 - src/Message/Message_PrinterOStream.cxx | 2 +- src/OSD/OSD_File.cxx | 4 ++-- src/OSD/OSD_Path.cxx | 5 ++--- src/Standard/Standard_Failure.cxx | 7 ++++--- src/StepFile/StepFile_ReadData.cxx | 3 ++- src/Units/Units_UnitsDictionary.cxx | 1 - src/math/math_BissecNewton.cxx | 9 ++------- src/math/math_NewtonMinimum.cxx | 5 +---- 11 files changed, 30 insertions(+), 46 deletions(-) diff --git a/src/FSD/FSD_CmpFile.cxx b/src/FSD/FSD_CmpFile.cxx index 85d76117f1..e5fdc3dc3e 100644 --- a/src/FSD/FSD_CmpFile.cxx +++ b/src/FSD/FSD_CmpFile.cxx @@ -69,13 +69,9 @@ Storage_Error FSD_CmpFile::Open(const TCollection_AsciiString& aName, const Stor SetName(aName); if (OpenMode() == Storage_VSNone) { - std::ios_base::openmode anOpenMode = std::ios_base::openmode(0); + std::ios_base::openmode anOpenMode; switch (aMode) { - case Storage_VSNone: - { - break; - } case Storage_VSRead: { // std::ios::nocreate is not portable @@ -104,11 +100,13 @@ Storage_Error FSD_CmpFile::Open(const TCollection_AsciiString& aName, const Stor #endif break; } - } - if (anOpenMode != 0) + case Storage_VSNone: + default: { - OSD_OpenStream(myStream, aName, anOpenMode); + return Storage_VSOpenError; } + } + OSD_OpenStream(myStream, aName, anOpenMode); if (myStream.fail()) { result = Storage_VSOpenError; } diff --git a/src/FSD/FSD_File.cxx b/src/FSD/FSD_File.cxx index 8ee7e2066d..325dc8af37 100644 --- a/src/FSD/FSD_File.cxx +++ b/src/FSD/FSD_File.cxx @@ -51,9 +51,7 @@ FSD_File::FSD_File() Storage_Error FSD_File::IsGoodFileType(const TCollection_AsciiString& aName) { FSD_File f; - Storage_Error s; - - s = f.Open(aName,Storage_VSRead); + Storage_Error s = f.Open(aName,Storage_VSRead); if (s == Storage_VSOk) { TCollection_AsciiString l; @@ -84,13 +82,9 @@ Storage_Error FSD_File::Open(const TCollection_AsciiString& aName,const Storage_ if (OpenMode() == Storage_VSNone) { - std::ios_base::openmode anOpenMode = std::ios_base::openmode(0); + std::ios_base::openmode anOpenMode; switch (aMode) { - case Storage_VSNone: - { - break; - } case Storage_VSRead: { // std::ios::nocreate is not portable @@ -107,11 +101,13 @@ Storage_Error FSD_File::Open(const TCollection_AsciiString& aName,const Storage_ anOpenMode = std::ios::in | std::ios::out; break; } + case Storage_VSNone: + default: + { + return Storage_VSOpenError; + } } - if (anOpenMode != 0) - { - OSD_OpenStream (myStream, aName.ToCString(), anOpenMode); - } + OSD_OpenStream (myStream, aName.ToCString(), anOpenMode); if (myStream.fail()) { result = Storage_VSOpenError; } @@ -237,7 +233,7 @@ void FSD_File::WriteExtendedLine(const TCollection_ExtendedString& buffer) void FSD_File::ReadExtendedLine(TCollection_ExtendedString& buffer) { char c = '\0'; - Standard_ExtCharacter i = 0,j,count = 0; + Standard_ExtCharacter i = 0,count = 0; Standard_Boolean fin = Standard_False; Standard_CString tg = ENDOFNORMALEXTENDEDSECTION; @@ -249,7 +245,6 @@ void FSD_File::ReadExtendedLine(TCollection_ExtendedString& buffer) if (c == tg[count]) count++; else count = 0; if (count < SIZEOFNORMALEXTENDEDSECTION) { - j = 0; i = (Standard_ExtCharacter)c; if (c == '\0') fin = Standard_True; i = (i << 8); @@ -258,7 +253,7 @@ void FSD_File::ReadExtendedLine(TCollection_ExtendedString& buffer) if (c == tg[count]) count++; else count = 0; if (count < SIZEOFNORMALEXTENDEDSECTION) { - j = (Standard_ExtCharacter)c; + Standard_ExtCharacter j = (Standard_ExtCharacter)c; if (c != '\n') { fin = Standard_False; i |= (0x00FF & j); diff --git a/src/Message/Message_Msg.cxx b/src/Message/Message_Msg.cxx index ade83fe1ff..aa4f686e9e 100644 --- a/src/Message/Message_Msg.cxx +++ b/src/Message/Message_Msg.cxx @@ -138,7 +138,6 @@ void Message_Msg::Set (const TCollection_ExtendedString& theMsg) aFormatType = Msg_StringType; break; default: - aFormatType = Msg_IndefiniteType; continue; } mySeqOfFormats.Append (Standard_Integer(aFormatType)); // type diff --git a/src/Message/Message_PrinterOStream.cxx b/src/Message/Message_PrinterOStream.cxx index ee53f8187a..02b030785d 100644 --- a/src/Message/Message_PrinterOStream.cxx +++ b/src/Message/Message_PrinterOStream.cxx @@ -223,7 +223,7 @@ void Message_PrinterOStream::SetConsoleTextColor (Standard_OStream* theOStream, return; } - const char* aCode = "\e[0m"; + const char* aCode; switch (theTextColor) { case Message_ConsoleColor_Default: diff --git a/src/OSD/OSD_File.cxx b/src/OSD/OSD_File.cxx index db63054d1d..1518a3b0c9 100644 --- a/src/OSD/OSD_File.cxx +++ b/src/OSD/OSD_File.cxx @@ -459,7 +459,7 @@ void OSD_File::Build (const OSD_OpenMode theMode, throw Standard_ProgramError ("OSD_File::Build(): no name was given"); } - const char* anFDOpenMode = "r"; + const char* anFDOpenMode; Standard_Integer anOpenMode = O_CREAT | O_TRUNC; switch (theMode) { @@ -622,7 +622,7 @@ void OSD_File::Open (const OSD_OpenMode theMode, throw Standard_ProgramError ("OSD_File::Open(): no name was given"); } - const char* anFDOpenMode = "r"; + const char* anFDOpenMode; Standard_Integer anOpenMode = 0; switch (theMode) { diff --git a/src/OSD/OSD_Path.cxx b/src/OSD/OSD_Path.cxx index e034e9e91d..ec46e03647 100644 --- a/src/OSD/OSD_Path.cxx +++ b/src/OSD/OSD_Path.cxx @@ -1521,7 +1521,6 @@ TCollection_AsciiString OSD_Path::RelativePath( TCollection_AsciiString EmptyString = "" ; TCollection_AsciiString FilePath ; Standard_Integer len ; - Standard_Integer i, n ; Standard_Boolean Wnt = 0 ; FilePath = aAbsFilePath ; @@ -1554,14 +1553,14 @@ TCollection_AsciiString OSD_Path::RelativePath( TCollection_AsciiString DirToken, FileToken ; Standard_Boolean Sibling = 0 ; - for (i = n = 1 ;; n++) { + for (Standard_Integer n = 1 ;; n++) { DirToken = aDirPath.Token("/\\",n) ; if (DirToken.IsEmpty()) return FilePath ; if (!Sibling) { len = FilePath.Length() ; - i = FilePath.Search("/") ; + Standard_Integer i = FilePath.Search("/") ; if (i > 0) { if (i == len) return EmptyString ; diff --git a/src/Standard/Standard_Failure.cxx b/src/Standard/Standard_Failure.cxx index 002c42a426..cacdd21d6a 100644 --- a/src/Standard/Standard_Failure.cxx +++ b/src/Standard/Standard_Failure.cxx @@ -44,10 +44,11 @@ Standard_Failure::StringRef* Standard_Failure::StringRef::allocate_message (cons } const Standard_Size aLen = strlen (theString); - StringRef* aStrPtr = (StringRef* )malloc (aLen + sizeof(Standard_Integer) + 1); + StringRef* aStrPtr = (StringRef* )Standard::AllocateOptimal (aLen + sizeof(Standard_Integer) + 1); if (aStrPtr != NULL) { - strcpy ((char* )&aStrPtr->Message[0], theString); + strncpy ((char* )&aStrPtr->Message[0], theString, aLen); + ((char* )&aStrPtr->Message[0])[aLen] = '\0'; aStrPtr->Counter = 1; } return aStrPtr; @@ -78,7 +79,7 @@ void Standard_Failure::StringRef::deallocate_message (Standard_Failure::StringRe { if (--theString->Counter == 0) { - free ((void* )theString); + Standard::Free((void* )theString); } } } diff --git a/src/StepFile/StepFile_ReadData.cxx b/src/StepFile/StepFile_ReadData.cxx index 91d0dd933c..95362afd6d 100644 --- a/src/StepFile/StepFile_ReadData.cxx +++ b/src/StepFile/StepFile_ReadData.cxx @@ -151,7 +151,8 @@ void StepFile_ReadData::CreateNewText(const char* theNewText, int theLenText) strcpy(myResText + (int)strlen(anOldResText), theNewText); return; } - strcpy(myResText, theNewText); + strncpy(myResText, theNewText, aLength); + myResText[aLength] = '\0'; } //======================================================================= diff --git a/src/Units/Units_UnitsDictionary.cxx b/src/Units/Units_UnitsDictionary.cxx index 05268f9a1e..890ff0a009 100644 --- a/src/Units/Units_UnitsDictionary.cxx +++ b/src/Units/Units_UnitsDictionary.cxx @@ -298,7 +298,6 @@ void Units_UnitsDictionary::Creates() } if(unit2[0]) { - j = 0; for(j=1;j<=theunitssequence->Length();j++) if(theunitssequence->Value(j) == unit2)break; diff --git a/src/math/math_BissecNewton.cxx b/src/math/math_BissecNewton.cxx index 88eecc5a2e..01dc4659f0 100644 --- a/src/math/math_BissecNewton.cxx +++ b/src/math/math_BissecNewton.cxx @@ -52,7 +52,7 @@ void math_BissecNewton::Perform(math_FunctionWithDerivative& F, Standard_Boolean GOOD; Standard_Integer j; Standard_Real dxold, fh, fl; - Standard_Real swap, temp, xh, xl; + Standard_Real xh, xl; GOOD = F.Values(Bound1, fl, df); if(!GOOD) { @@ -83,9 +83,6 @@ void math_BissecNewton::Perform(math_FunctionWithDerivative& F, else { xl = Bound2; xh = Bound1; - swap = fl; - fl = fh; - fh = swap; } // Modified by Sergey KHROMOV - Wed Jan 22 12:06:49 2003 End x = 0.5 * (Bound1 + Bound2); @@ -112,7 +109,7 @@ void math_BissecNewton::Perform(math_FunctionWithDerivative& F, else { dxold = dx; dx = f / df; - temp = x; + Standard_Real temp = x; x -= dx; if(temp == x) { TheStatus = math_OK; @@ -133,11 +130,9 @@ void math_BissecNewton::Perform(math_FunctionWithDerivative& F, } if(f < 0.0) { xl = x; - fl = f; } else if(f > 0.0) { xh = x; - fh = f; } else { TheStatus = math_OK; diff --git a/src/math/math_NewtonMinimum.cxx b/src/math/math_NewtonMinimum.cxx index 89ae93f952..2e06d08ea2 100644 --- a/src/math/math_NewtonMinimum.cxx +++ b/src/math/math_NewtonMinimum.cxx @@ -92,7 +92,6 @@ void math_NewtonMinimum::Perform(math_MultipleVarFunctionWithHessian& F, math_Vector Point2(1, F.NbVariables()); math_Vector* precedent = &Point1; math_Vector* suivant = &Point2; - math_Vector* auxiliaire = precedent; Standard_Boolean Ok = Standard_True; Standard_Integer NbConv = 0, ii, Nreduction; @@ -234,9 +233,7 @@ void math_NewtonMinimum::Perform(math_MultipleVarFunctionWithHessian& F, } if (VItere <= VPrecedent) { - auxiliaire = precedent; - precedent = suivant; - suivant = auxiliaire; + std::swap(precedent, suivant); PreviousMinimum = VPrecedent; TheMinimum = VItere; Ok = (nbiter < Itermax);