Fix: event field value: assertion fails on empty string
[lttng-tools.git] / src / common / event-field-value.c
index b57c7c53e206fc249de919575583e04234aef923..2dd1947c2eaaf5cbb10763423bfb786b779cb8cc 100644 (file)
@@ -190,8 +190,16 @@ struct lttng_event_field_value *lttng_event_field_value_string_create_with_size(
                goto error;
        }
 
-       assert(val);
-       field_val->val = strndup(val, size);
+       if (size) {
+               assert(val);
+               field_val->val = strndup(val, size);
+       } else {
+               /*
+                * User code do not expect a NULL string pointer. Populate with
+                * an empty string when length is 0.
+                */
+               field_val->val = strdup("");
+       }
        if (!field_val->val) {
                goto error;
        }
This page took 0.023383 seconds and 4 git commands to generate.