Minor cleanups/fixes (#12467)

This commit is contained in:
dav1901 2018-12-12 23:02:32 +02:00 committed by radare
parent 78ee6c0896
commit 3a24f6d8a1
3 changed files with 16 additions and 16 deletions

View file

@ -691,7 +691,10 @@ R_API char *r_str_newlen(const char *str, int len) {
R_API char *r_str_trunc_ellipsis(const char *str, int len) {
char *buf;
if (str && strlen (str) < len) {
if (!str) {
return NULL;
}
if (strlen (str) < len) {
buf = strdup (str);
} else {
buf = r_str_newlen (str, len);

View file

@ -772,6 +772,8 @@ R_API int r_num_between(RNum *num, const char *input_value) {
RList *nums = r_num_str_split_list (str);
int len = r_list_length (nums);
if (len < 3) {
free (str);
r_list_free (nums);
return -1;
}
if (len > 3) {

View file

@ -27,11 +27,6 @@ static DsoJsonInfo DSO_JSON_INFOS []= {
{DSO_JSON_END},//, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL},
};
// TODO: remove useless calloc wrapper
static void * json_new0 (unsigned int sz) {
return calloc (sz, 1);
}
static RList * build_str_list_from_iterable (RList *the_list) {
RList * res = r_list_newf (free);
DsoJsonObj *json_obj;
@ -57,7 +52,7 @@ static char * build_str_from_str_list_for_iterable (RList *the_list, int is_arra
len += strlen (str) + 1;
}
res = json_new0 (len);
res = calloc (len, 1);
// TODO: use [ if needed
if (res) {
strcpy (res, is_array? "[": "{");
@ -151,8 +146,8 @@ static int cmpDsoStr_to_str (DsoJsonStr *dsoStr1, char *dsoStr2) {
static void allocDsoStr (DsoJsonStr *dsoStr, unsigned int sz) {
free (dsoStr->data);
if (sz > 0) dsoStr->data = json_new0 (sz);
else dsoStr->data = json_new0 (10);
if (sz > 0) dsoStr->data = calloc (sz, 1);
else dsoStr->data = calloc (10, 1);
dsoStr->len = sz;
}
@ -187,7 +182,7 @@ static DsoJsonStr * dso_json_get_str (DsoJsonObj *dso_obj) {
}
DsoJsonObj * dso_json_null_new () {
DsoJsonObj *x = json_new0 (sizeof (DsoJsonObj));
DsoJsonObj *x = calloc (sizeof (DsoJsonObj), 1);
if (!x) return NULL;
x->info = get_type_info (DSO_JSON_NULL);
return x;
@ -201,7 +196,7 @@ DsoJsonObj * dso_json_str_new () {
DsoJsonObj *x = dso_json_null_new ();
if (!x) return NULL;
x->info = get_type_info (DSO_JSON_STR);
x->val._str = json_new0 (sizeof (DsoJsonStr));
x->val._str = calloc (sizeof (DsoJsonStr), 1);
return x;
}
@ -217,7 +212,7 @@ DsoJsonObj * dso_json_dict_entry_new () {
DsoJsonObj *x = dso_json_null_new ();
if (!x) return NULL;
x->info = get_type_info (DSO_JSON_DICT_ENTRY);
x->val._dict_entry = json_new0 (sizeof (DsoJsonDictEntry));
x->val._dict_entry = calloc (sizeof (DsoJsonDictEntry), 1);
if (!x->val._dict_entry) {
dso_json_null_free (x);
return NULL;
@ -256,7 +251,7 @@ char * dso_json_dict_entry_to_str (DsoJsonDictEntry * entry) {
if (key) {
int len = 2 + 3 + strlen (key);
if (value) len += strlen (value);
res = json_new0 (len);
res = calloc (len, 1);
if (res) {
if (value) {
snprintf (res, len, "%s:%s", key, value);
@ -425,7 +420,7 @@ DsoJsonObj * dso_json_list_new () {
DsoJsonObj *x = dso_json_null_new ();
if (x) {
x->info = get_type_info (DSO_JSON_LIST);
x->val._list = json_new0 (sizeof (DsoJsonList));
x->val._list = calloc (sizeof (DsoJsonList), 1);
if (x->val._list) {
x->val._list->json_list = r_list_newf ((RListFree)dso_json_obj_del);
} else {
@ -483,7 +478,7 @@ DsoJsonObj * dso_json_dict_new () {
DsoJsonObj *x = dso_json_null_new ();
if (x) {
x->info = get_type_info (DSO_JSON_DICT);
x->val._dict = json_new0 (sizeof (DsoJsonObj));
x->val._dict = calloc (sizeof (DsoJsonObj), 1);
if (!x->val._dict) {
dso_json_null_free (x);
return NULL;
@ -643,7 +638,7 @@ DsoJsonObj * dso_json_num_new () {
DsoJsonObj *x = dso_json_null_new ();
if (!x) return NULL;
x->info = get_type_info (DSO_JSON_NUM);
x->val._num = json_new0 (sizeof (DsoJsonNum));
x->val._num = calloc (sizeof (DsoJsonNum), 1);
return x;
}