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 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..9beac7f6a86 100644 --- a/test/cfg/windows.cpp +++ b/test/cfg/windows.cpp @@ -1260,3 +1260,31 @@ 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 uninit_time; + struct tm uninit_result; + // cppcheck-suppress uninitvar + (void)localtime_s(result, &uninit_time); + (void)localtime_s(&uninit_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 +}