diff --git a/cfg/std.cfg b/cfg/std.cfg index 11b20948e..cb1bf28cc 100644 --- a/cfg/std.cfg +++ b/cfg/std.cfg @@ -3178,6 +3178,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun + diff --git a/test/cfg/std.c b/test/cfg/std.c index f3e600b03..97fef1fbb 100644 --- a/test/cfg/std.c +++ b/test/cfg/std.c @@ -19,12 +19,33 @@ #include #include #include +#define __STDC_WANT_LIB_EXT1__ 1 #include #include #include #include #include +// 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 6be4cd6db..d6e3bf460 100644 --- a/test/cfg/std.cpp +++ b/test/cfg/std.cpp @@ -21,6 +21,7 @@ #include #include #include +#define __STDC_WANT_LIB_EXT1__ 1 #include #include #include @@ -31,6 +32,26 @@ #include #include +// 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) +{ + 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); +} +#endif // __STDC_LIB_EXT1__ + size_t nullPointer_strftime(char *s, size_t max, const char *fmt, const struct tm *p) { // cppcheck-suppress nullPointer