From 23450c897d11ccd8dfbe28cf3acca17f016e65be Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Sat, 9 May 2020 08:53:27 +0200 Subject: [PATCH] core: fix compilation with gcc -O3 MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit ../src/core/path.c: In function ‘path_serialize’: ../src/core/path.c:616:24: error: ‘%s’ directive argument is null [-Werror=format-overflow=] 616 | (void) serialize_item_format(f, "path-spec", "%s %%i %%s", | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 617 | path_type_to_string(s->type) //, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 618 | // s->previous_exists, | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 619 | // s->path | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 620 | ); | ~ In function ‘path_spec_dump’, inlined from ‘path_dump’ at ../src/core/path.c:392:17: ../src/core/path.c:226:9: error: ‘%s’ directive argument is null [-Werror=format-overflow=] 226 | fprintf(f, | ^~~~~~~~~~ 227 | "%s%s: %s\n", | ~~~~~~~~~~~~~ 228 | prefix, | ~~~~~~~ 229 | path_type_to_string(s->type), | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 230 | s->path); | ~~~~~~~~ s->type should be valid here, so let's just add an assert. For https://github.com/systemd/systemd/issues/6119#issuecomment-626073743. --- src/core/path.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/core/path.c b/src/core/path.c index c7907ce4bf..1bbf27c5c5 100644 --- a/src/core/path.c +++ b/src/core/path.c @@ -223,11 +223,10 @@ static void path_spec_mkdir(PathSpec *s, mode_t mode) { } static void path_spec_dump(PathSpec *s, FILE *f, const char *prefix) { - fprintf(f, - "%s%s: %s\n", - prefix, - path_type_to_string(s->type), - s->path); + const char *type; + + assert_se(type = path_type_to_string(s->type)); + fprintf(f, "%s%s: %s\n", prefix, type, s->path); } void path_spec_done(PathSpec *s) { @@ -607,14 +606,16 @@ static int path_serialize(Unit *u, FILE *f, FDSet *fds) { (void) serialize_item(f, "result", path_result_to_string(p->result)); LIST_FOREACH(spec, s, p->specs) { + const char *type; _cleanup_free_ char *escaped = NULL; escaped = cescape(s->path); if (!escaped) return log_oom(); + assert_se(type = path_type_to_string(s->type)); (void) serialize_item_format(f, "path-spec", "%s %i %s", - path_type_to_string(s->type), + type, s->previous_exists, s->path); } -- 2.25.1