Fix #10356 FP bufferAccessOutOfBounds is reported on strncmp() (#4281)

* Add test

* Fix #10356 FP bufferAccessOutOfBounds is reported on strncmp()

* Remove suppressions
This commit is contained in:
chrchr-github 2022-07-15 17:43:18 +02:00 committed by GitHub
parent 53cd3dc665
commit 71d386819e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 4 deletions

View File

@ -5137,12 +5137,10 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<arg nr="1" direction="in"> <arg nr="1" direction="in">
<not-null/> <not-null/>
<not-uninit/> <not-uninit/>
<minsize type="argvalue" arg="3"/>
</arg> </arg>
<arg nr="2" direction="in"> <arg nr="2" direction="in">
<not-null/> <not-null/>
<not-uninit/> <not-uninit/>
<minsize type="argvalue" arg="3"/>
</arg> </arg>
<arg nr="3" direction="in"> <arg nr="3" direction="in">
<not-uninit/> <not-uninit/>

View File

@ -75,6 +75,11 @@ char * invalidFunctionArgStr_strpbrk( const char *p )
int invalidFunctionArgStr_strncmp( const char *p ) int invalidFunctionArgStr_strncmp( const char *p )
{ {
const char string[] = "foo";
char other[5] = { 0 };
memcpy(other, "foo", 4);
if (strncmp(other, string, 5) != 0) {}
// No warning is expected for: // No warning is expected for:
const char emdash[3] = { -42, -43, -44 }; const char emdash[3] = { -42, -43, -44 };
return strncmp( p, emdash, 3 ); return strncmp( p, emdash, 3 );
@ -3921,9 +3926,7 @@ void bufferAccessOutOfBounds_strncmp(void)
const char src[3] = "abc"; const char src[3] = "abc";
char dest[1] = "a"; char dest[1] = "a";
(void)strncmp(dest,src,1); (void)strncmp(dest,src,1);
// cppcheck-suppress bufferAccessOutOfBounds
(void)strncmp(dest,src,2); (void)strncmp(dest,src,2);
// cppcheck-suppress bufferAccessOutOfBounds
(void)strncmp(dest,src,3); (void)strncmp(dest,src,3);
} }