From 16c5a117866edf4d1142303925cbfeda07638e8a Mon Sep 17 00:00:00 2001 From: orbitcowboy Date: Sat, 14 Oct 2023 16:59:42 +0200 Subject: [PATCH] posix.cfg: Warn in case the return value of localtime() is ignored. (#5555) --- cfg/posix.cfg | 1 + test/cfg/posix.c | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/cfg/posix.cfg b/cfg/posix.cfg index 66e01ad92..25712fceb 100644 --- a/cfg/posix.cfg +++ b/cfg/posix.cfg @@ -4054,6 +4054,7 @@ The function 'mktemp' is considered to be dangerous due to race conditions and s false + diff --git a/test/cfg/posix.c b/test/cfg/posix.c index 90e9c6389..a163f4ed8 100644 --- a/test/cfg/posix.c +++ b/test/cfg/posix.c @@ -30,6 +30,7 @@ #include #include #include +#include #if !(defined(__APPLE__) && defined(__MACH__)) #include #endif @@ -169,6 +170,14 @@ void invalidFunctionArgStr_mbsnrtowcs(void) if (mbsnrtowcs (wenough, &cp, 1, 10, &s) != 1 || wcscmp (wenough, L"AEF") != 0) {} } +struct tm * ignoredReturnValue_localtime(const time_t *tp) +{ + // cppcheck-suppress [ignoredReturnValue,localtimeCalled] + localtime(tp); + // cppcheck-suppress localtimeCalled + return localtime(tp); +} + int nullPointer_getpwuid_r(uid_t uid, struct passwd *pwd, char *buffer, size_t bufsize, struct passwd **result) { // cppcheck-suppress nullPointer