]> git.ipfire.org Git - thirdparty/ulogd2.git/commitdiff
output: JSON: optimize appending of newline to output
authorJeremy Sowden <jeremy@azazel.net>
Tue, 30 Nov 2021 10:55:58 +0000 (10:55 +0000)
committerPablo Neira Ayuso <pablo@netfilter.org>
Mon, 3 Jan 2022 16:58:23 +0000 (17:58 +0100)
We have `buflen` available.  We can remove `strncat` and assign the characters
directly, without traversing the whole buffer.

Fixes a compiler warning:

  logd_output_JSON.c:407:9: warning: `strncat` specified bound 1 equals source length

Signed-off-by: Jeremy Sowden <jeremy@azazel.net>
Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
output/ulogd_output_JSON.c

index 2166d15d6363e4801c0eb7691798bcd3baad9f16..913dfb84c8e74c7a1a27f4c03bf48a7bda78ed7f 100644 (file)
@@ -404,8 +404,8 @@ static int json_interp(struct ulogd_pluginstance *upi)
                return ULOGD_IRET_ERR;
        }
        buf = tmp;
-       strncat(buf, "\n", 1);
-       buflen++;
+       buf[buflen++] = '\n';
+       buf[buflen]   = '\0';
 
        if (opi->mode == JSON_MODE_FILE)
                return json_interp_file(upi, buf);