]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal-importer: avoid false maybe-uninitialized warning
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 23 Jun 2026 15:32:16 +0000 (00:32 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 27 Jun 2026 05:04:48 +0000 (14:04 +0900)
Observerd on Ubuntu 24.04 with GCC 13 on arm64 architecture.
```
../src/shared/journal-importer.c: In function ‘journal_importer_process_data’:
../src/shared/journal-importer.c:344:30: error: ‘line’ may be used uninitialized [-Werror=maybe-uninitialized]
  344 |                         if (!journal_field_valid(line, n - 1, true)) {
      |                              ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../src/shared/journal-importer.c:295:23: note: ‘line’ was declared here
  295 |                 char *line, *sep;
      |                       ^~~~
cc1: all warnings being treated as errors
```

src/shared/journal-importer.c

index 471ad879a4d437c310724d046d85ed3f7d5051e6..128866e17c5a88b34f18abd8584eaedd69bbe73b 100644 (file)
@@ -292,7 +292,7 @@ int journal_importer_process_data(JournalImporter *imp) {
 
         switch (imp->state) {
         case IMPORTER_STATE_LINE: {
-                char *line, *sep;
+                char *line = NULL;  /* avoid false maybe-uninitialized warning */
                 size_t n = 0;
 
                 assert(imp->data_size == 0);
@@ -317,7 +317,7 @@ int journal_importer_process_data(JournalImporter *imp) {
                    COREDUMP\n
                    LLLLLLLL0011223344...\n
                 */
-                sep = memchr(line, '=', n);
+                char *sep = memchr(line, '=', n);
                 if (sep) {
                         /* chomp newline */
                         n--;