From: Łukasz Stelmach Date: Thu, 29 Jun 2023 11:05:23 +0000 (+0200) Subject: Avoid passing NULL as format parameter X-Git-Tag: accepted/tizen/unified/dev/20230726.115516^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=39878c1fbc3ff86015e40521ddd22a3b80f82b60;p=platform%2Fupstream%2Fsystemd.git Avoid passing NULL as format parameter GCC reported possible problem with passing NULL returned from *_to_string() helpers as an argument for '%s' in a format string. ../src/core/job.c: In function 'job_finish_and_invalidate': ../src/core/job.c:976:27: error: '%s' directive argument is null [-Werror=format-overflow=] 976 | log_unit_debug(u, "Job %" PRIu32 " %s/%s finished, result=%s", j->id, u->id, job_type_to_string(t), job_result_to_string(result)); | ^~~~~~~ ../src/core/unit.h:878:190: note: in definition of macro 'log_unit_full' 878 | _u ? log_object_internal(level, error, PROJECT_FILE, __LINE__, __func__, _u->manager->unit_log_field, _u->id, _u->manager->invocation_log_field, _u->invocation_id_string, ##__VA_ARGS__) : \ | ^~~~~~~~~~~ ../src/core/job.c:976:9: note: in expansion of macro 'log_unit_debug' 976 | log_unit_debug(u, "Job %" PRIu32 " %s/%s finished, result=%s", j->id, u->id, job_type_to_string(t), job_result_to_string(result)); | ^~~~~~~~~~~~~~ Wrapping the helpers in strna() prevents this from happening. Further fixes may be applied depending on the outcomes of the discussion on the systemd-devel mailing list. Change-Id: Id73f2bc887f46bb07fc960d264953cd5dfce82de Link: https://lists.freedesktop.org/archives/systemd-devel/2023-June/049215.html Signed-off-by: Łukasz Stelmach --- diff --git a/src/core/job.c b/src/core/job.c index 5048a50..ffd7cd8 100644 --- a/src/core/job.c +++ b/src/core/job.c @@ -973,7 +973,9 @@ int job_finish_and_invalidate(Job *j, JobResult result, bool recursive, bool alr j->result = result; - log_unit_debug(u, "Job %" PRIu32 " %s/%s finished, result=%s", j->id, u->id, job_type_to_string(t), job_result_to_string(result)); + log_unit_debug(u, "Job %" PRIu32 " %s/%s finished, result=%s", + j->id, u->id, strna(job_type_to_string(t)), + strna(job_result_to_string(result))); /* If this job did nothing to respective unit we don't log the status message */ if (!already)