std.cfg: Improved configuration of fprintf() and added TODO tests for wcsftime() when array count value exceeds bounds.

This commit is contained in:
orbitcowboy 2022-05-08 18:02:10 +02:00
parent fab55287f7
commit 1942bd5679
3 changed files with 39 additions and 1 deletions

View File

@ -466,9 +466,11 @@
<leak-ignore/>
<arg nr="1" direction="out">
<not-null/>
<minsize type="argvalue" arg="2"/>
</arg>
<arg nr="2" direction="in">
<not-uninit/>
<valid>0:</valid>
</arg>
<arg nr="3" direction="in">
<not-null/>
@ -1604,6 +1606,7 @@
<noreturn>false</noreturn>
<leak-ignore/>
<arg nr="1" direction="inout">
<!-- If stream is a null pointer, all streams are flushed. -->
<not-uninit/>
</arg>
</function>
@ -1900,6 +1903,7 @@
<formatstr/>
<arg nr="2" direction="in">
<formatstr/>
<not-null/>
<not-uninit/>
</arg>
</function>

View File

@ -292,7 +292,7 @@ void nullpointer(int value)
fclose(fp);
fp = 0;
// No FP
fflush(0);
fflush(0); // If stream is a null pointer, all streams are flushed.
fp = freopen(0,"abc",stdin);
fclose(fp);
fp = NULL;
@ -435,6 +435,15 @@ void nullPointer_wcsftime(wchar_t* ptr, size_t maxsize, const wchar_t* format, c
(void)wcsftime(ptr, maxsize, format, timeptr);
}
void bufferAccessOutOfBounds_wcsftime(wchar_t* ptr, size_t maxsize, const wchar_t* format, const struct tm* timeptr)
{
wchar_t buf[42];
(void)wcsftime(buf, 42, format, timeptr);
// TODO cppcheck-suppress bufferAccessOutOfBounds
(void)wcsftime(buf, 43, format, timeptr);
(void)wcsftime(ptr, maxsize, format, timeptr);
}
int nullPointer_wcsncmp(const wchar_t* s1, const wchar_t* s2, size_t n)
{
// cppcheck-suppress nullPointer
@ -1578,6 +1587,14 @@ void uninitvar_fmod(void)
(void)fmodl(ld1,ld2);
}
void nullPointer_fprintf(FILE *Stream, char *Format, int Argument)
{
// cppcheck-suppress nullPointer
(void)fprintf(Stream, NULL, Argument);
// no warning is expected
(void)fprintf(Stream, Format, Argument);
}
void uninitvar_fprintf(FILE *Stream, char *Format, int Argument)
{
FILE *stream1, *stream2;

View File

@ -63,6 +63,23 @@ void invalidFunctionArg_fetestexcept(int excepts)
(void)std::fetestexcept(FE_ALL_EXCEPT+1);
}
void nullPointer_fprintf(FILE *Stream, char *Format, int Argument)
{
// cppcheck-suppress nullPointer
(void)std::fprintf(Stream, nullptr, Argument);
// no warning is expected
(void)std::fprintf(Stream, Format, Argument);
}
void bufferAccessOutOfBounds_wcsftime(wchar_t* ptr, size_t maxsize, const wchar_t* format, const struct tm* timeptr)
{
wchar_t buf[42];
(void)std::wcsftime(buf, 42, format, timeptr);
// TODO cppcheck-suppress bufferAccessOutOfBounds
(void)std::wcsftime(buf, 43, format, timeptr);
(void)std::wcsftime(ptr, maxsize, format, timeptr);
}
int qsort_cmpfunc (const void * a, const void * b) {
return (*static_cast<const int*>(a) - *static_cast<const int*>(b));
}