Commit 06f5f35ad4d929c0f148ad3e18d98665cdd22b92

Kano 2012-07-01T00:42:34

api.c allow NULL data displayed as (null)

diff --git a/api.c b/api.c
index 2f58488..d6a18d2 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;