diff --git a/libr/anal/sign.c b/libr/anal/sign.c index 592ae285a9674e..d5549a02c003f4 100644 --- a/libr/anal/sign.c +++ b/libr/anal/sign.c @@ -227,8 +227,8 @@ R_API bool r_sign_deserialize(RAnal *a, RSignItem *it, const char *k, const char R_RETURN_VAL_IF_FAIL (a && it && k && v, false); bool success = true; - char *k2 = R_STR_DUP (k); - char *v2 = R_STR_DUP (v); + char *k2 = strdup (k); + char *v2 = strdup (v); if (!k2 || !v2) { success = false; goto out; diff --git a/libr/core/canal.c b/libr/core/canal.c index 3d08e18dea5ecf..30df9f40aa29d4 100644 --- a/libr/core/canal.c +++ b/libr/core/canal.c @@ -2442,7 +2442,7 @@ static void add_single_addr_xrefs(RCore *core, ut64 addr, RGraph *graph) { r_return_if_fail (graph); RFlagItem *f = r_flag_get_at (core->flags, addr, false); char *me = (f && f->offset == addr) - ? R_STR_DUP (f->name) + ? strdup (f->name) : r_str_newf ("0x%" PFMT64x, addr); RGraphNode *curr_node = r_graph_add_node_info (graph, me, NULL, addr); diff --git a/libr/core/cmd_cmp.inc.c b/libr/core/cmd_cmp.inc.c index 0ab1afe131d30f..8012f153819f73 100644 --- a/libr/core/cmd_cmp.inc.c +++ b/libr/core/cmd_cmp.inc.c @@ -112,7 +112,7 @@ R_API bool r_core_cmpwatch_add(RCore *core, ut64 addr, int size, const char *cmd found = true; } cmpw->size = size; - cmpw->cmd = R_STR_DUP (cmd); + cmpw->cmd = strdup (cmd); if (!cmpw->cmd) { free (cmpw); return false; diff --git a/libr/core/cmd_debug.inc.c b/libr/core/cmd_debug.inc.c index 9fb727559674b0..ff1e3ef43afe95 100644 --- a/libr/core/cmd_debug.inc.c +++ b/libr/core/cmd_debug.inc.c @@ -2163,7 +2163,7 @@ R_API void r_core_debug_rr(RCore *core, RReg *reg, int mode) { valuestr = r_str_newf ("%s0x%"PFMT64x"%s", color, value, colorend); r_cons_print (Color_RESET); } else { - namestr = R_STR_DUP (r->name); + namestr = strdup (r->name); valuestr = r_str_newf ("0x%"PFMT64x, value); } ut64 o_offset = core->offset; diff --git a/libr/core/cmd_zign.inc.c b/libr/core/cmd_zign.inc.c index 28c517c89fbaf0..40821bcbdfb2a1 100644 --- a/libr/core/cmd_zign.inc.c +++ b/libr/core/cmd_zign.inc.c @@ -1099,7 +1099,7 @@ static bool diff_zig(void *data, const char *input) { return false; } - char *argv = R_STR_DUP (input); + char *argv = strdup (input); if (!argv) { return false; } diff --git a/libr/core/core.c b/libr/core/core.c index bec97239b77588..7e69fdf4762522 100644 --- a/libr/core/core.c +++ b/libr/core/core.c @@ -1202,14 +1202,14 @@ static void autocomplete_ms_path(RLineCompletion *completion, RCore *core, const dirname = r_file_new (pwd, lpath, NULL); } } - basename = R_STR_DUP (p + 1); + basename = strdup (p + 1); } else { // xxx if (strlen (pwd) == 1) { dirname = r_str_newf ("%s", R_SYS_DIR); } else { dirname = r_str_newf ("%s%s", pwd, R_SYS_DIR); } - basename = R_STR_DUP (lpath); + basename = strdup (lpath); } R_FREE (pwd); @@ -1340,7 +1340,7 @@ static void autocomplete_process_path(RLineCompletion *completion, const char *s path++; } #endif - lpath = R_STR_DUP (path); + lpath = strdup (path); #if R2__WINDOWS__ r_str_replace_ch (lpath, '/', '\\', true); #endif @@ -1351,7 +1351,7 @@ static void autocomplete_process_path(RLineCompletion *completion, const char *s #if R2__WINDOWS__ dirname = strdup ("\\.\\"); #else - dirname = R_STR_DUP (R_SYS_DIR); + dirname = strdup (R_SYS_DIR); #endif } else if (lpath[0] == '~' && lpath[1]) { // ~/xxx/yyy dirname = r_file_home (lpath + 2); @@ -1419,7 +1419,7 @@ static void autocomplete_filename(RLineCompletion *completion, RLineBuffer *buf, char *pipe = strchr (buf->data, '>'); if (pipe) { - args = R_STR_DUP (pipe); + args = strdup (pipe); #if 0 if (pipe[1] == ' ') { // currently unreachable @@ -1608,7 +1608,7 @@ static void autocomplete_sdb(RCore *core, RLineCompletion *completion, const cha if (pipe) { str = r_str_trim_head_ro (pipe + 1); } - lpath = R_STR_DUP (str); + lpath = strdup (str); p1 = strchr (lpath, '/'); if (p1) { *p1 = 0; diff --git a/libr/core/disasm.c b/libr/core/disasm.c index 0e4c2bee4a1d37..6ba554f49392e8 100644 --- a/libr/core/disasm.c +++ b/libr/core/disasm.c @@ -4859,7 +4859,7 @@ static void ds_print_ptr(RDisasmState *ds, int len, int idx) { f = r_flag_get_i (core->flags, refaddr); if (f) { if (strlen (msg) != 1) { - char *msg2 = R_STR_DUP (msg); + char *msg2 = strdup (msg); if (msg2) { r_str_filter (msg2, 0); if (!strncmp (msg2, "UH..", 4)) { diff --git a/libr/core/fortune.c b/libr/core/fortune.c index 654a399d5bbc52..a4ee1673e4195e 100644 --- a/libr/core/fortune.c +++ b/libr/core/fortune.c @@ -28,7 +28,7 @@ static bool _push_types(RList *type_list, char *fortune_dir) { char *file; r_list_foreach (files, iter, file) { if (r_str_startswith (file, "fortunes.") && file[9]) { - r_list_push (type_list, R_STR_DUP (file + 9)); + r_list_push (type_list, strdup (file + 9)); } } r_list_free (files); diff --git a/libr/core/panels.c b/libr/core/panels.c index f70f79b705ad93..f11c2ef247d926 100644 --- a/libr/core/panels.c +++ b/libr/core/panels.c @@ -514,7 +514,7 @@ static bool __check_panel_type(RPanel *panel, const char *type) { if (!panel || !panel->model->cmd || !type) { return false; } - char *tmp = R_STR_DUP (panel->model->cmd); + char *tmp = strdup (panel->model->cmd); int n = r_str_split (tmp, ' '); if (!n) { free (tmp); @@ -623,14 +623,14 @@ static void __set_decompiler_cache(RCore *core, char *s) { RAnalFunction *func = r_anal_get_fcn_in (core->anal, core->offset, R_ANAL_FCN_TYPE_NULL); if (func) { if (core->panels_root->cur_pdc_cache) { - sdb_ptr_set (core->panels_root->cur_pdc_cache, r_num_as_string (NULL, func->addr, false), R_STR_DUP (s), 0); + sdb_ptr_set (core->panels_root->cur_pdc_cache, r_num_as_string (NULL, func->addr, false), strdup (s), 0); } else { Sdb *sdb = sdb_new0 (); const char *pdc_now = r_config_get (core->config, "cmd.pdc"); sdb_ptr_set (sdb, r_num_as_string (NULL, func->addr, false), R_STR_DUP (s), 0); core->panels_root->cur_pdc_cache = sdb; if (!sdb_exists (core->panels_root->pdc_caches, pdc_now)) { - sdb_ptr_set (core->panels_root->pdc_caches, R_STR_DUP (pdc_now), sdb, 0); + sdb_ptr_set (core->panels_root->pdc_caches, strdup (pdc_now), sdb, 0); } } } @@ -639,7 +639,7 @@ static void __set_decompiler_cache(RCore *core, char *s) { static void __set_read_only(RCore *core, RPanel *p, char *s) { free (p->model->readOnly); - p->model->readOnly = R_STR_DUP (s); + p->model->readOnly = strdup (s); __set_dcb (core, p); __set_pcb (p); } @@ -2294,7 +2294,7 @@ static int __show_all_decompiler_cb(void *user) { r_config_set (core->config, "cmd.pdc", opt); RPanel *panel = __get_panel (panels, i++); panels->n_panels = i; - panel->model->title = R_STR_DUP (opt); + panel->model->title = strdup (opt); __set_read_only (core, panel, r_core_cmd_str (core, opt)); } __layout_equal_hor (panels); @@ -2317,7 +2317,7 @@ static void __init_modal_db(RCore *core) { SdbList *sdb_list = sdb_foreach_list (core->panels->db, true); ls_foreach (sdb_list, sdb_iter, kv) { const char *key = sdbkv_key (kv); - sdb_ptr_set (db, R_STR_DUP (key), &__create_panel_db, 0); + sdb_ptr_set (db, strdup (key), &__create_panel_db, 0); } sdb_ptr_set (db, "Search strings in data sections", &__search_strings_data_create, 0); sdb_ptr_set (db, "Search strings in the whole bin", &__search_strings_bin_create, 0); @@ -2597,7 +2597,7 @@ static void __handle_tab_new_with_cur_panel(RCore *core) { RPanel *new_panel = __get_panel (new_panels, 0); __init_panel_param (core, new_panel, cur->model->title, cur->model->cmd); new_panel->model->cache = cur->model->cache; - new_panel->model->funcName = R_STR_DUP (cur->model->funcName); + new_panel->model->funcName = strdup (cur->model->funcName); __set_cmd_str_cache (core, new_panel, cur->model->cmdStrCache); __maximize_panel_size (new_panels); diff --git a/libr/main/ravc2.c b/libr/main/ravc2.c index 49fb4405c47d42..c63e502cd73308 100644 --- a/libr/main/ravc2.c +++ b/libr/main/ravc2.c @@ -145,7 +145,7 @@ R_API int r_main_ravc2(int argc, const char **argv) { if (files) { size_t i; for (i = 2; i < argc - 1; i++) { - char *file = R_STR_DUP (argv[opt.ind + i]); + char *file = strdup (argv[opt.ind + i]); if (!file || !r_list_append (files, file)) { free (message); r_list_free (files); diff --git a/libr/util/rvc_git.c b/libr/util/rvc_git.c index 7e69bfcbd22a4b..dd4866375a0664 100644 --- a/libr/util/rvc_git.c +++ b/libr/util/rvc_git.c @@ -23,7 +23,7 @@ static Rvc *open_git(const char *path) { if (!vc) { return NULL; } - vc->path = R_STR_DUP (path); + vc->path = strdup (path); if (!vc->path) { free (vc); return NULL; diff --git a/libr/util/rvc_rvc.c b/libr/util/rvc_rvc.c index f080ae433c0104..3929081fcba220 100644 --- a/libr/util/rvc_rvc.c +++ b/libr/util/rvc_rvc.c @@ -66,7 +66,7 @@ static Rvc *rvc_rvc_new(const char *path) { R_LOG_ERROR ("Failed to create repo"); return NULL; } - rvc->path = R_STR_DUP (path); + rvc->path = strdup (path); if (!rvc->path) { free (rvc); return NULL; @@ -325,7 +325,7 @@ static char *absp2rp(Rvc *rvc, const char *absp) { free (arp); return NULL; } - char *p = R_STR_DUP (absp + r_str_len_utf8 (arp)); + char *p = strdup (absp + r_str_len_utf8 (arp)); free (arp); if (!p) { return NULL; @@ -716,7 +716,7 @@ R_API RList *branches_rvc(Rvc *rvc) { if (!r_str_startswith ((char *)kv->base.key, BPREFIX)) { continue; } - if (!r_list_append (ret, R_STR_DUP ((char *)kv->base.key + bplen)) + if (!r_list_append (ret, strdup ((char *)kv->base.key + bplen)) && !ret->head->data) { r_list_free (ret); ret = NULL; diff --git a/libr/util/str.c b/libr/util/str.c index 0443c88d0efdf2..ea6aa7773ce9c9 100644 --- a/libr/util/str.c +++ b/libr/util/str.c @@ -673,7 +673,7 @@ R_API char *r_str_trunc_ellipsis(const char *str, int len) { return strdup (str); } char *buf = NULL; - if (len) { + if (len > 0) { buf = r_str_ndup (str, len); } if (buf && len > 4) { diff --git a/libr/util/strbuf.c b/libr/util/strbuf.c index b37f40cc872838..a681b7883ca2c2 100644 --- a/libr/util/strbuf.c +++ b/libr/util/strbuf.c @@ -131,7 +131,7 @@ R_API bool r_strbuf_slice(RStrBuf *sb, int from, int len) { const char *fr = r_str_ansi_chrn (s, from + 1); const char *to = r_str_ansi_chrn (s, from + len + 1); char *r = NULL; - if (to - fr) { + if (to > fr) { r = r_str_ndup (fr, to - fr); } r_strbuf_fini (sb); diff --git a/libr/util/syscmd.c b/libr/util/syscmd.c index f5105653f4e00d..238f1862fa20b0 100644 --- a/libr/util/syscmd.c +++ b/libr/util/syscmd.c @@ -483,7 +483,7 @@ R_API char *r_syscmd_join(const char *file1, const char *file2) { } r_list_foreach (list2, iter2, str2) { if (r_str_startswith (str2, field)) { - char *out = R_STR_DUP (field); + char *out = strdup (field); char *first = strchr (str1, ' '); char *second = strchr (str2, ' '); out = r_str_append (out, r_str_get_fail (first, " ")); diff --git a/shlr/ar/ar.c b/shlr/ar/ar.c index 423677b65979f8..1b30afae197ec3 100644 --- a/shlr/ar/ar.c +++ b/shlr/ar/ar.c @@ -65,7 +65,7 @@ static char *name_from_table(ut64 off, filetable *tbl) { return NULL; } char *res = NULL; - if (i - off - 1) { + if (i - off - 1 > 0) { res = r_str_ndup (buf + off, i - off - 1); } return res;