std.cfg: Add strncpy_s and strncat_s (#1136)

This commit is contained in:
Sebastian 2018-03-26 18:38:26 +02:00 committed by orbitcowboy
parent db045c2bf6
commit d3284d5d54
2 changed files with 111 additions and 0 deletions

View File

@ -4581,6 +4581,29 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<valid>0:</valid>
</arg>
</function>
<!-- errno_t strncpy_s(char *restrict dest, rsize_t destsz, const char *restrict src, rsize_t count); // since C11 -->
<function name="strncpy_s">
<noreturn>false</noreturn>
<returnValue type="errno_t"/>
<leak-ignore/>
<arg nr="1">
<not-null/>
<not-uninit/>
<minsize type="argvalue" arg="2"/>
</arg>
<arg nr="2">
<not-uninit/>
<valid>0:</valid>
</arg>
<arg nr="3">
<not-null/>
<not-uninit/>
<minsize type="argvalue" arg="4"/>
</arg>
<arg nr="4">
<not-uninit/>
</arg>
</function>
<!-- const char *strpbrk(const char *str1, const char *str2); -->
<!-- char *strpbrk( char *str1, const char *str2); -->
<function name="strpbrk,std::strpbrk">
@ -4618,6 +4641,29 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<valid>0:</valid>
</arg>
</function>
<!-- errno_t strncat_s(char *restrict dest, rsize_t destsz, const char *restrict src, rsize_t count); // since C11 -->
<function name="strncat_s">
<noreturn>false</noreturn>
<returnValue type="errno_t"/>
<leak-ignore/>
<arg nr="1">
<not-null/>
<not-uninit/>
<minsize type="argvalue" arg="2"/>
</arg>
<arg nr="2">
<not-uninit/>
<valid>0:</valid>
</arg>
<arg nr="3">
<not-null/>
<not-uninit/>
<minsize type="argvalue" arg="4"/>
</arg>
<arg nr="4">
<not-uninit/>
</arg>
</function>
<!-- wchar_t *wcsncat(wchar_t *ct, const wchar_t *cs, size_t n); -->
<function name="wcsncat,std::wcsncat">
<noreturn>false</noreturn>

View File

@ -53,6 +53,19 @@ void bufferAccessOutOfBounds(void)
strncpy(a,"a",6);
// cppcheck-suppress redundantCopy
strncpy(a,"abcdefgh",4);
// valid call
strncpy_s(a,5,"abcd",5);
// string will be truncated, error is returned, but no buffer overflow
strncpy_s(a,5,"abcde",6);
// cppcheck-suppress bufferAccessOutOfBounds
strncpy_s(a,5,"a",6);
strncpy_s(a,5,"abcdefgh",4);
// valid call
strncat_s(a,5,"1",2);
// cppcheck-suppress bufferAccessOutOfBounds
strncat_s(a,10,"1",2);
// cppcheck-suppress bufferAccessOutOfBounds
strncat_s(a,5,"1",5);
fread(a,1,5,stdin);
// cppcheck-suppress bufferAccessOutOfBounds
fread(a,1,6,stdin);
@ -169,10 +182,18 @@ void nullpointer(int value)
// cppcheck-suppress nullPointer
strncpy(0,0,1);
// cppcheck-suppress nullPointer
strncpy_s(0,1,1,1);
// cppcheck-suppress nullPointer
strncpy_s(1,1,0,1);
// cppcheck-suppress nullPointer
wcsncpy(0,0,1);
// cppcheck-suppress nullPointer
strncat(0,0,1);
// cppcheck-suppress nullPointer
strncat_s(0,1,1,1);
// cppcheck-suppress nullPointer
strncat_s(1,1,0,1);
// cppcheck-suppress nullPointer
wcsncat(0,0,1);
// cppcheck-suppress ignoredReturnValue
// cppcheck-suppress nullPointer
@ -3022,6 +3043,28 @@ void uninivar_strncpy(void)
(void)strncpy(s,ct,n);
}
void uninivar_strncpy_s(char *Ct, size_t N1, char *S, size_t N2)
{
char *ct;
char *s;
size_t n1;
size_t n2;
// cppcheck-suppress uninitvar
(void)strncpy_s(ct,n1,s,n2);
// cppcheck-suppress uninitvar
(void)strncpy_s(ct,N1,S,N2);
// cppcheck-suppress uninitvar
(void)strncpy_s(Ct,n1,S,N2);
// cppcheck-suppress uninitvar
(void)strncpy_s(Ct,N1,s,N2);
// cppcheck-suppress uninitvar
(void)strncpy_s(Ct,N1,S,n2);
// no warning is expected for
(void)strncpy_s(Ct,N1,S,N2);
}
void uninivar_strpbrk(void)
{
char *cs;
@ -3048,6 +3091,28 @@ void uninivar_strncat(char *Ct, char *S, size_t N)
(void)strncat(Ct,S,N);
}
void uninivar_strncat_s(char *Ct, size_t N1, char *S, size_t N2)
{
char *ct;
char *s;
size_t n1;
size_t n2;
// cppcheck-suppress uninitvar
(void)strncat_s(ct,n1,s,n2);
// cppcheck-suppress uninitvar
(void)strncat_s(ct,N1,S,N2);
// cppcheck-suppress uninitvar
(void)strncat_s(Ct,n1,S,N2);
// cppcheck-suppress uninitvar
(void)strncat_s(Ct,N1,s,N2);
// cppcheck-suppress uninitvar
(void)strncat_s(Ct,N1,S,n2);
// no warning is expected for
(void)strncat_s(Ct,N1,S,N2);
}
void uninivar_wcsncat(wchar_t *Ct, wchar_t *S, size_t N)
{
wchar_t *ct;