From 1eac1757ad2fe043df17ac10262648504c226907 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Tue, 17 Jan 2012 15:02:05 +0100 Subject: [PATCH] Don't crash with NULL procname. --- src/xbt/xbt_log_layout_format.c | 6 +++++- src/xbt/xbt_log_layout_simple.c | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/xbt/xbt_log_layout_format.c b/src/xbt/xbt_log_layout_format.c index d09a2fe417..9fe811b881 100644 --- a/src/xbt/xbt_log_layout_format.c +++ b/src/xbt/xbt_log_layout_format.c @@ -64,7 +64,11 @@ static double format_begin_of_time = -1; check_overflow(len); \ } else (void)0 -#define show_string(data) show_it(data, "s") +#define show_string(data) \ + if (1) { \ + const char *show_string_data = (data); \ + show_it(show_string_data ? show_string_data : "(null)", "s"); \ + } else (void)0 #define show_int(data) show_it(data, "d") #define show_double(data) show_it(data, "f") diff --git a/src/xbt/xbt_log_layout_simple.c b/src/xbt/xbt_log_layout_simple.c index 30108d4697..7a81a9c30c 100644 --- a/src/xbt/xbt_log_layout_simple.c +++ b/src/xbt/xbt_log_layout_simple.c @@ -40,7 +40,7 @@ static int xbt_log_layout_simple_doit(xbt_log_layout_t l, /* Display the proc info if available */ procname = xbt_procname(); - if (*procname) { + if (procname && *procname) { len = snprintf(p, rem_size, "%s:%s:(%d) ", gras_os_myname(), procname, xbt_getpid()); check_overflow(len); -- 2.20.1