From 06f5f35ad4d929c0f148ad3e18d98665cdd22b92 Mon Sep 17 00:00:00 2001 From: Kano Date: Sun, 1 Jul 2012 00:42:34 +1000 Subject: [PATCH] api.c allow NULL data displayed as (null) --- api.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/api.c b/api.c index 2f584882..d6a18d29 100644 --- a/api.c +++ b/api.c @@ -179,6 +179,7 @@ static const char *DYNAMIC = _DYNAMIC; static const char *YES = "Y"; static const char *NO = "N"; +static const char *NULLSTR = "(null)"; static const char *DEVICECODE = "" #ifdef HAVE_OPENCL @@ -683,6 +684,13 @@ static struct api_data *api_add_data_full(struct api_data *root, char *name, enu api_data->data_was_malloc = copy_data; + // Avoid crashing on bad data + if (data == NULL) { + api_data->type = type = API_CONST; + data = (void *)NULLSTR; + api_data->data_was_malloc = copy_data = false; + } + if (!copy_data) api_data->data = data; else @@ -1763,7 +1771,7 @@ static void summary(__maybe_unused SOCKETTYPE c, __maybe_unused char *param, boo #ifdef WANT_CPUMINE char *algo = (char *)(algo_names[opt_algo]); if (algo == NULL) - algo = "(null)"; + algo = (char *)NULLSTR; #endif utility = total_accepted / ( total_secs ? total_secs : 1 ) * 60;