std.cfg, windows.cfg: Move strcpy_s from windows.cfg to std.cfg.

strcpy_s belongs to the standard so it must be in std.cfg instead of
windows.cfg.
Configuration for strcpy_s has been improved and tests were added.
Found by daca@home
This commit is contained in:
versat 2019-03-05 15:33:16 +01:00
parent fda0f52424
commit df73f7f355
3 changed files with 40 additions and 3 deletions

View File

@ -4643,6 +4643,25 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<strz/>
</arg>
</function>
<!-- errno_t strcpy_s(char *restrict dest, rsize_t destsz, const char *restrict src); // since C11 -->
<function name="strcpy_s">
<noreturn>false</noreturn>
<returnValue type="errno_t"/>
<leak-ignore/>
<arg nr="1" direction="out">
<not-null/>
<minsize type="argvalue" arg="2"/>
</arg>
<arg nr="2" direction="in">
<not-uninit/>
<valid>1:</valid>
</arg>
<arg nr="3" direction="in">
<not-null/>
<not-uninit/>
<strz/>
</arg>
</function>
<!-- wchar_t *wcscpy(wchar_t *deststr, const wchar_t *srcstr); -->
<function name="wcscpy,std::wcscpy">
<returnValue type="wchar_t *"/>

View File

@ -2220,10 +2220,9 @@ HFONT CreateFont(
<not-uninit/>
</arg>
</function>
<!-- errno_t strcpy_s(char *strDestination, size_t numberOfElements, const char *strSource);
errno_t wcscpy_s(wchar_t *strDestination, size_t numberOfElements, const wchar_t *strSource);
<!-- errno_t wcscpy_s(wchar_t *strDestination, size_t numberOfElements, const wchar_t *strSource);
errno_t _mbscpy_s(unsigned char *strDestination, size_t numberOfElements, const unsigned char *strSource); -->
<function name="strcpy_s,wcscpy_s,_mbscpy_s,_tcscpy_s">
<function name="wcscpy_s,_mbscpy_s,_tcscpy_s">
<noreturn>false</noreturn>
<returnValue type="errno_t"/>
<leak-ignore/>

View File

@ -44,6 +44,8 @@ void bufferAccessOutOfBounds(void)
// cppcheck-suppress bufferAccessOutOfBounds
// TODO cppcheck-suppress redundantCopy
strcpy(a, "abcde");
// cppcheck-suppress bufferAccessOutOfBounds
strcpy_s(a, 10, "abcdefghij");
// TODO cppcheck-suppress redundantCopy
strncpy(a,"abcde",5);
// cppcheck-suppress bufferAccessOutOfBounds
@ -191,6 +193,10 @@ void nullpointer(int value)
// cppcheck-suppress nullPointer
wcscmp(0,0);
// cppcheck-suppress nullPointer
strcpy_s(0,1,1);
// cppcheck-suppress nullPointer
strcpy_s(1,1,0);
// cppcheck-suppress nullPointer
strncpy(0,0,1);
// cppcheck-suppress nullPointer
strncpy_s(0,1,1,1);
@ -2956,6 +2962,16 @@ void uninitvar_strcpy(void)
(void)strcpy(str1,str2);
}
void uninitvar_strcpy_s(char * strDest)
{
char *strUninit1;
char *strUninit2;
// cppcheck-suppress uninitvar
(void)strcpy_s(strUninit1, 1, "a");
// cppcheck-suppress uninitvar
(void)strcpy_s(strDest, 1, strUninit2);
}
void uninitvar_wcscpy(void)
{
wchar_t *str1;
@ -3822,6 +3838,9 @@ void invalidFunctionArg(char c)
(void)toupper(c);
(void)toupper(0);
(void)toupper(255);
/* cppcheck-suppress invalidFunctionArg */
(void)strcpy_s(1,0,"a");
}
void invalidFunctionArgString(char c)