]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
time: fix warning in timestring creation
authorVictor Julien <vjulien@oisf.net>
Tue, 26 Apr 2022 19:03:42 +0000 (21:03 +0200)
committerVictor Julien <vjulien@oisf.net>
Tue, 3 May 2022 11:30:19 +0000 (13:30 +0200)
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.
(cherry picked from commit 2f48e432cd4465bbb1f42fe7778fee44a5d0aa47)

src/util-time.c

index 8da993739dcbeb20528a37b7173bb3a0f10701ae..5cfa38a340868c2c0ccd6e5bf3cd7db045c6cbc6 100644 (file)
@@ -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");