json: allow empty string values
authorVincent Fu <vincent.fu@samsung.com>
Tue, 7 Jan 2025 20:56:19 +0000 (20:56 +0000)
committerVincent Fu <vincent.fu@samsung.com>
Thu, 23 Jan 2025 17:57:42 +0000 (12:57 -0500)
The JSON standard permits empty strings. Currently fio's JSON module
returns an error when it encounters an empty string. Change this to
allow empty strings.

https://www.json.org/ is the reference I used for the JSON standard.

This is needed for upcoming patches to support FIO_OPT_STR_SET job
options (norandommap, time_based, etc) that are enabled when the option
is included without specifying a value for it. The value for these
options is best represented by an empty string. Disallowing empty string
values would prevent these options from appearing in job option
dictionaries in the JSON output.

Signed-off-by: Vincent Fu <vincent.fu@samsung.com>
json.c

diff --git a/json.c b/json.c
index cd3d5d74db12aab06409e523b95d9eed3c013682..6375b3c2faac225d5980d727fac2a0558b53da7d 100644 (file)
--- a/json.c
+++ b/json.c
@@ -56,9 +56,6 @@ static char *strdup_escape(const char *str)
        char *p, *ret;
        int escapes;
 
-       if (!strlen(str))
-               return NULL;
-
        escapes = 0;
        while ((input = strpbrk(input, "\\\"")) != NULL) {
                escapes++;