From 9b5f0c2c0858225d12e9c3b1ac8c5cbb8fa7f15d Mon Sep 17 00:00:00 2001 From: aln Date: Thu, 30 Jun 2022 16:00:34 +0300 Subject: [PATCH] Fixed warnings - arrayIndexOutOfBoundsCond - nullPointer --- src/BinLDrivers/BinLDrivers_DocumentSection.cxx | 4 ++-- src/ExprIntrp/lex.ExprIntrp.c | 17 +++++++++++++---- src/IFSelect/IFSelect_SessionPilot.cxx | 4 ++-- src/OSD/OSD_PerfMeter.cxx | 2 +- src/StepFile/lex.step.cxx | 3 +++ 5 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/BinLDrivers/BinLDrivers_DocumentSection.cxx b/src/BinLDrivers/BinLDrivers_DocumentSection.cxx index 547ced34d5..1edc70ddca 100644 --- a/src/BinLDrivers/BinLDrivers_DocumentSection.cxx +++ b/src/BinLDrivers/BinLDrivers_DocumentSection.cxx @@ -223,14 +223,14 @@ Standard_Boolean BinLDrivers_DocumentSection::ReadTOC ( char aBuf[THE_BUF_SIZE]; Standard_Integer aNameBufferSize; theStream.read ((char *)&aNameBufferSize, sizeof(Standard_Integer)); - if (theStream.eof() || aNameBufferSize > THE_BUF_SIZE) + if (theStream.eof() || aNameBufferSize > THE_BUF_SIZE - 1) return Standard_False; #ifdef DO_INVERSE aNameBufferSize = InverseSize(aNameBufferSize); #endif if (aNameBufferSize > 0) { theStream.read ((char *)&aBuf[0], (Standard_Size)aNameBufferSize); - aBuf[aNameBufferSize] = '\0'; + aBuf[aNameBufferSize-1] = '\0'; theSection.myName = (Standard_CString)&aBuf[0]; uint64_t aValue[3]; diff --git a/src/ExprIntrp/lex.ExprIntrp.c b/src/ExprIntrp/lex.ExprIntrp.c index 0bd3db536e..cab45c5708 100644 --- a/src/ExprIntrp/lex.ExprIntrp.c +++ b/src/ExprIntrp/lex.ExprIntrp.c @@ -1731,8 +1731,10 @@ static void yy_load_buffer_state (void) void yy_delete_buffer (YY_BUFFER_STATE b ) { - if ( ! b ) - return; + if ( ! b ) { + YY_FATAL_ERROR("out of dynamic memory in yy_delete_buffer()"); + return; + } if ( b == YY_CURRENT_BUFFER ) /* Not sure if we should pop here. */ YY_CURRENT_BUFFER_LVALUE = (YY_BUFFER_STATE) 0; @@ -1750,6 +1752,11 @@ static void yy_load_buffer_state (void) static void yy_init_buffer (YY_BUFFER_STATE b, FILE * file ) { + if ( ! b ) { + YY_FATAL_ERROR("out of dynamic memory in yy_init_buffer()"); + return; + } + int oerrno = errno; yy_flush_buffer( b ); @@ -1777,8 +1784,10 @@ static void yy_load_buffer_state (void) */ void yy_flush_buffer (YY_BUFFER_STATE b ) { - if ( ! b ) - return; + if ( ! b ) { + YY_FATAL_ERROR("out of dynamic memory in yy_flush_buffer()"); + return; + } b->yy_n_chars = 0; diff --git a/src/IFSelect/IFSelect_SessionPilot.cxx b/src/IFSelect/IFSelect_SessionPilot.cxx index acf782e10e..fb400dc262 100644 --- a/src/IFSelect/IFSelect_SessionPilot.cxx +++ b/src/IFSelect/IFSelect_SessionPilot.cxx @@ -113,11 +113,11 @@ IFSelect_SessionPilot::IFSelect_SessionPilot (const Standard_CString prompt) continue; } if (nc == 0) thewordeb.SetValue (thenbwords,i); - if (nc > MAXCARS) { std::cout<<"Arg."< "<= MAXCARS - 1) { std::cout<<"Arg."< "< 0) { - unarg[nc] = '\0'; thewords(thenbwords).Clear(); + unarg[nc + 1] = '\0'; thewords(thenbwords).Clear(); thewords(thenbwords).AssignCat(unarg); #ifdef DEBUG_TRACE std::cout<<"thewords("<