From 1942bd56791446a3f27c4743ab45392675f962c0 Mon Sep 17 00:00:00 2001 From: orbitcowboy Date: Sun, 8 May 2022 18:02:10 +0200 Subject: [PATCH] std.cfg: Improved configuration of fprintf() and added TODO tests for wcsftime() when array count value exceeds bounds. --- cfg/std.cfg | 4 ++++ test/cfg/std.c | 19 ++++++++++++++++++- test/cfg/std.cpp | 17 +++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/cfg/std.cfg b/cfg/std.cfg index 86ecac53f..7bd1b2a07 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -466,9 +466,11 @@ + + 0: @@ -1604,6 +1606,7 @@ false + @@ -1900,6 +1903,7 @@ + diff --git a/test/cfg/std.c b/test/cfg/std.c index 408c98fd8..337d0efc3 100644 --- a/test/cfg/std.c +++ b/test/cfg/std.c @@ -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; diff --git a/test/cfg/std.cpp b/test/cfg/std.cpp index 174b700ed..890a1737a 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -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(a) - *static_cast(b)); }