@@ -119,12 +119,9 @@ static void obj_add_result(struct json_object *o, const char *v, ...)
119119 va_start (ap , v );
120120
121121 if (vasprintf (& value , v , ap ) < 0 )
122- value = NULL ;
122+ value = "Could not allocate string" ;
123123
124- if (value )
125- obj_add_str (o , "Result" , value );
126- else
127- obj_add_str (o , "Result" , "Could not allocate string" );
124+ obj_add_str (o , "Result" , value );
128125
129126 va_end (ap );
130127}
@@ -138,12 +135,9 @@ static void obj_add_key(struct json_object *o, const char *k, const char *v, ...
138135 va_start (ap , v );
139136
140137 if (vasprintf (& value , v , ap ) < 0 )
141- value = NULL ;
138+ value = "Could not allocate string" ;
142139
143- if (value )
144- obj_add_str (o , k , value );
145- else
146- obj_add_str (o , k , "Could not allocate string" );
140+ obj_add_str (o , k , value );
147141
148142 va_end (ap );
149143}
@@ -4588,9 +4582,9 @@ static void json_output_error_status(int status, const char *msg, va_list ap)
45884582 _cleanup_free_ char * value = NULL ;
45894583
45904584 if (vasprintf (& value , msg , ap ) < 0 )
4591- value = NULL ;
4585+ value = "Could not allocate string" ;
45924586
4593- sprintf (json_str , "Error: %s" , value ? value : "Could not allocate string" );
4587+ sprintf (json_str , "Error: %s" , value );
45944588 r = obj_create (json_str );
45954589
45964590 if (status < 0 ) {
@@ -4628,9 +4622,9 @@ static void json_output_message(bool error, const char *msg, va_list ap)
46284622 _cleanup_free_ char * value = NULL ;
46294623
46304624 if (vasprintf (& value , msg , ap ) < 0 )
4631- value = NULL ;
4625+ value = "Could not allocate string" ;
46324626
4633- obj_add_str (r , error ? "error" : "result" , value ? value : "Could not allocate string" );
4627+ obj_add_str (r , error ? "error" : "result" , value );
46344628
46354629 obj_print (r );
46364630}
@@ -4642,12 +4636,9 @@ static void json_output_perror(const char *msg)
46424636 _cleanup_free_ char * error = NULL ;
46434637
46444638 if (asprintf (& error , "%s: %s" , msg , strerror (errno )) < 0 )
4645- error = NULL ;
4639+ error = "Could not allocate string" ;
46464640
4647- if (error )
4648- obj_add_str (r , "error" , error );
4649- else
4650- obj_add_str (r , "error" , "Could not allocate string" );
4641+ obj_add_str (r , "error" , error );
46514642
46524643 json_output_object (r );
46534644}
0 commit comments