time: fix warning in timestring creation

cppcheck:

src/util-time.c:255:18: warning: Either the condition 'str!=NULL' is redundant or there is possible null pointer dereference: str. [nullPointerRedundantCheck]
        snprintf(str, size, "ts-error");
                 ^
src/util-time.c:252:48: note: Assuming that condition 'str!=NULL' is not redundant
    if (likely(t != NULL && fmt != NULL && str != NULL)) {
                                               ^
src/util-time.c:255:18: note: Null pointer dereference
        snprintf(str, size, "ts-error");
                 ^

Only `t` could possibly be NULL if `localtime_r` fails elsewhere.

Bug: #5291.
pull/7321/head
Victor Julien 4 years ago
parent 4fcb8740e7
commit 2f48e432cd

@ -249,7 +249,7 @@ void CreateUtcIsoTimeString (const struct timeval *ts, char *str, size_t size)
void CreateFormattedTimeString (const struct tm *t, const char *fmt, char *str, size_t size)
{
if (likely(t != NULL && fmt != NULL && str != NULL)) {
if (likely(t != NULL)) {
strftime(str, size, fmt, t);
} else {
snprintf(str, size, "ts-error");

Loading…
Cancel
Save