projects
/
fio.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Use calloc() instead of malloc + memset
[fio.git]
/
json.c
diff --git
a/json.c
b/json.c
index cdc3b2185fa428e3a68842c44b7079448607108b..6145ee489dbd2c6077dfa3a8913fa3935cc49c0c 100644
(file)
--- a/
json.c
+++ b/
json.c
@@
-8,18
+8,12
@@
struct json_object *json_create_object(void)
{
struct json_object *json_create_object(void)
{
- struct json_object *obj = malloc(sizeof(struct json_object));
- if (obj)
- memset(obj, 0, sizeof(struct json_object));
- return obj;
+ return calloc(1, sizeof(struct json_object));
}
struct json_array *json_create_array(void)
{
}
struct json_array *json_create_array(void)
{
- struct json_array *array = malloc(sizeof(struct json_array));
- if (array)
- memset(array, 0, sizeof(struct json_array));
- return array;
+ return calloc(1, sizeof(struct json_array));
}
static struct json_pair *json_create_pair(const char *name, struct json_value *value)
}
static struct json_pair *json_create_pair(const char *name, struct json_value *value)
@@
-35,7
+29,7
@@
static struct json_pair *json_create_pair(const char *name, struct json_value *v
return pair;
}
return pair;
}
-static struct json_value *json_create_value_int(long number)
+static struct json_value *json_create_value_int(long
long
number)
{
struct json_value *value = malloc(sizeof(struct json_value));
{
struct json_value *value = malloc(sizeof(struct json_value));
@@
-84,7
+78,7
@@
static char *strdup_escape(const char *str)
}
/*
}
/*
- * Valid JSON strings must escape '"' and '/' with a prece
e
ding '/'
+ * Valid JSON strings must escape '"' and '/' with a preceding '/'
*/
static struct json_value *json_create_value_string(const char *str)
{
*/
static struct json_value *json_create_value_string(const char *str)
{
@@
-212,7
+206,7
@@
int json_object_add_value_type(struct json_object *obj, const char *name, int ty
if (type == JSON_TYPE_STRING)
value = json_create_value_string(va_arg(args, char *));
else if (type == JSON_TYPE_INTEGER)
if (type == JSON_TYPE_STRING)
value = json_create_value_string(va_arg(args, char *));
else if (type == JSON_TYPE_INTEGER)
- value = json_create_value_int(va_arg(args, long));
+ value = json_create_value_int(va_arg(args, long
long
));
else if (type == JSON_TYPE_FLOAT)
value = json_create_value_float(va_arg(args, double));
else if (type == JSON_TYPE_OBJECT)
else if (type == JSON_TYPE_FLOAT)
value = json_create_value_float(va_arg(args, double));
else if (type == JSON_TYPE_OBJECT)
@@
-248,7
+242,7
@@
int json_array_add_value_type(struct json_array *array, int type, ...)
if (type == JSON_TYPE_STRING)
value = json_create_value_string(va_arg(args, char *));
else if (type == JSON_TYPE_INTEGER)
if (type == JSON_TYPE_STRING)
value = json_create_value_string(va_arg(args, char *));
else if (type == JSON_TYPE_INTEGER)
- value = json_create_value_int(va_arg(args, long));
+ value = json_create_value_int(va_arg(args, long
long
));
else if (type == JSON_TYPE_FLOAT)
value = json_create_value_float(va_arg(args, double));
else if (type == JSON_TYPE_OBJECT)
else if (type == JSON_TYPE_FLOAT)
value = json_create_value_float(va_arg(args, double));
else if (type == JSON_TYPE_OBJECT)
@@
-350,7
+344,7
@@
static void json_print_value(struct json_value *value)
log_info("\"%s\"", value->string);
break;
case JSON_TYPE_INTEGER:
log_info("\"%s\"", value->string);
break;
case JSON_TYPE_INTEGER:
- log_info("%ld", value->integer_number);
+ log_info("%l
l
d", value->integer_number);
break;
case JSON_TYPE_FLOAT:
log_info("%.2f", value->float_number);
break;
case JSON_TYPE_FLOAT:
log_info("%.2f", value->float_number);