1090 lines
42 KiB
Diff
1090 lines
42 KiB
Diff
From 6e5b1a93fb3fd25d23ad4cf8cc99251a863cccd3 Mon Sep 17 00:00:00 2001
|
|
From: tanyifeng <tanyifeng1@huawei.com>
|
|
Date: Fri, 12 Apr 2019 06:06:12 -0400
|
|
Subject: [PATCH 085/139] lxc: update json file from isulad
|
|
|
|
Signed-off-by: tanyifeng <tanyifeng1@huawei.com>
|
|
Signed-off-by: LiFeng <lifeng68@huawei.com>
|
|
---
|
|
src/lxc/json/defs.c | 38 +++++-----
|
|
src/lxc/json/json_common.c | 160 +++++++++++++++++++--------------------
|
|
src/lxc/json/json_common.h | 2 +-
|
|
src/lxc/json/logger_json_file.c | 50 ++++++------
|
|
src/lxc/json/oci_runtime_hooks.c | 3 +-
|
|
src/lxc/json/oci_runtime_spec.c | 32 ++++----
|
|
6 files changed, 142 insertions(+), 143 deletions(-)
|
|
|
|
diff --git a/src/lxc/json/defs.c b/src/lxc/json/defs.c
|
|
index 38df2f7..e7d9a09 100644
|
|
--- a/src/lxc/json/defs.c
|
|
+++ b/src/lxc/json/defs.c
|
|
@@ -15,20 +15,20 @@ defs_hook *make_defs_hook(yajl_val tree, struct parser_context *ctx, parser_erro
|
|
ret = safe_malloc(sizeof(*ret));
|
|
{
|
|
yajl_val val = get_val(tree, "path", yajl_t_string);
|
|
- if (val) {
|
|
+ if (val != NULL) {
|
|
char *str = YAJL_GET_STRING(val);
|
|
ret->path = safe_strdup(str ? str : "");
|
|
}
|
|
}
|
|
{
|
|
yajl_val tmp = get_val(tree, "args", yajl_t_array);
|
|
- if (tmp && YAJL_GET_ARRAY(tmp)) {
|
|
+ if (tmp != NULL && YAJL_GET_ARRAY(tmp) != NULL && YAJL_GET_ARRAY(tmp)->len > 0) {
|
|
size_t i;
|
|
ret->args_len = YAJL_GET_ARRAY(tmp)->len;
|
|
ret->args = safe_malloc((YAJL_GET_ARRAY(tmp)->len + 1) * sizeof(*ret->args));
|
|
for (i = 0; i < YAJL_GET_ARRAY(tmp)->len; i++) {
|
|
yajl_val val = YAJL_GET_ARRAY(tmp)->values[i];
|
|
- if (val) {
|
|
+ if (val != NULL) {
|
|
char *str = YAJL_GET_STRING(val);
|
|
ret->args[i] = safe_strdup(str ? str : "");
|
|
}
|
|
@@ -37,13 +37,13 @@ defs_hook *make_defs_hook(yajl_val tree, struct parser_context *ctx, parser_erro
|
|
}
|
|
{
|
|
yajl_val tmp = get_val(tree, "env", yajl_t_array);
|
|
- if (tmp && YAJL_GET_ARRAY(tmp)) {
|
|
+ if (tmp != NULL && YAJL_GET_ARRAY(tmp) != NULL && YAJL_GET_ARRAY(tmp)->len > 0) {
|
|
size_t i;
|
|
ret->env_len = YAJL_GET_ARRAY(tmp)->len;
|
|
ret->env = safe_malloc((YAJL_GET_ARRAY(tmp)->len + 1) * sizeof(*ret->env));
|
|
for (i = 0; i < YAJL_GET_ARRAY(tmp)->len; i++) {
|
|
yajl_val val = YAJL_GET_ARRAY(tmp)->values[i];
|
|
- if (val) {
|
|
+ if (val != NULL) {
|
|
char *str = YAJL_GET_STRING(val);
|
|
ret->env[i] = safe_strdup(str ? str : "");
|
|
}
|
|
@@ -52,7 +52,7 @@ defs_hook *make_defs_hook(yajl_val tree, struct parser_context *ctx, parser_erro
|
|
}
|
|
{
|
|
yajl_val val = get_val(tree, "timeout", yajl_t_number);
|
|
- if (val) {
|
|
+ if (val != NULL) {
|
|
int invalid = common_safe_int(YAJL_GET_NUMBER(val), (int *)&ret->timeout);
|
|
if (invalid) {
|
|
if (asprintf(err, "Invalid value '%s' with type 'integer' for key 'timeout': %s", YAJL_GET_NUMBER(val), strerror(-invalid)) < 0)
|
|
@@ -84,14 +84,14 @@ defs_hook *make_defs_hook(yajl_val tree, struct parser_context *ctx, parser_erro
|
|
}
|
|
|
|
void free_defs_hook(defs_hook *ptr) {
|
|
- if (!ptr)
|
|
+ if (ptr == NULL)
|
|
return;
|
|
free(ptr->path);
|
|
ptr->path = NULL;
|
|
- if (ptr->args) {
|
|
+ if (ptr->args != NULL) {
|
|
size_t i;
|
|
for (i = 0; i < ptr->args_len; i++) {
|
|
- if (ptr->args[i]) {
|
|
+ if (ptr->args[i] != NULL) {
|
|
free(ptr->args[i]);
|
|
ptr->args[i] = NULL;
|
|
}
|
|
@@ -99,10 +99,10 @@ void free_defs_hook(defs_hook *ptr) {
|
|
free(ptr->args);
|
|
ptr->args = NULL;
|
|
}
|
|
- if (ptr->env) {
|
|
+ if (ptr->env != NULL) {
|
|
size_t i;
|
|
for (i = 0; i < ptr->env_len; i++) {
|
|
- if (ptr->env[i]) {
|
|
+ if (ptr->env[i] != NULL) {
|
|
free(ptr->env[i]);
|
|
ptr->env[i] = NULL;
|
|
}
|
|
@@ -119,24 +119,24 @@ yajl_gen_status gen_defs_hook(yajl_gen g, defs_hook *ptr, struct parser_context
|
|
stat = reformat_start_map(g);
|
|
if (yajl_gen_status_ok != stat)
|
|
GEN_SET_ERROR_AND_RETURN(stat, err);
|
|
- if ((ctx->options & GEN_OPTIONS_ALLKEYVALUE) ||(ptr && ptr->path)) {
|
|
+ if ((ctx->options & GEN_OPTIONS_ALLKEYVALUE) ||(ptr != NULL && ptr->path != NULL)) {
|
|
char *str = "";
|
|
stat = reformat_map_key(g, "path", strlen("path"));
|
|
if (yajl_gen_status_ok != stat)
|
|
GEN_SET_ERROR_AND_RETURN(stat, err);
|
|
- if (ptr && ptr->path) {
|
|
+ if (ptr != NULL && ptr->path != NULL) {
|
|
str = ptr->path;
|
|
}
|
|
stat = reformat_string(g, str, strlen(str));
|
|
if (yajl_gen_status_ok != stat)
|
|
GEN_SET_ERROR_AND_RETURN(stat, err);
|
|
}
|
|
- if ((ctx->options & GEN_OPTIONS_ALLKEYVALUE) ||(ptr && ptr->args)) {
|
|
+ if ((ctx->options & GEN_OPTIONS_ALLKEYVALUE) || (ptr != NULL && ptr->args != NULL)) {
|
|
size_t len = 0, i;
|
|
stat = reformat_map_key(g, "args", strlen("args"));
|
|
if (yajl_gen_status_ok != stat)
|
|
GEN_SET_ERROR_AND_RETURN(stat, err);
|
|
- if (ptr && ptr->args) {
|
|
+ if (ptr != NULL && ptr->args != NULL) {
|
|
len = ptr->args_len;
|
|
}
|
|
if (!len && !(ctx->options & GEN_OPTIONS_SIMPLIFY))
|
|
@@ -155,12 +155,12 @@ yajl_gen_status gen_defs_hook(yajl_gen g, defs_hook *ptr, struct parser_context
|
|
if (!len && !(ctx->options & GEN_OPTIONS_SIMPLIFY))
|
|
yajl_gen_config(g, yajl_gen_beautify, 1);
|
|
}
|
|
- if ((ctx->options & GEN_OPTIONS_ALLKEYVALUE) ||(ptr && ptr->env)) {
|
|
+ if ((ctx->options & GEN_OPTIONS_ALLKEYVALUE) || (ptr != NULL && ptr->env != NULL)) {
|
|
size_t len = 0, i;
|
|
stat = reformat_map_key(g, "env", strlen("env"));
|
|
if (yajl_gen_status_ok != stat)
|
|
GEN_SET_ERROR_AND_RETURN(stat, err);
|
|
- if (ptr && ptr->env) {
|
|
+ if (ptr != NULL && ptr->env != NULL) {
|
|
len = ptr->env_len;
|
|
}
|
|
if (!len && !(ctx->options & GEN_OPTIONS_SIMPLIFY))
|
|
@@ -179,12 +179,12 @@ yajl_gen_status gen_defs_hook(yajl_gen g, defs_hook *ptr, struct parser_context
|
|
if (!len && !(ctx->options & GEN_OPTIONS_SIMPLIFY))
|
|
yajl_gen_config(g, yajl_gen_beautify, 1);
|
|
}
|
|
- if ((ctx->options & GEN_OPTIONS_ALLKEYVALUE) ||(ptr && ptr->timeout)) {
|
|
+ if ((ctx->options & GEN_OPTIONS_ALLKEYVALUE) ||(ptr != NULL && ptr->timeout)) {
|
|
long long int num = 0;
|
|
stat = reformat_map_key(g, "timeout", strlen("timeout"));
|
|
if (yajl_gen_status_ok != stat)
|
|
GEN_SET_ERROR_AND_RETURN(stat, err);
|
|
- if (ptr && ptr->timeout) {
|
|
+ if (ptr != NULL && ptr->timeout) {
|
|
num = (long long int)ptr->timeout;
|
|
}
|
|
stat = reformat_int(g, num);
|
|
diff --git a/src/lxc/json/json_common.c b/src/lxc/json/json_common.c
|
|
index e339ab3..54b7b61 100755
|
|
--- a/src/lxc/json/json_common.c
|
|
+++ b/src/lxc/json/json_common.c
|
|
@@ -111,7 +111,7 @@ int common_safe_double(const char *numstr, double *converted) {
|
|
char *err_str = NULL;
|
|
double d;
|
|
|
|
- if (!numstr) {
|
|
+ if (numstr == NULL) {
|
|
return -EINVAL;
|
|
}
|
|
|
|
@@ -121,7 +121,7 @@ int common_safe_double(const char *numstr, double *converted) {
|
|
return -errno;
|
|
}
|
|
|
|
- if (!err_str || err_str == numstr || *err_str != '\0') {
|
|
+ if (err_str == NULL || err_str == numstr || *err_str != '\0') {
|
|
return -EINVAL;
|
|
}
|
|
|
|
@@ -133,7 +133,7 @@ int common_safe_uint8(const char *numstr, uint8_t *converted) {
|
|
char *err = NULL;
|
|
unsigned long int uli;
|
|
|
|
- if (!numstr) {
|
|
+ if (numstr == NULL) {
|
|
return -EINVAL;
|
|
}
|
|
|
|
@@ -143,7 +143,7 @@ int common_safe_uint8(const char *numstr, uint8_t *converted) {
|
|
return -errno;
|
|
}
|
|
|
|
- if (!err || err == numstr || *err != '\0') {
|
|
+ if (err == NULL || err == numstr || *err != '\0') {
|
|
return -EINVAL;
|
|
}
|
|
|
|
@@ -159,7 +159,7 @@ int common_safe_uint16(const char *numstr, uint16_t *converted) {
|
|
char *err = NULL;
|
|
unsigned long int uli;
|
|
|
|
- if (!numstr) {
|
|
+ if (numstr == NULL) {
|
|
return -EINVAL;
|
|
}
|
|
|
|
@@ -169,7 +169,7 @@ int common_safe_uint16(const char *numstr, uint16_t *converted) {
|
|
return -errno;
|
|
}
|
|
|
|
- if (!err || err == numstr || *err != '\0') {
|
|
+ if (err == NULL || err == numstr || *err != '\0') {
|
|
return -EINVAL;
|
|
}
|
|
|
|
@@ -185,7 +185,7 @@ int common_safe_uint32(const char *numstr, uint32_t *converted) {
|
|
char *err = NULL;
|
|
unsigned long long int ull;
|
|
|
|
- if (!numstr) {
|
|
+ if (numstr == NULL) {
|
|
return -EINVAL;
|
|
}
|
|
|
|
@@ -195,7 +195,7 @@ int common_safe_uint32(const char *numstr, uint32_t *converted) {
|
|
return -errno;
|
|
}
|
|
|
|
- if (!err || err == numstr || *err != '\0') {
|
|
+ if (err == NULL || err == numstr || *err != '\0') {
|
|
return -EINVAL;
|
|
}
|
|
|
|
@@ -211,7 +211,7 @@ int common_safe_uint64(const char *numstr, uint64_t *converted) {
|
|
char *err = NULL;
|
|
unsigned long long int ull;
|
|
|
|
- if (!numstr) {
|
|
+ if (numstr == NULL) {
|
|
return -EINVAL;
|
|
}
|
|
|
|
@@ -221,7 +221,7 @@ int common_safe_uint64(const char *numstr, uint64_t *converted) {
|
|
return -errno;
|
|
}
|
|
|
|
- if (!err || err == numstr || *err != '\0') {
|
|
+ if (err == NULL || err == numstr || *err != '\0') {
|
|
return -EINVAL;
|
|
}
|
|
|
|
@@ -233,7 +233,7 @@ int common_safe_uint(const char *numstr, unsigned int *converted) {
|
|
char *err = NULL;
|
|
unsigned long long int ull;
|
|
|
|
- if (!numstr) {
|
|
+ if (numstr == NULL) {
|
|
return -EINVAL;
|
|
}
|
|
|
|
@@ -243,7 +243,7 @@ int common_safe_uint(const char *numstr, unsigned int *converted) {
|
|
return -errno;
|
|
}
|
|
|
|
- if (!err || err == numstr || *err != '\0') {
|
|
+ if (err == NULL || err == numstr || *err != '\0') {
|
|
return -EINVAL;
|
|
}
|
|
|
|
@@ -259,7 +259,7 @@ int common_safe_int8(const char *numstr, int8_t *converted) {
|
|
char *err = NULL;
|
|
long int li;
|
|
|
|
- if (!numstr) {
|
|
+ if (numstr == NULL) {
|
|
return -EINVAL;
|
|
}
|
|
|
|
@@ -269,7 +269,7 @@ int common_safe_int8(const char *numstr, int8_t *converted) {
|
|
return -errno;
|
|
}
|
|
|
|
- if (!err || err == numstr || *err != '\0') {
|
|
+ if (err == NULL || err == numstr || *err != '\0') {
|
|
return -EINVAL;
|
|
}
|
|
|
|
@@ -285,7 +285,7 @@ int common_safe_int16(const char *numstr, int16_t *converted) {
|
|
char *err = NULL;
|
|
long int li;
|
|
|
|
- if (!numstr) {
|
|
+ if (numstr == NULL) {
|
|
return -EINVAL;
|
|
}
|
|
|
|
@@ -295,7 +295,7 @@ int common_safe_int16(const char *numstr, int16_t *converted) {
|
|
return -errno;
|
|
}
|
|
|
|
- if (!err || err == numstr || *err != '\0') {
|
|
+ if (err == NULL || err == numstr || *err != '\0') {
|
|
return -EINVAL;
|
|
}
|
|
|
|
@@ -311,7 +311,7 @@ int common_safe_int32(const char *numstr, int32_t *converted) {
|
|
char *err = NULL;
|
|
long long int lli;
|
|
|
|
- if (!numstr) {
|
|
+ if (numstr == NULL) {
|
|
return -EINVAL;
|
|
}
|
|
|
|
@@ -321,7 +321,7 @@ int common_safe_int32(const char *numstr, int32_t *converted) {
|
|
return -errno;
|
|
}
|
|
|
|
- if (!err || err == numstr || *err != '\0') {
|
|
+ if (err == NULL || err == numstr || *err != '\0') {
|
|
return -EINVAL;
|
|
}
|
|
|
|
@@ -337,7 +337,7 @@ int common_safe_int64(const char *numstr, int64_t *converted) {
|
|
char *err = NULL;
|
|
long long int lli;
|
|
|
|
- if (!numstr) {
|
|
+ if (numstr == NULL) {
|
|
return -EINVAL;
|
|
}
|
|
|
|
@@ -347,7 +347,7 @@ int common_safe_int64(const char *numstr, int64_t *converted) {
|
|
return -errno;
|
|
}
|
|
|
|
- if (!err || err == numstr || *err != '\0') {
|
|
+ if (err == NULL || err == numstr || *err != '\0') {
|
|
return -EINVAL;
|
|
}
|
|
|
|
@@ -359,7 +359,7 @@ int common_safe_int(const char *numstr, int *converted) {
|
|
char *err = NULL;
|
|
long long int lli;
|
|
|
|
- if (!numstr) {
|
|
+ if (numstr == NULL) {
|
|
return -EINVAL;
|
|
}
|
|
|
|
@@ -369,7 +369,7 @@ int common_safe_int(const char *numstr, int *converted) {
|
|
return -errno;
|
|
}
|
|
|
|
- if (!err || err == numstr || *err != '\0') {
|
|
+ if (err == NULL || err == numstr || *err != '\0') {
|
|
return -EINVAL;
|
|
}
|
|
|
|
@@ -385,12 +385,12 @@ char *safe_strdup(const char *src)
|
|
{
|
|
char *dst = NULL;
|
|
|
|
- if (!src) {
|
|
+ if (src == NULL) {
|
|
return NULL;
|
|
}
|
|
|
|
dst = strdup(src);
|
|
- if (!dst) {
|
|
+ if (dst == NULL) {
|
|
abort();
|
|
}
|
|
|
|
@@ -402,7 +402,7 @@ yajl_gen_status gen_json_map_int_int(void *ctx, json_map_int_int *map, struct pa
|
|
yajl_gen_status stat = yajl_gen_status_ok;
|
|
yajl_gen g = (yajl_gen) ctx;
|
|
size_t len = 0, i = 0;
|
|
- if (map) {
|
|
+ if (map != NULL) {
|
|
len = map->len;
|
|
}
|
|
if (!len && !(ptx->options & GEN_OPTIONS_SIMPLIFY)) {
|
|
@@ -444,7 +444,7 @@ yajl_gen_status gen_json_map_int_int(void *ctx, json_map_int_int *map, struct pa
|
|
}
|
|
|
|
void free_json_map_int_int(json_map_int_int *map) {
|
|
- if (map) {
|
|
+ if (map != NULL) {
|
|
size_t i;
|
|
for (i = 0; i < map->len; i++) {
|
|
// No need to free key for type int
|
|
@@ -459,7 +459,7 @@ void free_json_map_int_int(json_map_int_int *map) {
|
|
}
|
|
json_map_int_int *make_json_map_int_int(yajl_val src, struct parser_context *ctx, parser_error *err) {
|
|
json_map_int_int *ret = NULL;
|
|
- if (src && YAJL_GET_OBJECT(src)) {
|
|
+ if (src != NULL && YAJL_GET_OBJECT(src) != NULL) {
|
|
size_t i;
|
|
size_t len = YAJL_GET_OBJECT(src)->len;
|
|
ret = safe_malloc(sizeof(*ret));
|
|
@@ -470,11 +470,11 @@ json_map_int_int *make_json_map_int_int(yajl_val src, struct parser_context *ctx
|
|
const char *srckey = YAJL_GET_OBJECT(src)->keys[i];
|
|
yajl_val srcval = YAJL_GET_OBJECT(src)->values[i];
|
|
|
|
- if (srckey) {
|
|
+ if (srckey != NULL) {
|
|
int invalid;
|
|
invalid = common_safe_int(srckey, &(ret->keys[i]));
|
|
if (invalid) {
|
|
- if (!*err && asprintf(err, "Invalid key '%s' with type 'int': %s", srckey, strerror(-invalid)) < 0) {
|
|
+ if (*err == NULL && asprintf(err, "Invalid key '%s' with type 'int': %s", srckey, strerror(-invalid)) < 0) {
|
|
*(err) = safe_strdup("error allocating memory");
|
|
}
|
|
free_json_map_int_int(ret);
|
|
@@ -482,10 +482,10 @@ json_map_int_int *make_json_map_int_int(yajl_val src, struct parser_context *ctx
|
|
}
|
|
}
|
|
|
|
- if (srcval) {
|
|
+ if (srcval != NULL) {
|
|
int invalid;
|
|
if (!YAJL_IS_NUMBER(srcval)) {
|
|
- if (!*err && asprintf(err, "Invalid value with type 'int' for key '%s'", srckey) < 0) {
|
|
+ if (*err == NULL && asprintf(err, "Invalid value with type 'int' for key '%s'", srckey) < 0) {
|
|
*(err) = safe_strdup("error allocating memory");
|
|
}
|
|
free_json_map_int_int(ret);
|
|
@@ -493,7 +493,7 @@ json_map_int_int *make_json_map_int_int(yajl_val src, struct parser_context *ctx
|
|
}
|
|
invalid = common_safe_int(YAJL_GET_NUMBER(srcval), &(ret->values[i]));
|
|
if (invalid) {
|
|
- if (!*err && asprintf(err, "Invalid value with type 'int' for key '%s': %s", srckey, strerror(-invalid)) < 0) {
|
|
+ if (*err == NULL && asprintf(err, "Invalid value with type 'int' for key '%s': %s", srckey, strerror(-invalid)) < 0) {
|
|
*(err) = safe_strdup("error allocating memory");
|
|
}
|
|
free_json_map_int_int(ret);
|
|
@@ -506,10 +506,10 @@ json_map_int_int *make_json_map_int_int(yajl_val src, struct parser_context *ctx
|
|
}
|
|
int append_json_map_int_int(json_map_int_int *map, int key, int val) {
|
|
size_t len;
|
|
- int *keys;
|
|
- int *vals;
|
|
+ int *keys = NULL;
|
|
+ int *vals = NULL;
|
|
|
|
- if (!map) {
|
|
+ if (map == NULL) {
|
|
return -1;
|
|
}
|
|
|
|
@@ -548,7 +548,7 @@ yajl_gen_status gen_json_map_int_bool(void *ctx, json_map_int_bool *map, struct
|
|
yajl_gen_status stat = yajl_gen_status_ok;
|
|
yajl_gen g = (yajl_gen) ctx;
|
|
size_t len = 0, i = 0;
|
|
- if (map) {
|
|
+ if (map != NULL) {
|
|
len = map->len;
|
|
}
|
|
if (!len && !(ptx->options & GEN_OPTIONS_SIMPLIFY)) {
|
|
@@ -590,7 +590,7 @@ yajl_gen_status gen_json_map_int_bool(void *ctx, json_map_int_bool *map, struct
|
|
}
|
|
|
|
void free_json_map_int_bool(json_map_int_bool *map) {
|
|
- if (map) {
|
|
+ if (map != NULL) {
|
|
size_t i;
|
|
for (i = 0; i < map->len; i++) {
|
|
// No need to free key for type int
|
|
@@ -605,7 +605,7 @@ void free_json_map_int_bool(json_map_int_bool *map) {
|
|
}
|
|
json_map_int_bool *make_json_map_int_bool(yajl_val src, struct parser_context *ctx, parser_error *err) {
|
|
json_map_int_bool *ret = NULL;
|
|
- if (src && YAJL_GET_OBJECT(src)) {
|
|
+ if (src != NULL && YAJL_GET_OBJECT(src) != NULL) {
|
|
size_t i;
|
|
size_t len = YAJL_GET_OBJECT(src)->len;
|
|
ret = safe_malloc(sizeof(*ret));
|
|
@@ -616,11 +616,11 @@ json_map_int_bool *make_json_map_int_bool(yajl_val src, struct parser_context *c
|
|
const char *srckey = YAJL_GET_OBJECT(src)->keys[i];
|
|
yajl_val srcval = YAJL_GET_OBJECT(src)->values[i];
|
|
|
|
- if (srckey) {
|
|
+ if (srckey != NULL) {
|
|
int invalid;
|
|
invalid = common_safe_int(srckey, &(ret->keys[i]));
|
|
if (invalid) {
|
|
- if (!*err && asprintf(err, "Invalid key '%s' with type 'int': %s", srckey, strerror(-invalid)) < 0) {
|
|
+ if (*err == NULL && asprintf(err, "Invalid key '%s' with type 'int': %s", srckey, strerror(-invalid)) < 0) {
|
|
*(err) = safe_strdup("error allocating memory");
|
|
}
|
|
free_json_map_int_bool(ret);
|
|
@@ -628,13 +628,13 @@ json_map_int_bool *make_json_map_int_bool(yajl_val src, struct parser_context *c
|
|
}
|
|
}
|
|
|
|
- if (srcval) {
|
|
+ if (srcval != NULL) {
|
|
if (YAJL_IS_TRUE(srcval)) {
|
|
ret->values[i] = true;
|
|
} else if (YAJL_IS_FALSE(srcval)) {
|
|
ret->values[i] = false;
|
|
} else {
|
|
- if (!*err && asprintf(err, "Invalid value with type 'bool' for key '%s'", srckey) < 0) {
|
|
+ if (*err == NULL && asprintf(err, "Invalid value with type 'bool' for key '%s'", srckey) < 0) {
|
|
*(err) = safe_strdup("error allocating memory");
|
|
}
|
|
free_json_map_int_bool(ret);
|
|
@@ -647,10 +647,10 @@ json_map_int_bool *make_json_map_int_bool(yajl_val src, struct parser_context *c
|
|
}
|
|
int append_json_map_int_bool(json_map_int_bool *map, int key, bool val) {
|
|
size_t len;
|
|
- int *keys;
|
|
- bool *vals;
|
|
+ int *keys = NULL;
|
|
+ bool *vals = NULL;
|
|
|
|
- if (!map) {
|
|
+ if (map == NULL) {
|
|
return -1;
|
|
}
|
|
|
|
@@ -689,7 +689,7 @@ yajl_gen_status gen_json_map_int_string(void *ctx, json_map_int_string *map, str
|
|
yajl_gen_status stat = yajl_gen_status_ok;
|
|
yajl_gen g = (yajl_gen) ctx;
|
|
size_t len = 0, i = 0;
|
|
- if (map) {
|
|
+ if (map != NULL) {
|
|
len = map->len;
|
|
}
|
|
if (!len && !(ptx->options & GEN_OPTIONS_SIMPLIFY)) {
|
|
@@ -731,7 +731,7 @@ yajl_gen_status gen_json_map_int_string(void *ctx, json_map_int_string *map, str
|
|
}
|
|
|
|
void free_json_map_int_string(json_map_int_string *map) {
|
|
- if (map) {
|
|
+ if (map != NULL) {
|
|
size_t i;
|
|
for (i = 0; i < map->len; i++) {
|
|
// No need to free key for type int
|
|
@@ -747,7 +747,7 @@ void free_json_map_int_string(json_map_int_string *map) {
|
|
}
|
|
json_map_int_string *make_json_map_int_string(yajl_val src, struct parser_context *ctx, parser_error *err) {
|
|
json_map_int_string *ret = NULL;
|
|
- if (src && YAJL_GET_OBJECT(src)) {
|
|
+ if (src != NULL && YAJL_GET_OBJECT(src) != NULL) {
|
|
size_t i;
|
|
size_t len = YAJL_GET_OBJECT(src)->len;
|
|
ret = safe_malloc(sizeof(*ret));
|
|
@@ -758,11 +758,11 @@ json_map_int_string *make_json_map_int_string(yajl_val src, struct parser_contex
|
|
const char *srckey = YAJL_GET_OBJECT(src)->keys[i];
|
|
yajl_val srcval = YAJL_GET_OBJECT(src)->values[i];
|
|
|
|
- if (srckey) {
|
|
+ if (srckey != NULL) {
|
|
int invalid;
|
|
invalid = common_safe_int(srckey, &(ret->keys[i]));
|
|
if (invalid) {
|
|
- if (!*err && asprintf(err, "Invalid key '%s' with type 'int': %s", srckey, strerror(-invalid)) < 0) {
|
|
+ if (*err == NULL && asprintf(err, "Invalid key '%s' with type 'int': %s", srckey, strerror(-invalid)) < 0) {
|
|
*(err) = safe_strdup("error allocating memory");
|
|
}
|
|
free_json_map_int_string(ret);
|
|
@@ -770,9 +770,9 @@ json_map_int_string *make_json_map_int_string(yajl_val src, struct parser_contex
|
|
}
|
|
}
|
|
|
|
- if (srcval) {
|
|
+ if (srcval != NULL) {
|
|
if (!YAJL_IS_STRING(srcval)) {
|
|
- if (!*err && asprintf(err, "Invalid value with type 'string' for key '%s'", srckey) < 0) {
|
|
+ if (*err == NULL && asprintf(err, "Invalid value with type 'string' for key '%s'", srckey) < 0) {
|
|
*(err) = safe_strdup("error allocating memory");
|
|
}
|
|
free_json_map_int_string(ret);
|
|
@@ -787,10 +787,10 @@ json_map_int_string *make_json_map_int_string(yajl_val src, struct parser_contex
|
|
}
|
|
int append_json_map_int_string(json_map_int_string *map, int key, const char *val) {
|
|
size_t len;
|
|
- int *keys;
|
|
- char **vals;
|
|
+ int *keys = NULL;
|
|
+ char **vals = NULL;
|
|
|
|
- if (!map) {
|
|
+ if (map == NULL) {
|
|
return -1;
|
|
}
|
|
|
|
@@ -829,7 +829,7 @@ yajl_gen_status gen_json_map_string_int(void *ctx, json_map_string_int *map, str
|
|
yajl_gen_status stat = yajl_gen_status_ok;
|
|
yajl_gen g = (yajl_gen) ctx;
|
|
size_t len = 0, i = 0;
|
|
- if (map) {
|
|
+ if (map != NULL) {
|
|
len = map->len;
|
|
}
|
|
if (!len && !(ptx->options & GEN_OPTIONS_SIMPLIFY)) {
|
|
@@ -862,7 +862,7 @@ yajl_gen_status gen_json_map_string_int(void *ctx, json_map_string_int *map, str
|
|
}
|
|
|
|
void free_json_map_string_int(json_map_string_int *map) {
|
|
- if (map) {
|
|
+ if (map != NULL) {
|
|
size_t i;
|
|
for (i = 0; i < map->len; i++) {
|
|
free(map->keys[i]);
|
|
@@ -878,7 +878,7 @@ void free_json_map_string_int(json_map_string_int *map) {
|
|
}
|
|
json_map_string_int *make_json_map_string_int(yajl_val src, struct parser_context *ctx, parser_error *err) {
|
|
json_map_string_int *ret = NULL;
|
|
- if (src && YAJL_GET_OBJECT(src)) {
|
|
+ if (src != NULL && YAJL_GET_OBJECT(src) != NULL) {
|
|
size_t i;
|
|
size_t len = YAJL_GET_OBJECT(src)->len;
|
|
ret = safe_malloc(sizeof(*ret));
|
|
@@ -890,10 +890,10 @@ json_map_string_int *make_json_map_string_int(yajl_val src, struct parser_contex
|
|
yajl_val srcval = YAJL_GET_OBJECT(src)->values[i];
|
|
ret->keys[i] = safe_strdup(srckey ? srckey : "");
|
|
|
|
- if (srcval) {
|
|
+ if (srcval != NULL) {
|
|
int invalid;
|
|
if (!YAJL_IS_NUMBER(srcval)) {
|
|
- if (!*err && asprintf(err, "Invalid value with type 'int' for key '%s'", srckey) < 0) {
|
|
+ if (*err == NULL && asprintf(err, "Invalid value with type 'int' for key '%s'", srckey) < 0) {
|
|
*(err) = safe_strdup("error allocating memory");
|
|
}
|
|
free_json_map_string_int(ret);
|
|
@@ -901,7 +901,7 @@ json_map_string_int *make_json_map_string_int(yajl_val src, struct parser_contex
|
|
}
|
|
invalid = common_safe_int(YAJL_GET_NUMBER(srcval), &(ret->values[i]));
|
|
if (invalid) {
|
|
- if (!*err && asprintf(err, "Invalid value with type 'int' for key '%s': %s", srckey, strerror(-invalid)) < 0) {
|
|
+ if (*err == NULL && asprintf(err, "Invalid value with type 'int' for key '%s': %s", srckey, strerror(-invalid)) < 0) {
|
|
*(err) = safe_strdup("error allocating memory");
|
|
}
|
|
free_json_map_string_int(ret);
|
|
@@ -914,10 +914,10 @@ json_map_string_int *make_json_map_string_int(yajl_val src, struct parser_contex
|
|
}
|
|
int append_json_map_string_int(json_map_string_int *map, const char *key, int val) {
|
|
size_t len;
|
|
- char **keys;
|
|
- int *vals;
|
|
+ char **keys = NULL;
|
|
+ int *vals = NULL;
|
|
|
|
- if (!map) {
|
|
+ if (map == NULL) {
|
|
return -1;
|
|
}
|
|
|
|
@@ -956,7 +956,7 @@ yajl_gen_status gen_json_map_string_bool(void *ctx, json_map_string_bool *map, s
|
|
yajl_gen_status stat = yajl_gen_status_ok;
|
|
yajl_gen g = (yajl_gen) ctx;
|
|
size_t len = 0, i = 0;
|
|
- if (map) {
|
|
+ if (map != NULL) {
|
|
len = map->len;
|
|
}
|
|
if (!len && !(ptx->options & GEN_OPTIONS_SIMPLIFY)) {
|
|
@@ -989,7 +989,7 @@ yajl_gen_status gen_json_map_string_bool(void *ctx, json_map_string_bool *map, s
|
|
}
|
|
|
|
void free_json_map_string_bool(json_map_string_bool *map) {
|
|
- if (map) {
|
|
+ if (map != NULL) {
|
|
size_t i;
|
|
for (i = 0; i < map->len; i++) {
|
|
free(map->keys[i]);
|
|
@@ -1005,7 +1005,7 @@ void free_json_map_string_bool(json_map_string_bool *map) {
|
|
}
|
|
json_map_string_bool *make_json_map_string_bool(yajl_val src, struct parser_context *ctx, parser_error *err) {
|
|
json_map_string_bool *ret = NULL;
|
|
- if (src && YAJL_GET_OBJECT(src)) {
|
|
+ if (src != NULL && YAJL_GET_OBJECT(src) != NULL) {
|
|
size_t i;
|
|
size_t len = YAJL_GET_OBJECT(src)->len;
|
|
ret = safe_malloc(sizeof(*ret));
|
|
@@ -1017,13 +1017,13 @@ json_map_string_bool *make_json_map_string_bool(yajl_val src, struct parser_cont
|
|
yajl_val srcval = YAJL_GET_OBJECT(src)->values[i];
|
|
ret->keys[i] = safe_strdup(srckey ? srckey : "");
|
|
|
|
- if (srcval) {
|
|
+ if (srcval != NULL) {
|
|
if (YAJL_IS_TRUE(srcval)) {
|
|
ret->values[i] = true;
|
|
} else if (YAJL_IS_FALSE(srcval)) {
|
|
ret->values[i] = false;
|
|
} else {
|
|
- if (!*err && asprintf(err, "Invalid value with type 'bool' for key '%s'", srckey) < 0) {
|
|
+ if (*err == NULL && asprintf(err, "Invalid value with type 'bool' for key '%s'", srckey) < 0) {
|
|
*(err) = safe_strdup("error allocating memory");
|
|
}
|
|
free_json_map_string_bool(ret);
|
|
@@ -1036,10 +1036,10 @@ json_map_string_bool *make_json_map_string_bool(yajl_val src, struct parser_cont
|
|
}
|
|
int append_json_map_string_bool(json_map_string_bool *map, const char *key, bool val) {
|
|
size_t len;
|
|
- char **keys;
|
|
- bool *vals;
|
|
+ char **keys = NULL;
|
|
+ bool *vals = NULL;
|
|
|
|
- if (!map) {
|
|
+ if (map == NULL) {
|
|
return -1;
|
|
}
|
|
|
|
@@ -1078,7 +1078,7 @@ yajl_gen_status gen_json_map_string_string(void *ctx, json_map_string_string *ma
|
|
yajl_gen_status stat = yajl_gen_status_ok;
|
|
yajl_gen g = (yajl_gen) ctx;
|
|
size_t len = 0, i = 0;
|
|
- if (map) {
|
|
+ if (map != NULL) {
|
|
len = map->len;
|
|
}
|
|
if (!len && !(ptx->options & GEN_OPTIONS_SIMPLIFY)) {
|
|
@@ -1111,7 +1111,7 @@ yajl_gen_status gen_json_map_string_string(void *ctx, json_map_string_string *ma
|
|
}
|
|
|
|
void free_json_map_string_string(json_map_string_string *map) {
|
|
- if (map) {
|
|
+ if (map != NULL) {
|
|
size_t i;
|
|
for (i = 0; i < map->len; i++) {
|
|
free(map->keys[i]);
|
|
@@ -1128,7 +1128,7 @@ void free_json_map_string_string(json_map_string_string *map) {
|
|
}
|
|
json_map_string_string *make_json_map_string_string(yajl_val src, struct parser_context *ctx, parser_error *err) {
|
|
json_map_string_string *ret = NULL;
|
|
- if (src && YAJL_GET_OBJECT(src)) {
|
|
+ if (src != NULL && YAJL_GET_OBJECT(src) != NULL) {
|
|
size_t i;
|
|
size_t len = YAJL_GET_OBJECT(src)->len;
|
|
ret = safe_malloc(sizeof(*ret));
|
|
@@ -1140,9 +1140,9 @@ json_map_string_string *make_json_map_string_string(yajl_val src, struct parser_
|
|
yajl_val srcval = YAJL_GET_OBJECT(src)->values[i];
|
|
ret->keys[i] = safe_strdup(srckey ? srckey : "");
|
|
|
|
- if (srcval) {
|
|
+ if (srcval != NULL) {
|
|
if (!YAJL_IS_STRING(srcval)) {
|
|
- if (!*err && asprintf(err, "Invalid value with type 'string' for key '%s'", srckey) < 0) {
|
|
+ if (*err == NULL && asprintf(err, "Invalid value with type 'string' for key '%s'", srckey) < 0) {
|
|
*(err) = safe_strdup("error allocating memory");
|
|
}
|
|
free_json_map_string_string(ret);
|
|
@@ -1157,10 +1157,10 @@ json_map_string_string *make_json_map_string_string(yajl_val src, struct parser_
|
|
}
|
|
int append_json_map_string_string(json_map_string_string *map, const char *key, const char *val) {
|
|
size_t len, i;
|
|
- char **keys;
|
|
- char **vals;
|
|
+ char **keys = NULL;
|
|
+ char **vals = NULL;
|
|
|
|
- if (!map) {
|
|
+ if (map == NULL) {
|
|
return -1;
|
|
}
|
|
|
|
diff --git a/src/lxc/json/json_common.h b/src/lxc/json/json_common.h
|
|
index eb8281c..218a837 100755
|
|
--- a/src/lxc/json/json_common.h
|
|
+++ b/src/lxc/json/json_common.h
|
|
@@ -27,7 +27,7 @@ extern "C" {
|
|
# define GEN_OPTIONS_NOT_VALIDATE_UTF8 0x08
|
|
|
|
#define GEN_SET_ERROR_AND_RETURN(stat, err) { \
|
|
- if (!*(err)) {\
|
|
+ if (*(err) == NULL) {\
|
|
if (asprintf(err, "%s: %s: %d: error generating json, errcode: %d", __FILE__, __func__, __LINE__, stat) < 0) { \
|
|
*(err) = safe_strdup("error allocating memory"); \
|
|
} \
|
|
diff --git a/src/lxc/json/logger_json_file.c b/src/lxc/json/logger_json_file.c
|
|
index 4d78103..6433b04 100644
|
|
--- a/src/lxc/json/logger_json_file.c
|
|
+++ b/src/lxc/json/logger_json_file.c
|
|
@@ -15,32 +15,32 @@ logger_json_file *make_logger_json_file(yajl_val tree, struct parser_context *ct
|
|
ret = safe_malloc(sizeof(*ret));
|
|
{
|
|
yajl_val tmp = get_val(tree, "log", yajl_t_string);
|
|
- if (tmp) {
|
|
+ if (tmp != NULL) {
|
|
char *str = YAJL_GET_STRING(tmp);
|
|
ret->log = (uint8_t *)safe_strdup(str ? str : "");
|
|
- ret->log_len = str ? strlen(str) : 0;
|
|
+ ret->log_len = str != NULL ? strlen(str) : 0;
|
|
}
|
|
}
|
|
{
|
|
yajl_val val = get_val(tree, "stream", yajl_t_string);
|
|
- if (val) {
|
|
+ if (val != NULL) {
|
|
char *str = YAJL_GET_STRING(val);
|
|
ret->stream = safe_strdup(str ? str : "");
|
|
}
|
|
}
|
|
{
|
|
yajl_val val = get_val(tree, "time", yajl_t_string);
|
|
- if (val) {
|
|
+ if (val != NULL) {
|
|
char *str = YAJL_GET_STRING(val);
|
|
ret->time = safe_strdup(str ? str : "");
|
|
}
|
|
}
|
|
{
|
|
yajl_val tmp = get_val(tree, "attrs", yajl_t_string);
|
|
- if (tmp) {
|
|
+ if (tmp != NULL) {
|
|
char *str = YAJL_GET_STRING(tmp);
|
|
ret->attrs = (uint8_t *)safe_strdup(str ? str : "");
|
|
- ret->attrs_len = str ? strlen(str) : 0;
|
|
+ ret->attrs_len = str != NULL ? strlen(str) : 0;
|
|
}
|
|
}
|
|
|
|
@@ -59,7 +59,7 @@ logger_json_file *make_logger_json_file(yajl_val tree, struct parser_context *ct
|
|
}
|
|
|
|
void free_logger_json_file(logger_json_file *ptr) {
|
|
- if (!ptr)
|
|
+ if (ptr == NULL)
|
|
return;
|
|
free(ptr->log);
|
|
ptr->log = NULL;
|
|
@@ -78,13 +78,13 @@ yajl_gen_status gen_logger_json_file(yajl_gen g, logger_json_file *ptr, struct p
|
|
stat = reformat_start_map(g);
|
|
if (yajl_gen_status_ok != stat)
|
|
GEN_SET_ERROR_AND_RETURN(stat, err);
|
|
- if ((ctx->options & GEN_OPTIONS_ALLKEYVALUE) || (ptr && ptr->log && ptr->log_len)) {
|
|
+ if ((ctx->options & GEN_OPTIONS_ALLKEYVALUE) || (ptr != NULL && ptr->log != NULL && ptr->log_len)) {
|
|
const char *str = "";
|
|
size_t len = 0;
|
|
stat = reformat_map_key(g, "log", strlen("log"));
|
|
if (yajl_gen_status_ok != stat)
|
|
GEN_SET_ERROR_AND_RETURN(stat, err);
|
|
- if (ptr && ptr->log) {
|
|
+ if (ptr != NULL && ptr->log != NULL) {
|
|
str = (const char *)ptr->log;
|
|
len = ptr->log_len;
|
|
}
|
|
@@ -92,37 +92,37 @@ yajl_gen_status gen_logger_json_file(yajl_gen g, logger_json_file *ptr, struct p
|
|
if (yajl_gen_status_ok != stat)
|
|
GEN_SET_ERROR_AND_RETURN(stat, err);
|
|
}
|
|
- if ((ctx->options & GEN_OPTIONS_ALLKEYVALUE) ||(ptr && ptr->stream)) {
|
|
+ if ((ctx->options & GEN_OPTIONS_ALLKEYVALUE) ||(ptr != NULL && ptr->stream != NULL)) {
|
|
char *str = "";
|
|
stat = reformat_map_key(g, "stream", strlen("stream"));
|
|
if (yajl_gen_status_ok != stat)
|
|
GEN_SET_ERROR_AND_RETURN(stat, err);
|
|
- if (ptr && ptr->stream) {
|
|
+ if (ptr != NULL && ptr->stream != NULL) {
|
|
str = ptr->stream;
|
|
}
|
|
stat = reformat_string(g, str, strlen(str));
|
|
if (yajl_gen_status_ok != stat)
|
|
GEN_SET_ERROR_AND_RETURN(stat, err);
|
|
}
|
|
- if ((ctx->options & GEN_OPTIONS_ALLKEYVALUE) ||(ptr && ptr->time)) {
|
|
+ if ((ctx->options & GEN_OPTIONS_ALLKEYVALUE) ||(ptr != NULL && ptr->time != NULL)) {
|
|
char *str = "";
|
|
stat = reformat_map_key(g, "time", strlen("time"));
|
|
if (yajl_gen_status_ok != stat)
|
|
GEN_SET_ERROR_AND_RETURN(stat, err);
|
|
- if (ptr && ptr->time) {
|
|
+ if (ptr != NULL && ptr->time != NULL) {
|
|
str = ptr->time;
|
|
}
|
|
stat = reformat_string(g, str, strlen(str));
|
|
if (yajl_gen_status_ok != stat)
|
|
GEN_SET_ERROR_AND_RETURN(stat, err);
|
|
}
|
|
- if ((ctx->options & GEN_OPTIONS_ALLKEYVALUE) || (ptr && ptr->attrs && ptr->attrs_len)) {
|
|
+ if ((ctx->options & GEN_OPTIONS_ALLKEYVALUE) || (ptr != NULL && ptr->attrs != NULL && ptr->attrs_len)) {
|
|
const char *str = "";
|
|
size_t len = 0;
|
|
stat = reformat_map_key(g, "attrs", strlen("attrs"));
|
|
if (yajl_gen_status_ok != stat)
|
|
GEN_SET_ERROR_AND_RETURN(stat, err);
|
|
- if (ptr && ptr->attrs) {
|
|
+ if (ptr != NULL && ptr->attrs != NULL) {
|
|
str = (const char *)ptr->attrs;
|
|
len = ptr->attrs_len;
|
|
}
|
|
@@ -140,9 +140,9 @@ yajl_gen_status gen_logger_json_file(yajl_gen g, logger_json_file *ptr, struct p
|
|
logger_json_file *logger_json_file_parse_file(const char *filename, struct parser_context *ctx, parser_error *err) {
|
|
logger_json_file *ptr;
|
|
size_t filesize;
|
|
- char *content;
|
|
+ char *content = NULL;
|
|
|
|
- if (!filename || !err)
|
|
+ if (filename == NULL || err == NULL)
|
|
return NULL;
|
|
|
|
*err = NULL;
|
|
@@ -160,9 +160,9 @@ logger_json_file *logger_json_file_parse_file(const char *filename, struct parse
|
|
logger_json_file *logger_json_file_parse_file_stream(FILE *stream, struct parser_context *ctx, parser_error *err) {
|
|
logger_json_file *ptr;
|
|
size_t filesize;
|
|
- char *content ;
|
|
+ char *content = NULL ;
|
|
|
|
- if (!stream || !err)
|
|
+ if (stream == NULL || err == NULL)
|
|
return NULL;
|
|
|
|
*err = NULL;
|
|
@@ -182,11 +182,11 @@ logger_json_file *logger_json_file_parse_data(const char *jsondata, struct parse
|
|
char errbuf[1024];
|
|
struct parser_context tmp_ctx;
|
|
|
|
- if (!jsondata || !err)
|
|
+ if (jsondata == NULL || err == NULL)
|
|
return NULL;
|
|
|
|
*err = NULL;
|
|
- if (!ctx) {
|
|
+ if (ctx == NULL) {
|
|
ctx = &tmp_ctx;
|
|
memset(&tmp_ctx, 0, sizeof(tmp_ctx));
|
|
}
|
|
@@ -207,11 +207,11 @@ char *logger_json_file_generate_json(logger_json_file *ptr, struct parser_contex
|
|
char *json_buf = NULL;
|
|
size_t gen_len = 0;
|
|
|
|
- if (!ptr || !err)
|
|
+ if (ptr == NULL || err == NULL)
|
|
return NULL;
|
|
|
|
*err = NULL;
|
|
- if (!ctx) {
|
|
+ if (ctx == NULL) {
|
|
ctx = &tmp_ctx;
|
|
memset(&tmp_ctx, 0, sizeof(tmp_ctx));
|
|
}
|
|
@@ -221,12 +221,12 @@ char *logger_json_file_generate_json(logger_json_file *ptr, struct parser_contex
|
|
goto out;
|
|
}
|
|
if (yajl_gen_status_ok != gen_logger_json_file(g, ptr, ctx, err)) {
|
|
- if (!*err)
|
|
+ if (*err == NULL)
|
|
*err = safe_strdup("Failed to generate json");
|
|
goto free_out;
|
|
}
|
|
yajl_gen_get_buf(g, &gen_buf, &gen_len);
|
|
- if (!gen_buf) {
|
|
+ if (gen_buf == NULL) {
|
|
*err = safe_strdup("Error to get generated json");
|
|
goto free_out;
|
|
}
|
|
diff --git a/src/lxc/json/oci_runtime_hooks.c b/src/lxc/json/oci_runtime_hooks.c
|
|
index 3aa134e..43ff8d7 100644
|
|
--- a/src/lxc/json/oci_runtime_hooks.c
|
|
+++ b/src/lxc/json/oci_runtime_hooks.c
|
|
@@ -46,8 +46,7 @@ oci_runtime_spec_hooks *oci_runtime_spec_hooks_parse_file(const char *filename,
|
|
}
|
|
return NULL;
|
|
}
|
|
- oci_runtime_spec_hooks *ptr = make_oci_runtime_spec_hooks(tree, ctx,
|
|
- err);
|
|
+ oci_runtime_spec_hooks *ptr = make_oci_runtime_spec_hooks(tree, ctx, err);
|
|
yajl_tree_free(tree);
|
|
return ptr;
|
|
}
|
|
diff --git a/src/lxc/json/oci_runtime_spec.c b/src/lxc/json/oci_runtime_spec.c
|
|
index 1f6073c..4ccb635 100644
|
|
--- a/src/lxc/json/oci_runtime_spec.c
|
|
+++ b/src/lxc/json/oci_runtime_spec.c
|
|
@@ -15,7 +15,7 @@ oci_runtime_spec_hooks *make_oci_runtime_spec_hooks(yajl_val tree, struct parser
|
|
ret = safe_malloc(sizeof(*ret));
|
|
{
|
|
yajl_val tmp = get_val(tree, "prestart", yajl_t_array);
|
|
- if (tmp && YAJL_GET_ARRAY(tmp)) {
|
|
+ if (tmp != NULL && YAJL_GET_ARRAY(tmp) != NULL && YAJL_GET_ARRAY(tmp)->len > 0) {
|
|
size_t i;
|
|
ret->prestart_len = YAJL_GET_ARRAY(tmp)->len;
|
|
ret->prestart = safe_malloc((YAJL_GET_ARRAY(tmp)->len + 1) * sizeof(*ret->prestart));
|
|
@@ -31,7 +31,7 @@ oci_runtime_spec_hooks *make_oci_runtime_spec_hooks(yajl_val tree, struct parser
|
|
}
|
|
{
|
|
yajl_val tmp = get_val(tree, "poststart", yajl_t_array);
|
|
- if (tmp && YAJL_GET_ARRAY(tmp)) {
|
|
+ if (tmp != NULL && YAJL_GET_ARRAY(tmp) != NULL && YAJL_GET_ARRAY(tmp)->len > 0) {
|
|
size_t i;
|
|
ret->poststart_len = YAJL_GET_ARRAY(tmp)->len;
|
|
ret->poststart = safe_malloc((YAJL_GET_ARRAY(tmp)->len + 1) * sizeof(*ret->poststart));
|
|
@@ -47,7 +47,7 @@ oci_runtime_spec_hooks *make_oci_runtime_spec_hooks(yajl_val tree, struct parser
|
|
}
|
|
{
|
|
yajl_val tmp = get_val(tree, "poststop", yajl_t_array);
|
|
- if (tmp && YAJL_GET_ARRAY(tmp)) {
|
|
+ if (tmp != NULL && YAJL_GET_ARRAY(tmp) != NULL && YAJL_GET_ARRAY(tmp)->len > 0) {
|
|
size_t i;
|
|
ret->poststop_len = YAJL_GET_ARRAY(tmp)->len;
|
|
ret->poststop = safe_malloc((YAJL_GET_ARRAY(tmp)->len + 1) * sizeof(*ret->poststop));
|
|
@@ -76,32 +76,32 @@ oci_runtime_spec_hooks *make_oci_runtime_spec_hooks(yajl_val tree, struct parser
|
|
}
|
|
|
|
void free_oci_runtime_spec_hooks(oci_runtime_spec_hooks *ptr) {
|
|
- if (!ptr)
|
|
+ if (ptr == NULL)
|
|
return;
|
|
- if (ptr->prestart) {
|
|
+ if (ptr->prestart != NULL) {
|
|
size_t i;
|
|
for (i = 0; i < ptr->prestart_len; i++)
|
|
- if (ptr->prestart[i]) {
|
|
+ if (ptr->prestart[i] != NULL) {
|
|
free_defs_hook(ptr->prestart[i]);
|
|
ptr->prestart[i] = NULL;
|
|
}
|
|
free(ptr->prestart);
|
|
ptr->prestart = NULL;
|
|
}
|
|
- if (ptr->poststart) {
|
|
+ if (ptr->poststart != NULL) {
|
|
size_t i;
|
|
for (i = 0; i < ptr->poststart_len; i++)
|
|
- if (ptr->poststart[i]) {
|
|
+ if (ptr->poststart[i] != NULL) {
|
|
free_defs_hook(ptr->poststart[i]);
|
|
ptr->poststart[i] = NULL;
|
|
}
|
|
free(ptr->poststart);
|
|
ptr->poststart = NULL;
|
|
}
|
|
- if (ptr->poststop) {
|
|
+ if (ptr->poststop != NULL) {
|
|
size_t i;
|
|
for (i = 0; i < ptr->poststop_len; i++)
|
|
- if (ptr->poststop[i]) {
|
|
+ if (ptr->poststop[i] != NULL) {
|
|
free_defs_hook(ptr->poststop[i]);
|
|
ptr->poststop[i] = NULL;
|
|
}
|
|
@@ -117,12 +117,12 @@ yajl_gen_status gen_oci_runtime_spec_hooks(yajl_gen g, oci_runtime_spec_hooks *p
|
|
stat = reformat_start_map(g);
|
|
if (yajl_gen_status_ok != stat)
|
|
GEN_SET_ERROR_AND_RETURN(stat, err);
|
|
- if ((ctx->options & GEN_OPTIONS_ALLKEYVALUE) ||(ptr && ptr->prestart)) {
|
|
+ if ((ctx->options & GEN_OPTIONS_ALLKEYVALUE) ||(ptr != NULL && ptr->prestart != NULL)) {
|
|
size_t len = 0, i;
|
|
stat = reformat_map_key(g, "prestart", strlen("prestart"));
|
|
if (yajl_gen_status_ok != stat)
|
|
GEN_SET_ERROR_AND_RETURN(stat, err);
|
|
- if (ptr && ptr->prestart) {
|
|
+ if (ptr != NULL && ptr->prestart != NULL) {
|
|
len = ptr->prestart_len;
|
|
}
|
|
if (!len && !(ctx->options & GEN_OPTIONS_SIMPLIFY))
|
|
@@ -141,12 +141,12 @@ yajl_gen_status gen_oci_runtime_spec_hooks(yajl_gen g, oci_runtime_spec_hooks *p
|
|
if (yajl_gen_status_ok != stat)
|
|
GEN_SET_ERROR_AND_RETURN(stat, err);
|
|
}
|
|
- if ((ctx->options & GEN_OPTIONS_ALLKEYVALUE) ||(ptr && ptr->poststart)) {
|
|
+ if ((ctx->options & GEN_OPTIONS_ALLKEYVALUE) ||(ptr != NULL && ptr->poststart != NULL)) {
|
|
size_t len = 0, i;
|
|
stat = reformat_map_key(g, "poststart", strlen("poststart"));
|
|
if (yajl_gen_status_ok != stat)
|
|
GEN_SET_ERROR_AND_RETURN(stat, err);
|
|
- if (ptr && ptr->poststart) {
|
|
+ if (ptr != NULL && ptr->poststart != NULL) {
|
|
len = ptr->poststart_len;
|
|
}
|
|
if (!len && !(ctx->options & GEN_OPTIONS_SIMPLIFY))
|
|
@@ -165,12 +165,12 @@ yajl_gen_status gen_oci_runtime_spec_hooks(yajl_gen g, oci_runtime_spec_hooks *p
|
|
if (yajl_gen_status_ok != stat)
|
|
GEN_SET_ERROR_AND_RETURN(stat, err);
|
|
}
|
|
- if ((ctx->options & GEN_OPTIONS_ALLKEYVALUE) ||(ptr && ptr->poststop)) {
|
|
+ if ((ctx->options & GEN_OPTIONS_ALLKEYVALUE) ||(ptr != NULL && ptr->poststop != NULL)) {
|
|
size_t len = 0, i;
|
|
stat = reformat_map_key(g, "poststop", strlen("poststop"));
|
|
if (yajl_gen_status_ok != stat)
|
|
GEN_SET_ERROR_AND_RETURN(stat, err);
|
|
- if (ptr && ptr->poststop) {
|
|
+ if (ptr != NULL && ptr->poststop != NULL) {
|
|
len = ptr->poststop_len;
|
|
}
|
|
if (!len && !(ctx->options & GEN_OPTIONS_SIMPLIFY))
|
|
--
|
|
1.8.3.1
|
|
|