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 <l.stelmach@samsung.com>
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)