File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -365,7 +365,8 @@ CTU::FileInfo *CTU::getFileInfo(const Tokenizer *tokenizer)
365365 functionCall.location = FileInfo::Location (tokenizer, tok);
366366 functionCall.callArgNr = argnr + 1 ;
367367 functionCall.callArgumentExpression = argtok->expressionString ();
368- functionCall.callArgValue = argtok->variable ()->dimension (0 ) * argtok->valueType ()->typeSize (*tokenizer->getSettings ());
368+ const auto typeSize = argtok->valueType ()->typeSize (*tokenizer->getSettings ());
369+ functionCall.callArgValue = typeSize > 0 ? argtok->variable ()->dimension (0 ) * typeSize : -1 ;
369370 functionCall.warning = false ;
370371 fileInfo->functionCalls .push_back (std::move (functionCall));
371372 }
@@ -528,7 +529,7 @@ static bool findPath(const std::string &callId,
528529 case CTU::FileInfo::InvalidValueType::bufferOverflow:
529530 if (functionCall->callValueType != ValueFlow::Value::ValueType::BUFFER_SIZE)
530531 continue ;
531- if (unsafeValue < 0 || unsafeValue >= functionCall->callArgValue )
532+ if (unsafeValue < 0 || ( unsafeValue >= functionCall->callArgValue && functionCall-> callArgValue >= 0 ) )
532533 break ;
533534 continue ;
534535 }
Original file line number Diff line number Diff line change @@ -5236,6 +5236,13 @@ class TestBufferOverrun : public TestFixture {
52365236 " }\n " );
52375237 ASSERT_EQUALS (" [test.cpp:4] -> [test.cpp:1]: (error) Array index out of bounds; 'argv' buffer size is 1 and it is accessed at offset 5.\n " ,
52385238 errout.str ());
5239+
5240+ ctu (" void g(int *b) { b[0] = 0; }\n "
5241+ " void f() {\n "
5242+ " GLint a[1];\n "
5243+ " g(a);\n "
5244+ " }\n " );
5245+ ASSERT_EQUALS (" " , errout.str ());
52395246 }
52405247
52415248 void ctu_variable () {
You can’t perform that action at this time.
0 commit comments