std.cfg: Improved configuration of localtime_s()

This commit is contained in:
orbitcowboy 2022-05-01 12:47:13 +02:00
parent 0410f01647
commit 5db6fc1f54
3 changed files with 43 additions and 0 deletions

View File

@ -3178,6 +3178,7 @@ The obsolete function 'gets' is called. With 'gets' you'll get a buffer overrun
<leak-ignore/>
<arg nr="1" direction="in">
<not-null/>
<not-uninit/>
</arg>
<arg nr="2" direction="out">
<not-null/>

View File

@ -19,12 +19,33 @@
#include <wctype.h>
#include <fenv.h>
#include <setjmp.h>
#define __STDC_WANT_LIB_EXT1__ 1
#include <time.h>
#include <stdbool.h>
#include <stdint.h>
#include <inttypes.h>
#include <float.h>
// 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];

View File

@ -21,6 +21,7 @@
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define __STDC_WANT_LIB_EXT1__ 1
#include <ctime>
#include <cwchar>
#include <fstream>
@ -31,6 +32,26 @@
#include <iterator>
#include <vector>
// 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