Skip to content

Commit 16c5a11

Browse files
authored
posix.cfg: Warn in case the return value of localtime() is ignored. (#5555)
1 parent 903df84 commit 16c5a11

2 files changed

Lines changed: 10 additions & 0 deletions

File tree

cfg/posix.cfg

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4054,6 +4054,7 @@ The function 'mktemp' is considered to be dangerous due to race conditions and s
40544054
<noreturn>false</noreturn>
40554055
<returnValue type="struct tm *"/>
40564056
<leak-ignore/>
4057+
<use-retval/>
40574058
<arg nr="1" direction="in">
40584059
<not-null/>
40594060
<not-uninit/>

test/cfg/posix.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <stdarg.h>
3131
#include <ctype.h>
3232
#include <stdbool.h>
33+
#include <time.h>
3334
#if !(defined(__APPLE__) && defined(__MACH__))
3435
#include <mqueue.h>
3536
#endif
@@ -169,6 +170,14 @@ void invalidFunctionArgStr_mbsnrtowcs(void)
169170
if (mbsnrtowcs (wenough, &cp, 1, 10, &s) != 1 || wcscmp (wenough, L"AEF") != 0) {}
170171
}
171172

173+
struct tm * ignoredReturnValue_localtime(const time_t *tp)
174+
{
175+
// cppcheck-suppress [ignoredReturnValue,localtimeCalled]
176+
localtime(tp);
177+
// cppcheck-suppress localtimeCalled
178+
return localtime(tp);
179+
}
180+
172181
int nullPointer_getpwuid_r(uid_t uid, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result)
173182
{
174183
// cppcheck-suppress nullPointer

0 commit comments

Comments
 (0)