提交 0bb18439 编写于 作者: M Max Bruckner

print_value: return as soon as possible

上级 5ea4fad2
......@@ -1049,27 +1049,34 @@ static cJSON_bool print_value(const cJSON * const item, const size_t depth, cons
{
case cJSON_NULL:
output = ensure(output_buffer, 5, hooks);
if (output != NULL)
if (output == NULL)
{
strcpy((char*)output, "null");
return false;
}
break;
strcpy((char*)output, "null");
return true;
case cJSON_False:
output = ensure(output_buffer, 6, hooks);
if (output != NULL)
if (output == NULL)
{
strcpy((char*)output, "false");
return false;
}
break;
strcpy((char*)output, "false");
return true;
case cJSON_True:
output = ensure(output_buffer, 5, hooks);
if (output != NULL)
if (output == NULL)
{
strcpy((char*)output, "true");
return false;
}
break;
strcpy((char*)output, "true");
return true;
case cJSON_Number:
return print_number(item, output_buffer, hooks);
case cJSON_Raw:
{
size_t raw_length = 0;
......@@ -1079,31 +1086,31 @@ static cJSON_bool print_value(const cJSON * const item, const size_t depth, cons
{
hooks->deallocate(output_buffer->buffer);
}
output = NULL;
break;
return false;
}
raw_length = strlen(item->valuestring) + sizeof('\0');
output = ensure(output_buffer, raw_length, hooks);
if (output != NULL)
if (output == NULL)
{
memcpy(output, item->valuestring, raw_length);
return false;
}
break;
memcpy(output, item->valuestring, raw_length);
return true;
}
case cJSON_String:
return print_string(item, output_buffer, hooks);
break;
case cJSON_Array:
return print_array(item, depth, format, output_buffer, hooks);
case cJSON_Object:
return print_object(item, depth, format, output_buffer, hooks);
default:
output = NULL;
break;
return false;
}
return output != NULL;
}
/* Build an array from input text. */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册