From f7438095bf5a055e63d1490f525afc72b0629531 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Wed, 7 Oct 2026 10:36:51 +0200 Subject: [PATCH 1/3] update tests --- test/cfg/std.c | 20 -------------------- test/cfg/std.cpp | 32 -------------------------------- test/cfg/windows.cpp | 26 ++++++++++++++++++++++++++ 3 files changed, 26 insertions(+), 52 deletions(-) diff --git a/test/cfg/std.c b/test/cfg/std.c index 997f8204f73..1adaf63f7a4 100644 --- a/test/cfg/std.c +++ b/test/cfg/std.c @@ -171,26 +171,6 @@ void nullPointer_qsort(void *base, size_t n, size_t size, int (*cmp)(const void qsort(base, n, size, qsort_cmpfunc); } -// As with all bounds-checked functions, localtime_s is only guaranteed to be available if __STDC_LIB_EXT1__ is defined by the implementation and if the user defines __STDC_WANT_LIB_EXT1__ to the integer constant 1 before including time.h. -#ifdef __STDC_LIB_EXT1__ -void uninitvar_localtime_s(const time_t *restrict time, struct tm *restrict result) -{ - const time_t *restrict Time; - // cppcheck-suppress uninitvar - (void)localtime_s(Time, result); - (void)localtime_s(time, result); -} - -void nullPointer_localtime_s(const time_t *restrict time, struct tm *restrict result) -{ - // cppcheck-suppress nullPointer - (void)localtime_s(NULL, result); - // cppcheck-suppress nullPointer - (void)localtime_s(time, NULL); - (void)localtime_s(time, result); -} -#endif // __STDC_LIB_EXT1__ - size_t bufferAccessOutOfBounds_wcsrtombs(char * dest, const wchar_t ** src, size_t len, mbstate_t * ps) { char buf[42]; diff --git a/test/cfg/std.cpp b/test/cfg/std.cpp index e4753a09f7c..27a4beada03 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -689,38 +689,6 @@ void *bufferAccessOutOfBounds_memchr(void *s, int c, size_t n) return std::memchr(s,c,n); } -// As with all bounds-checked functions, localtime_s is only guaranteed to be available if __STDC_LIB_EXT1__ is defined by the implementation and if the user defines __STDC_WANT_LIB_EXT1__ to the integer constant 1 before including time.h. -#ifdef __STDC_LIB_EXT1__ -void uninitvar_localtime_s(const std::time_t *restrict time, struct tm *restrict result) -{ - // cppcheck-suppress valueFlowBailoutIncompleteVar - const std::time_t *restrict Time; - // TODO cppcheck-suppress uninitvar - (void)std::localtime_s(Time, result); - (void)std::localtime_s(time, result); -} - -void nullPointer_localtime_s(const std::time_t *restrict time, struct tm *restrict result) -{ - // cppcheck-suppress nullPointer - (void)std::localtime_s(NULL, result); - // cppcheck-suppress nullPointer - (void)std::localtime_s(time, NULL); - (void)std::localtime_s(time, result); -} - -void memleak_localtime_s(const std::time_t *restrict time, struct tm *restrict result) // #9258 -{ - const time_t t = time(0); - const struct tm* const now = new tm(); - if (localtime_s(now, &t) == 0) { - // cppcheck-suppress valueFlowBailoutIncompleteVar - std::cout << now->tm_mday << std::endl; - } - // cppcheck-suppress memleak -} -#endif // __STDC_LIB_EXT1__ - size_t nullPointer_strftime(char *s, size_t max, const char *fmt, const struct tm *p) { // cppcheck-suppress nullPointer diff --git a/test/cfg/windows.cpp b/test/cfg/windows.cpp index 37c580a0134..3cb1ef99bf1 100644 --- a/test/cfg/windows.cpp +++ b/test/cfg/windows.cpp @@ -1260,3 +1260,29 @@ void constParameterPointer_SetupDiGetDeviceInstanceId(HDEVINFO info, SP_DEVINFO_ TCHAR buffer[buffer_size]; SetupDiGetDeviceInstanceId(info, data, buffer, buffer_size, NULL); } + +void uninitvar_localtime_s(const time_t *time, struct tm *result) +{ + time_t Time; + // cppcheck-suppress uninitvar + (void)localtime_s(result, &Time); + (void)localtime_s(result, time); +} + +void nullPointer_localtime_s(const time_t *time, struct tm *result) +{ + // cppcheck-suppress nullPointer + (void)localtime_s(result, NULL); + // cppcheck-suppress nullPointer + (void)localtime_s(NULL, time); + (void)localtime_s(result, time); +} + +void memleak_localtime_s(void) // #9258 +{ + const time_t t = time(0); + struct tm *const now = new tm(); + if (localtime_s(now, &t) == 0) + printf("%d\n", now->tm_mday); + // cppcheck-suppress memleak +} From 5426ee6e0db51a82df7c7a4a809535f3776531a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Wed, 7 Oct 2026 10:44:23 +0200 Subject: [PATCH 2/3] add test --- test/cfg/windows.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/cfg/windows.cpp b/test/cfg/windows.cpp index 3cb1ef99bf1..9beac7f6a86 100644 --- a/test/cfg/windows.cpp +++ b/test/cfg/windows.cpp @@ -1263,9 +1263,11 @@ void constParameterPointer_SetupDiGetDeviceInstanceId(HDEVINFO info, SP_DEVINFO_ void uninitvar_localtime_s(const time_t *time, struct tm *result) { - time_t Time; + time_t uninit_time; + struct tm uninit_result; // cppcheck-suppress uninitvar - (void)localtime_s(result, &Time); + (void)localtime_s(result, &uninit_time); + (void)localtime_s(&uninit_result, time); (void)localtime_s(result, time); } From f5f75fb889a41fe03255d159938c88381104b3c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Wed, 7 Oct 2026 10:11:41 +0200 Subject: [PATCH 3/3] fix --- cfg/std.cfg | 11 +++++------ cfg/windows.cfg | 5 +++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/cfg/std.cfg b/cfg/std.cfg index 6c434b8715c..2b18eb682f7 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -3238,16 +3238,15 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun - - - + + false - + - - + diff --git a/cfg/windows.cfg b/cfg/windows.cfg index b2251900d42..f01000459c7 100644 --- a/cfg/windows.cfg +++ b/cfg/windows.cfg @@ -4654,9 +4654,10 @@ HFONT CreateFont( - - + false