]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
client: fix compilation warning about unterminated strings
authorVincent Bernat <vincent@bernat.ch>
Tue, 10 Mar 2026 07:37:08 +0000 (08:37 +0100)
committerVincent Bernat <vincent@bernat.ch>
Tue, 10 Mar 2026 07:37:08 +0000 (08:37 +0100)
With GCC 15, we get:

```
../../../src/client/json_writer.c: In function ‘json_element_dump’:
../../../src/client/json_writer.c:160:43: warning: initializer-string for array of ‘char’ truncates NUL terminator but destination lacks ‘nonstring’ attribute (3 chars into 2 available) [-Wunterminated-string-initialization]
  160 |         static const char pairs[2][2] = { "{}", "[]" };
      |                                           ^~~~
../../../src/client/json_writer.c:160:49: warning: initializer-string for array of ‘char’ truncates NUL terminator but destination lacks ‘nonstring’ attribute (3 chars into 2 available) [-Wunterminated-string-initialization]
  160 |         static const char pairs[2][2] = { "{}", "[]" };
      |                                                 ^~~~
```

This is a false positive as they are not used as strings, but let's
accomodate the compiler by using enough space for the NUL terminator.

src/client/json_writer.c

index dc6665ad83c23286fe856fbf3878bf7eafac13d7..b0c616d303f9b5a3ff9f91e2f92b200cb80d77f5 100644 (file)
@@ -157,7 +157,7 @@ json_string_dump(FILE *fh, const char *s)
 static void
 json_element_dump(FILE *fh, struct element *current, int indent)
 {
-       static const char pairs[2][2] = { "{}", "[]" };
+       static const char pairs[2][3] = { "{}", "[]" };
        struct element *el;
        switch (current->tag) {
        case STRING: