@@ -43,6 +43,13 @@ namespace {
4343
4444// ---------------------------------------------------------------------------
4545
46+ // CWE ids used:
47+ static const CWE CWE119 (119U );
48+ static const CWE CWE131 (131U );
49+ static const CWE CWE788 (788U );
50+
51+ // ---------------------------------------------------------------------------
52+
4653static void makeArrayIndexOutOfBoundsError (std::ostream& oss, const CheckBufferOverrun::ArrayInfo &arrayInfo, const std::vector<MathLib::bigint> &index)
4754{
4855 oss << " Array '" << arrayInfo.varname ();
@@ -61,7 +68,7 @@ void CheckBufferOverrun::arrayIndexOutOfBoundsError(const Token *tok, const Arra
6168{
6269 std::ostringstream oss;
6370 makeArrayIndexOutOfBoundsError (oss, arrayInfo, index);
64- reportError (tok, Severity::error, " arrayIndexOutOfBounds" , oss.str (), 788U , false );
71+ reportError (tok, Severity::error, " arrayIndexOutOfBounds" , oss.str (), CWE788 , false );
6572}
6673
6774void CheckBufferOverrun::arrayIndexOutOfBoundsError (const Token *tok, const ArrayInfo &arrayInfo, const std::vector<ValueFlow::Value> &index)
@@ -92,7 +99,7 @@ void CheckBufferOverrun::arrayIndexOutOfBoundsError(const Token *tok, const Arra
9299 std::list<const Token *> callstack;
93100 callstack.push_back (tok);
94101 callstack.push_back (condition);
95- reportError (callstack, Severity::warning, " arrayIndexOutOfBoundsCond" , errmsg.str (), 0U , false );
102+ reportError (callstack, Severity::warning, " arrayIndexOutOfBoundsCond" , errmsg.str (), CWE ( 0U ) , false );
96103 } else {
97104 std::ostringstream errmsg;
98105 errmsg << " Array '" << arrayInfo.varname ();
@@ -133,7 +140,7 @@ static std::string bufferOverrunMessage(std::string varnames)
133140
134141void CheckBufferOverrun::bufferOverrunError (const Token *tok, const std::string &varnames)
135142{
136- reportError (tok, Severity::error, " bufferAccessOutOfBounds" , bufferOverrunMessage (varnames), 788U , false );
143+ reportError (tok, Severity::error, " bufferAccessOutOfBounds" , bufferOverrunMessage (varnames), CWE788 , false );
137144}
138145
139146
@@ -177,7 +184,7 @@ void CheckBufferOverrun::outOfBoundsError(const Token *tok, const std::string &w
177184 if (show_size_info)
178185 oss << " : Supplied size " << supplied_size << " is larger than actual size " << actual_size;
179186 oss << ' .' ;
180- reportError (tok, Severity::error, " outOfBounds" , oss.str (), 788U , false );
187+ reportError (tok, Severity::error, " outOfBounds" , oss.str (), CWE788 , false );
181188}
182189
183190void CheckBufferOverrun::pointerOutOfBoundsError (const Token *tok, const Token *index, const MathLib::bigint indexvalue)
@@ -221,12 +228,12 @@ void CheckBufferOverrun::terminateStrncpyError(const Token *tok, const std::stri
221228 " The buffer '" + varname + " ' may not be null-terminated after the call to strncpy().\n "
222229 " If the source string's size fits or exceeds the given size, strncpy() does not add a "
223230 " zero at the end of the buffer. This causes bugs later in the code if the code "
224- " assumes buffer is null-terminated." , 0U , true );
231+ " assumes buffer is null-terminated." , CWE ( 0U ) , true );
225232}
226233
227234void CheckBufferOverrun::cmdLineArgsError (const Token *tok)
228235{
229- reportError (tok, Severity::error, " insecureCmdLineArgs" , " Buffer overrun possible for long command line arguments." , 119U , false );
236+ reportError (tok, Severity::error, " insecureCmdLineArgs" , " Buffer overrun possible for long command line arguments." , CWE119 , false );
230237}
231238
232239void CheckBufferOverrun::bufferNotZeroTerminatedError (const Token *tok, const std::string &varname, const std::string &function)
@@ -235,7 +242,7 @@ void CheckBufferOverrun::bufferNotZeroTerminatedError(const Token *tok, const st
235242 " The buffer '" + varname + " ' is not null-terminated after the call to " + function + " (). "
236243 " This will cause bugs later in the code if the code assumes the buffer is null-terminated." ;
237244
238- reportError (tok, Severity::warning, " bufferNotZeroTerminated" , errmsg, 0U , true );
245+ reportError (tok, Severity::warning, " bufferNotZeroTerminated" , errmsg, CWE ( 0U ) , true );
239246}
240247
241248void CheckBufferOverrun::argumentSizeError (const Token *tok, const std::string &functionName, const std::string &varname)
@@ -248,7 +255,7 @@ void CheckBufferOverrun::negativeMemoryAllocationSizeError(const Token *tok)
248255 reportError (tok, Severity::error, " negativeMemoryAllocationSize" ,
249256 " Memory allocation size is negative.\n "
250257 " Memory allocation size is negative."
251- " Negative allocation size has no specified behaviour." , 131U , false );
258+ " Negative allocation size has no specified behaviour." , CWE131 , false );
252259}
253260
254261// ---------------------------------------------------------------------------
@@ -1717,7 +1724,7 @@ void CheckBufferOverrun::negativeIndexError(const Token *tok, const ValueFlow::V
17171724 ostr << " Array index " << index.intvalue << " is out of bounds." ;
17181725 if (index.condition )
17191726 ostr << " Otherwise there is useless condition at line " << index.condition ->linenr () << " ." ;
1720- reportError (tok, index.condition ? Severity::warning : Severity::error, " negativeIndex" , ostr.str (), 0U , index.inconclusive );
1727+ reportError (tok, index.condition ? Severity::warning : Severity::error, " negativeIndex" , ostr.str (), CWE ( 0U ) , index.inconclusive );
17211728}
17221729
17231730CheckBufferOverrun::ArrayInfo::ArrayInfo ()
0 commit comments