From 892aafd74269d387b30fe24b43a5a05a3beef231 Mon Sep 17 00:00:00 2001 From: satk0 Date: Mon, 22 Jul 2024 14:43:02 +0200 Subject: [PATCH 01/31] Depreciate r_str_new --- libr/anal/sign.c | 8 ++++---- libr/anal/value.c | 2 +- libr/arch/arch_value.c | 2 +- libr/arch/p/8051/8051_disas.c | 2 +- libr/arch/p/dalvik/plugin.c | 6 +++--- libr/arch/p/pyc/opcode_arg_fmt.c | 8 ++++---- libr/arch/p/pyc/pyc_dis.c | 8 ++++---- libr/bin/format/mach0/mach0.c | 4 ++-- libr/bin/format/xnu/r_cf_dict.c | 4 ++-- libr/core/anal_tp.c | 2 +- libr/core/canal.c | 4 ++-- libr/core/cbin.c | 2 +- libr/core/cmd.c | 2 +- libr/core/cmd_anal.inc.c | 2 +- libr/core/cmd_cmp.inc.c | 2 +- libr/core/cmd_debug.inc.c | 2 +- libr/core/cmd_zign.inc.c | 4 ++-- libr/core/core.c | 24 ++++++++++++------------ libr/core/disasm.c | 2 +- libr/core/fortune.c | 4 ++-- libr/core/panels.c | 24 ++++++++++++------------ libr/core/visual.c | 2 +- libr/lang/p/lib.c | 2 +- libr/main/ravc2.c | 4 ++-- libr/main/rax2.c | 2 +- libr/util/axml.c | 4 ++-- libr/util/rvc_git.c | 4 ++-- libr/util/rvc_rvc.c | 20 ++++++++++---------- libr/util/syscmd.c | 2 +- libr/util/table.c | 2 +- 30 files changed, 80 insertions(+), 80 deletions(-) diff --git a/libr/anal/sign.c b/libr/anal/sign.c index 567c0fd1b9dd8..b1b9c0b831a11 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_new (k); - char *v2 = r_str_new (v); + char *k2 = R_STR_DUP (k); + char *v2 = R_STR_DUP (v); if (!k2 || !v2) { success = false; goto out; @@ -248,7 +248,7 @@ R_API bool r_sign_deserialize(RAnal *a, RSignItem *it, const char *k, const char } it->space = r_spaces_add (&a->zign_spaces, r_str_word_get0 (k2, 1)); - it->name = r_str_new (r_str_word_get0 (k2, 2)); + it->name = R_STR_DUP (r_str_word_get0 (k2, 2)); // remove newline at end char *save_ptr = NULL; @@ -343,7 +343,7 @@ R_API bool r_sign_deserialize(RAnal *a, RSignItem *it, const char *k, const char if (token[0] != 0) { it->hash = R_NEW0 (RSignHash); if (it->hash) { - it->hash->bbhash = r_str_new (token); + it->hash->bbhash = R_STR_DUP (token); } } break; diff --git a/libr/anal/value.c b/libr/anal/value.c index 3aa19664a4eb6..53adf2d969355 100644 --- a/libr/anal/value.c +++ b/libr/anal/value.c @@ -66,7 +66,7 @@ R_API const char *r_anal_value_type_tostring(RAnalValue *value) { R_API char *r_anal_value_tostring(RAnalValue *value) { char *out = NULL; if (value) { - out = r_str_new (""); + out = R_STR_DUP (""); if (!value->base && !value->reg) { if (value->imm != -1LL) { out = r_str_appendf (out, "0x%"PFMT64x, value->imm); diff --git a/libr/arch/arch_value.c b/libr/arch/arch_value.c index f24a08513ae05..6ecf88b534623 100644 --- a/libr/arch/arch_value.c +++ b/libr/arch/arch_value.c @@ -100,7 +100,7 @@ R_API bool r_arch_value_set_ut64(RArchValue *val, RReg *reg, RIOBind *iob, ut64 R_API char *r_arch_value_tostring(RArchValue *value) { char *out = NULL; if (value) { - out = r_str_new (""); + out = R_STR_DUP (""); if (!value->base && !value->reg) { if (value->imm != -1LL) { out = r_str_appendf (out, "0x%"PFMT64x, value->imm); diff --git a/libr/arch/p/8051/8051_disas.c b/libr/arch/p/8051/8051_disas.c index 83a4bd1115fcf..ee06ad47ea76d 100644 --- a/libr/arch/p/8051/8051_disas.c +++ b/libr/arch/p/8051/8051_disas.c @@ -31,7 +31,7 @@ static char *r_8051_disas(ut64 pc, const ut8 *buf, int len, int *olen) { // op @Ri; op Rn disasm = r_str_newf (name, buf[0] & mask); } else { - disasm = r_str_new (name); + disasm = R_STR_DUP (name); } break; case 2: diff --git a/libr/arch/p/dalvik/plugin.c b/libr/arch/p/dalvik/plugin.c index be29eaab0a523..a2caab7a767c6 100644 --- a/libr/arch/p/dalvik/plugin.c +++ b/libr/arch/p/dalvik/plugin.c @@ -761,9 +761,9 @@ static int dalvik_disassemble(RArchSession *as, RAnalOp *op, ut64 addr, const ut R_FREE (strasm); size = 2; } - op->mnemonic = r_str_new (r_str_get_fail (strasm, "invalid")); + op->mnemonic = R_STR_DUP (r_str_get_fail (strasm, "invalid")); } else if (len > 0) { - op->mnemonic = r_str_new ("invalid"); + op->mnemonic = R_STR_DUP ("invalid"); size = len; } @@ -794,7 +794,7 @@ static bool decode(RArchSession *as, RAnalOp *op, RAnalOpMask mask) { int sz = dalvik_opcodes[data[0]].len; if (!op || sz > len) { if (mask & R_ARCH_OP_MASK_DISASM) { - op->mnemonic = r_str_new ("invalid"); + op->mnemonic = R_STR_DUP ("invalid"); } return false; } diff --git a/libr/arch/p/pyc/opcode_arg_fmt.c b/libr/arch/p/pyc/opcode_arg_fmt.c index 9974e5a0ca4cc..1b6064a15b975 100644 --- a/libr/arch/p/pyc/opcode_arg_fmt.c +++ b/libr/arch/p/pyc/opcode_arg_fmt.c @@ -22,20 +22,20 @@ char *format_CALL_FUNCTION_KW_36(ut32 oparg) { } char *format_CALL_FUNCTION_EX_36(ut32 oparg) { - return r_str_new ((oparg & 0x01)? "keyword args": ""); + return R_STR_DUP ((oparg & 0x01)? "keyword args": ""); } static const char *MAKE_FUNCTION_FLAGS[] = { "default", "keyword-only", "annotation", "closure" }; char *format_MAKE_FUNCTION_arg_36(ut32 oparg) { size_t i; - char *ret = r_str_new (" "); + char *ret = R_STR_DUP (" "); for (i = 0; i < sizeof (MAKE_FUNCTION_FLAGS) / sizeof (char *); ++i) { if (oparg & 0x1) { ret = r_str_appendf (ret, ", %s", MAKE_FUNCTION_FLAGS[i]); } else { free (ret); - ret = r_str_new (MAKE_FUNCTION_FLAGS[i]); + ret = R_STR_DUP (MAKE_FUNCTION_FLAGS[i]); } oparg >>= 1; } @@ -60,7 +60,7 @@ char *format_value_flags_36(ut32 oparg) { // empty fmt_spec. ret = ""; } - return r_str_new (ret); + return R_STR_DUP (ret); } char *format_extended_arg_36(ut32 oparg) { diff --git a/libr/arch/p/pyc/pyc_dis.c b/libr/arch/p/pyc/pyc_dis.c index 43bbecb843eec..6e20259e0e8c3 100644 --- a/libr/arch/p/pyc/pyc_dis.c +++ b/libr/arch/p/pyc/pyc_dis.c @@ -139,14 +139,14 @@ static char *parse_arg(pyc_opcode_object *op, ut32 oparg, pyc_code_object *cobj, arg = r_str_newf ("'%s'", (char *)t->data); break; default: - arg = r_str_new (t->data); + arg = R_STR_DUP (t->data); } } if (op->type & HASNAME) { if (names) { t = (pyc_object *)r_list_get_n (names, oparg); if (t) { - return r_str_new (t->data); + return R_STR_DUP (t->data); } } return NULL; @@ -167,7 +167,7 @@ static char *parse_arg(pyc_opcode_object *op, ut32 oparg, pyc_code_object *cobj, if (oparg < 0 || oparg >= CMP_OP_SIZE) { return NULL; } - arg = r_str_new (cmp_op[oparg]); + arg = R_STR_DUP (cmp_op[oparg]); } if (op->type & HASFREE) { if (!cellvars || !freevars) { @@ -184,7 +184,7 @@ static char *parse_arg(pyc_opcode_object *op, ut32 oparg, pyc_code_object *cobj, if (!t) { return NULL; } - arg = r_str_new (t->data); + arg = R_STR_DUP (t->data); } if (op->type & (HASVARGS | HASNARGS)) { arg = r_str_newf ("%u", oparg); diff --git a/libr/bin/format/mach0/mach0.c b/libr/bin/format/mach0/mach0.c index 46127f363289e..b8eb5c4e157d8 100644 --- a/libr/bin/format/mach0/mach0.c +++ b/libr/bin/format/mach0/mach0.c @@ -4184,9 +4184,9 @@ ut64 MACH0_(get_baddr)(struct MACH0_(obj_t) *mo) { char *MACH0_(get_class)(struct MACH0_(obj_t) *mo) { #if R_BIN_MACH064 - return r_str_new ("MACH064"); + return R_STR_DUP ("MACH064"); #else - return r_str_new ("MACH0"); + return R_STR_DUP ("MACH0"); #endif } diff --git a/libr/bin/format/xnu/r_cf_dict.c b/libr/bin/format/xnu/r_cf_dict.c index 6952982125735..039fa5df37b4c 100644 --- a/libr/bin/format/xnu/r_cf_dict.c +++ b/libr/bin/format/xnu/r_cf_dict.c @@ -673,7 +673,7 @@ static RCFValue *r_cf_value_clone(RCFValue *value) { RListIter *iter; RCFKeyValue *item; r_list_foreach (((RCFValueDict *)value)->pairs, iter, item) { - char *key = r_str_new (item->key); + char *key = R_STR_DUP (item->key); if (key) { RCFValue *clone = r_cf_value_clone (item->value); if (clone) { @@ -714,7 +714,7 @@ static RCFValue *r_cf_value_clone(RCFValue *value) { case R_CF_STRING: { RCFValueString *string = R_NEW0 (RCFValueString); if (string) { - string->value = r_str_new (((RCFValueString *)value)->value); + string->value = R_STR_DUP (((RCFValueString *)value)->value); if (string->value) { copy = (RCFValue *)string; } else { diff --git a/libr/core/anal_tp.c b/libr/core/anal_tp.c index ef42754374571..3be06b244347e 100644 --- a/libr/core/anal_tp.c +++ b/libr/core/anal_tp.c @@ -455,7 +455,7 @@ static void type_match(RCore *core, char *fcn_name, ut64 addr, ut64 baddr, const break; } const String *type_ = RVecString_at (&types, pos++); - type = type_ ? r_str_new (*type_) : NULL; + type = type_ ? R_STR_DUP (*type_) : NULL; DD R_LOG_INFO ("TYPE (%s)", type); } else { type = r_type_func_args_type (TDB, fcn_name, arg_num); diff --git a/libr/core/canal.c b/libr/core/canal.c index 60e3f77b3689d..0138bc2ee9426 100644 --- a/libr/core/canal.c +++ b/libr/core/canal.c @@ -2452,7 +2452,7 @@ static void add_single_addr_xrefs(RCore *core, ut64 addr, RGraph *graph) { } RFlagItem *f = r_flag_get_at (core->flags, addr, false); char *me = (f && f->offset == addr) - ? r_str_new (f->name) + ? R_STR_DUP (f->name) : r_str_newf ("0x%" PFMT64x, addr); RGraphNode *curr_node = r_graph_add_node_info (graph, me, NULL, addr); @@ -2472,7 +2472,7 @@ static void add_single_addr_xrefs(RCore *core, ut64 addr, RGraph *graph) { continue; } RFlagItem *item = r_flag_get_i (core->flags, ref->addr); - char *src = item? r_str_new (item->name): r_str_newf ("0x%08" PFMT64x, ref->addr); + char *src = item? R_STR_DUP (item->name): r_str_newf ("0x%08" PFMT64x, ref->addr); RGraphNode *reference_from = r_graph_add_node_info (graph, src, NULL, ref->addr); free (src); r_graph_add_edge (graph, reference_from, curr_node); diff --git a/libr/core/cbin.c b/libr/core/cbin.c index d698c23575314..9617474961eac 100644 --- a/libr/core/cbin.c +++ b/libr/core/cbin.c @@ -2969,7 +2969,7 @@ static bool bin_map_sections_to_segments(RBin *bin, PJ *pj, int mode) { r_list_foreach (segments, iter, segment) { RInterval segment_itv = (RInterval){segment->vaddr, segment->size}; - char *tmp2 = r_str_new (""); + char *tmp2 = R_STR_DUP (""); r_list_foreach (sections, iter2, section) { RInterval section_itv = (RInterval){section->vaddr, section->size}; if (r_itv_begin (section_itv) >= r_itv_begin (segment_itv) && r_itv_end (section_itv) <= r_itv_end (segment_itv) && section->name[0]) { diff --git a/libr/core/cmd.c b/libr/core/cmd.c index d6d299e8518a3..98ca437ba9a51 100644 --- a/libr/core/cmd.c +++ b/libr/core/cmd.c @@ -2522,7 +2522,7 @@ static int cmd_kuery(void *data, const char *input) { RLine *line = core->cons->line; if (!line->sdbshell_hist) { line->sdbshell_hist = r_list_newf (free); - r_list_append (line->sdbshell_hist, r_str_new ("\0")); + r_list_append (line->sdbshell_hist, R_STR_DUP ("\0")); } RList *sdb_hist = line->sdbshell_hist; r_line_set_hist_callback (line, &r_line_hist_sdb_up, &r_line_hist_sdb_down); diff --git a/libr/core/cmd_anal.inc.c b/libr/core/cmd_anal.inc.c index 98f691e6210fb..d2130bd094768 100644 --- a/libr/core/cmd_anal.inc.c +++ b/libr/core/cmd_anal.inc.c @@ -10183,7 +10183,7 @@ static char *get_buf_asm(RCore *core, ut64 from, ut64 addr, RAnalFunction *fcn, buf_asm = r_print_colorize_opcode (core->print, str, core->cons->context->pal.reg, core->cons->context->pal.num, false, fcn ? fcn->addr : 0); } else { - buf_asm = r_str_new (str); + buf_asm = R_STR_DUP (str); } return buf_asm; } diff --git a/libr/core/cmd_cmp.inc.c b/libr/core/cmd_cmp.inc.c index 418df4c98dd16..0ab1afe131d30 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_new (cmd); + cmpw->cmd = R_STR_DUP (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 fe5d5dcf8d48e..9fb727559674b 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_new (r->name); + namestr = R_STR_DUP (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 09ff2181bf13b..28c517c89fbaf 100644 --- a/libr/core/cmd_zign.inc.c +++ b/libr/core/cmd_zign.inc.c @@ -842,7 +842,7 @@ static double get_zb_threshold(RCore *core) { static bool bestmatch_fcn(RCore *core, const char *input, bool json) { r_return_val_if_fail (input && core, false); - char *argv = r_str_new (input); + char *argv = R_STR_DUP (input); if (!argv) { return false; } @@ -1099,7 +1099,7 @@ static bool diff_zig(void *data, const char *input) { return false; } - char *argv = r_str_new (input); + char *argv = R_STR_DUP (input); if (!argv) { return false; } diff --git a/libr/core/core.c b/libr/core/core.c index 6191d323d8fb9..120fc9f21342f 100644 --- a/libr/core/core.c +++ b/libr/core/core.c @@ -1185,12 +1185,12 @@ static void autocomplete_ms_path(RLineCompletion *completion, RCore *core, const char *pwd = strdup (core->rfs->cwd? (const char *)core->rfs->cwd: "."); int n = 0; RFSFile *file; - char *lpath = r_str_new (path); + char *lpath = R_STR_DUP (path); char *p = (char *)r_str_last (lpath, R_SYS_DIR); if (p) { *p = 0; if (p == lpath) { // /xxx - dirname = r_str_new ("/"); + dirname = R_STR_DUP ("/"); } else if (lpath[0] == '.') { // ./xxx/yyy dirname = r_str_newf ("%s%s", pwd, R_SYS_DIR); } else if (lpath[0] == '/') { // /xxx/yyy @@ -1202,14 +1202,14 @@ static void autocomplete_ms_path(RLineCompletion *completion, RCore *core, const dirname = r_file_new (pwd, lpath, NULL); } } - basename = r_str_new (p + 1); + basename = R_STR_DUP (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_new (lpath); + basename = R_STR_DUP (lpath); } R_FREE (pwd); @@ -1340,7 +1340,7 @@ static void autocomplete_process_path(RLineCompletion *completion, const char *s path++; } #endif - lpath = r_str_new (path); + lpath = R_STR_DUP (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_new (R_SYS_DIR); + dirname = R_STR_DUP (R_SYS_DIR); #endif } else if (lpath[0] == '~' && lpath[1]) { // ~/xxx/yyy dirname = r_file_home (lpath + 2); @@ -1372,10 +1372,10 @@ static void autocomplete_process_path(RLineCompletion *completion, const char *s #endif dirname = r_str_newf (fmt, R_SYS_DIR, lpath, R_SYS_DIR); } - basename = r_str_new (p + 1); + basename = R_STR_DUP (p + 1); } else { // xxx dirname = r_str_newf (".%s", R_SYS_DIR); - basename = r_str_new (lpath); + basename = R_STR_DUP (lpath); } if (!dirname || !basename) { @@ -1419,7 +1419,7 @@ static void autocomplete_filename(RLineCompletion *completion, RLineBuffer *buf, char *pipe = strchr (buf->data, '>'); if (pipe) { - args = r_str_new (pipe); + args = R_STR_DUP (pipe); #if 0 if (pipe[1] == ' ') { // currently unreachable @@ -1427,7 +1427,7 @@ static void autocomplete_filename(RLineCompletion *completion, RLineBuffer *buf, } #endif } else { - args = r_str_new (buf->data); + args = R_STR_DUP (buf->data); } if (!args) { @@ -1439,7 +1439,7 @@ static void autocomplete_filename(RLineCompletion *completion, RLineBuffer *buf, goto out; } - input = r_str_new (r_str_word_get0 (args, narg)); + input = R_STR_DUP (r_str_word_get0 (args, narg)); if (!input) { goto out; } @@ -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_new (str); + lpath = R_STR_DUP (str); p1 = strchr (lpath, '/'); if (p1) { *p1 = 0; diff --git a/libr/core/disasm.c b/libr/core/disasm.c index 54955d0e900f3..18812a51259e9 100644 --- a/libr/core/disasm.c +++ b/libr/core/disasm.c @@ -4856,7 +4856,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_new (msg); + char *msg2 = R_STR_DUP (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 e2be4985f89f6..654a399d5bbc5 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_new (file + 9)); + r_list_push (type_list, R_STR_DUP (file + 9)); } } r_list_free (files); @@ -102,7 +102,7 @@ static char *getrandomline(RCore *core) { return NULL; } const char *file = (const char *)r_list_get_n (types, r_num_rand (r_list_length (types))); - char *type = r_str_new (file); + char *type = R_STR_DUP (file); r_list_free (types); if (!type) { return NULL; diff --git a/libr/core/panels.c b/libr/core/panels.c index ca57f47fae0f0..d0b1272cdc4c9 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_new (panel->model->cmd); + char *tmp = R_STR_DUP (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_new (s), 0); + sdb_ptr_set (core->panels_root->cur_pdc_cache, r_num_as_string (NULL, func->addr, false), R_STR_DUP (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_new (s), 0); + 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_new (pdc_now), sdb, 0); + sdb_ptr_set (core->panels_root->pdc_caches, R_STR_DUP (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_new (s); + p->model->readOnly = R_STR_DUP (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_new (opt); + panel->model->title = R_STR_DUP (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_new (key), &__create_panel_db, 0); + sdb_ptr_set (db, R_STR_DUP (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_new (cur->model->funcName); + new_panel->model->funcName = R_STR_DUP (cur->model->funcName); __set_cmd_str_cache (core, new_panel, cur->model->cmdStrCache); __maximize_panel_size (new_panels); @@ -4685,7 +4685,7 @@ static void __print_decompiler_cb(void *user, void *p) { return; #if 0 if (core->panels_root->cur_pdc_cache) { - cmdstr = r_str_new ((char *)sdb_ptr_get (core->panels_root->cur_pdc_cache, + cmdstr = R_STR_DUP ((char *)sdb_ptr_get (core->panels_root->cur_pdc_cache, r_num_as_string (NULL, func->addr, false), 0)); if (R_STR_ISNOTEMPTY (cmdstr)) { __set_cmd_str_cache (core, panel, cmdstr); @@ -5233,7 +5233,7 @@ static void __add_menu(RCore *core, const char *parent, const char *name, RPanel } item->n_sub = 0; item->selectedIndex = 0; - item->name = name ? r_str_new (name) : NULL; + item->name = name ? R_STR_DUP (name) : NULL; item->sub = NULL; item->cb = cb; item->p = R_NEW0 (RPanel); @@ -7564,10 +7564,10 @@ R_API bool r_core_panels_root(RCore *core, RPanelsRoot *panels_root) { } const char *pdc_now = r_config_get (core->config, "cmd.pdc"); if (sdb_exists (panels_root->pdc_caches, pdc_now)) { - panels_root->cur_pdc_cache = sdb_ptr_get (panels_root->pdc_caches, r_str_new (pdc_now), 0); + panels_root->cur_pdc_cache = sdb_ptr_get (panels_root->pdc_caches, R_STR_DUP (pdc_now), 0); } else { Sdb *sdb = sdb_new0(); - sdb_ptr_set (panels_root->pdc_caches, r_str_new (pdc_now), sdb, 0); + sdb_ptr_set (panels_root->pdc_caches, R_STR_DUP (pdc_now), sdb, 0); panels_root->cur_pdc_cache = sdb; } } diff --git a/libr/core/visual.c b/libr/core/visual.c index f29023f4b028a..abb9e74f99733 100644 --- a/libr/core/visual.c +++ b/libr/core/visual.c @@ -218,7 +218,7 @@ static const char *__core_visual_print_command(RCore *core) { } if (r_config_get_b (core->config, "scr.dumpcols")) { free (core->stkcmd); - core->stkcmd = r_str_new (stackPrintCommand (core)); + core->stkcmd = R_STR_DUP (stackPrintCommand (core)); return printfmtColumns[PIDX]; } return printfmtSingle[PIDX]; diff --git a/libr/lang/p/lib.c b/libr/lang/p/lib.c index 37388bb2718f6..2022c4dafba18 100644 --- a/libr/lang/p/lib.c +++ b/libr/lang/p/lib.c @@ -5,7 +5,7 @@ static bool lang_lib_file_run(RLangSession *user, const char *file) { char *libpath; void *lib; - if (!(libpath = r_str_new (file))) { + if (!(libpath = R_STR_DUP (file))) { return false; } if (!r_str_startswith (libpath, "/") && !r_str_startswith (libpath, "./")) { diff --git a/libr/main/ravc2.c b/libr/main/ravc2.c index d55df1eeda838..49fb4405c47d4 100644 --- a/libr/main/ravc2.c +++ b/libr/main/ravc2.c @@ -139,13 +139,13 @@ R_API int r_main_ravc2(int argc, const char **argv) { free (rp); return 1; } - char *message = r_str_new (opt.argv[opt.ind + 1]); + char *message = R_STR_DUP (opt.argv[opt.ind + 1]); if (message) { RList *files = r_list_new(); if (files) { size_t i; for (i = 2; i < argc - 1; i++) { - char *file = r_str_new(argv[opt.ind + i]); + char *file = R_STR_DUP (argv[opt.ind + i]); if (!file || !r_list_append (files, file)) { free (message); r_list_free (files); diff --git a/libr/main/rax2.c b/libr/main/rax2.c index a8a1f81d55e48..af58185016804 100644 --- a/libr/main/rax2.c +++ b/libr/main/rax2.c @@ -688,7 +688,7 @@ static bool rax(RNum *num, char *str, int len, int last, RaxActions *flags, RaxM } if (flags->octal2raw) { // -o char *modified_str = (*str == '0') - ? r_str_new (str) + ? R_STR_DUP (str) : r_str_newf ("0%s", str); const char *errstr = NULL; ut64 n = r_num_calc (num, modified_str, &errstr); diff --git a/libr/util/axml.c b/libr/util/axml.c index d3402ef9210f2..c088f8917c9c0 100644 --- a/libr/util/axml.c +++ b/libr/util/axml.c @@ -196,7 +196,7 @@ static char *resource_value(string_pool_t *pool, const ut8 *data, ut64 data_size resource_value_t *value) { switch (value->type) { case RESOURCE_NULL: - return r_str_new (""); + return R_STR_DUP (""); case RESOURCE_REFERENCE: return r_str_newf ("@0x%x", value->data.d); case RESOURCE_STRING: @@ -213,7 +213,7 @@ static char *resource_value(string_pool_t *pool, const ut8 *data, ut64 data_size R_LOG_WARN ("Resource type is not recognized: %#x", value->type); break; } - return r_str_new ("null"); + return R_STR_DUP ("null"); } static bool dump_element(PJ *pj, RStrBuf *sb, string_pool_t *pool, namespace_t *namespace, diff --git a/libr/util/rvc_git.c b/libr/util/rvc_git.c index 15fe860eac054..7e69bfcbd22a4 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_new (path); + vc->path = R_STR_DUP (path); if (!vc->path) { free (vc); return NULL; @@ -182,7 +182,7 @@ R_API RList *branches_git(Rvc *rvc) { char *name; r_list_foreach (ret, iter, name) { if (*(char *)iter->data == '*') { - iter->data = r_str_new (name + 2); + iter->data = R_STR_DUP (name + 2); free (name); } diff --git a/libr/util/rvc_rvc.c b/libr/util/rvc_rvc.c index fe9b30986481a..f080ae433c010 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_new (path); + rvc->path = R_STR_DUP (path); if (!rvc->path) { free (rvc); return NULL; @@ -183,15 +183,15 @@ static bool update_blobs(const RList *ignore, RList *blobs, const RList *nh) { if (strcmp (nh->head->data, blob->fname)) { continue; } - blob->fhash = r_str_new (nh->tail->data); + blob->fhash = R_STR_DUP (nh->tail->data); return (bool) blob->fhash; } blob = R_NEW (RvcBlob); if (!blob) { return false; } - blob->fhash = r_str_new (nh->tail->data); - blob->fname = r_str_new (nh->head->data); + blob->fhash = R_STR_DUP (nh->tail->data); + blob->fname = R_STR_DUP (nh->head->data); if (!blob->fhash || !blob->fname) { goto fail_ret; } @@ -325,7 +325,7 @@ static char *absp2rp(Rvc *rvc, const char *absp) { free (arp); return NULL; } - char *p = r_str_new (absp + r_str_len_utf8 (arp)); + char *p = R_STR_DUP (absp + r_str_len_utf8 (arp)); free (arp); if (!p) { return NULL; @@ -352,7 +352,7 @@ static RvcBlob *bfadd(Rvc *rvc, const char *fname) { return NULL; } if (!r_file_exists (absp)) { - ret->fhash = r_str_new (NULLVAL); + ret->fhash = R_STR_DUP (NULLVAL); if (!ret->fhash) { goto fail_ret; } @@ -642,7 +642,7 @@ static char *find_blob_hash(Rvc *rvc, const char *fname) { RvcBlob *b; r_list_foreach_prev (blobs, i, b) { if (!strcmp (b->fname, fname)) { - char *bhash = r_str_new (b->fhash); + char *bhash = R_STR_DUP (b->fhash); free_blobs (blobs); return bhash; } @@ -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_new ((char *)kv->base.key + bplen)) + if (!r_list_append (ret, R_STR_DUP ((char *)kv->base.key + bplen)) && !ret->head->data) { r_list_free (ret); ret = NULL; @@ -944,7 +944,7 @@ R_API char *curbranch_rvc(Rvc *rvc) { if (!rvc->db) { return NULL; } - char *ret = r_str_new (sdb_const_get (rvc->db, CURRENTB, 0) + char *ret = R_STR_DUP (sdb_const_get (rvc->db, CURRENTB, 0) + r_str_len_utf8 (BPREFIX)); return ret; } @@ -1162,7 +1162,7 @@ static RList *uncommited_rvc(Rvc *rvc) { continue; } free (rfp); - char *append = r_str_new (file); + char *append = R_STR_DUP (file); if (!append) { goto fail_ret; } diff --git a/libr/util/syscmd.c b/libr/util/syscmd.c index 32fc642e73615..f5105653f4e00 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_new (field); + char *out = R_STR_DUP (field); char *first = strchr (str1, ' '); char *second = strchr (str2, ' '); out = r_str_append (out, r_str_get_fail (first, " ")); diff --git a/libr/util/table.c b/libr/util/table.c index efb82615f660d..8e626c8b1c7cf 100644 --- a/libr/util/table.c +++ b/libr/util/table.c @@ -267,7 +267,7 @@ R_API void r_table_add_rowf(RTable *t, const char *fmt, ...) { r_list_append (list, r_str_newf ("%.03lf", va_arg (ap, double))); break; case 'b': - r_list_append (list, r_str_new (r_str_bool (va_arg (ap, int)))); + r_list_append (list, R_STR_DUP (r_str_bool (va_arg (ap, int)))); break; case 'i': case 'd': From 166629d78d390734bc46d4ed001f8eb1172fed3a Mon Sep 17 00:00:00 2001 From: satk0 Date: Tue, 23 Jul 2024 12:53:21 +0200 Subject: [PATCH 02/31] Depreciate r_str_newlen --- libr/anal/var.c | 4 ++-- libr/bin/p/bin_lua.c | 2 +- libr/core/cmd_help.inc.c | 4 ++-- libr/core/disasm.c | 2 +- libr/core/panels.c | 4 ++-- libr/util/file.c | 4 ++-- libr/util/str.c | 6 +++--- libr/util/strbuf.c | 2 +- shlr/ar/ar.c | 2 +- 9 files changed, 15 insertions(+), 15 deletions(-) diff --git a/libr/anal/var.c b/libr/anal/var.c index 0c1f4a69a4f94..f93b55e06a9f0 100644 --- a/libr/anal/var.c +++ b/libr/anal/var.c @@ -334,7 +334,7 @@ R_API RList *r_anal_var_deserialize(const char *ser) { } nxt++; } - v->name = r_str_newlen (ser, i); + v->name = r_str_ndup (ser, i); if (!v->name) { goto bad_serial; } @@ -345,7 +345,7 @@ R_API RList *r_anal_var_deserialize(const char *ser) { for (i = 0; *nxt && *nxt != ','; i++) { nxt++; } - v->type = r_str_newlen (ser, i); + v->type = r_str_ndup (ser, i); if (!v->type) { goto bad_serial; } diff --git a/libr/bin/p/bin_lua.c b/libr/bin/p/bin_lua.c index f1b80d5d1c84f..a18c0c33fa671 100644 --- a/libr/bin/p/bin_lua.c +++ b/libr/bin/p/bin_lua.c @@ -144,7 +144,7 @@ static void addString(const ut8 *buf, ut64 offset, ut64 length, ParseStruct *par return; } - binstring->string = r_str_newlen ((char *) buf + offset, length); + binstring->string = r_str_ndup ((char *) buf + offset, length); binstring->vaddr = binstring->paddr = offset; binstring->ordinal = 0; binstring->size = length; diff --git a/libr/core/cmd_help.inc.c b/libr/core/cmd_help.inc.c index 361ecd557bf3a..f3a0910b48593 100644 --- a/libr/core/cmd_help.inc.c +++ b/libr/core/cmd_help.inc.c @@ -455,7 +455,7 @@ static char *filterFlags(RCore *core, const char *msg) { // find } end = strchr (dollar + 2, '}'); if (end) { - word = r_str_newlen (dollar+2, end-dollar-2); + word = r_str_ndup (dollar+2, end-dollar-2); end++; } else { msg = dollar + 1; @@ -471,7 +471,7 @@ static char *filterFlags(RCore *core, const char *msg) { if (!end) { end = dollar + strlen (dollar); } - word = r_str_newlen (dollar+1, end-dollar-1); + word = r_str_ndup (dollar+1, end-dollar-1); } if (end && word) { ut64 val = r_num_math (core->num, word); diff --git a/libr/core/disasm.c b/libr/core/disasm.c index 18812a51259e9..e278b6dfa4eb0 100644 --- a/libr/core/disasm.c +++ b/libr/core/disasm.c @@ -1283,7 +1283,7 @@ static void ds_build_op_str(RDisasmState *ds, bool print_color) { char **wc_array = r_str_argv (wcdata, &argc); for (i = 0; i < argc; i++) { bgcolor = strchr (wc_array[i], '\x1b'); - word = r_str_newlen (wc_array[i], bgcolor - wc_array[i]); + word = r_str_ndup (wc_array[i], bgcolor - wc_array[i]); ds_highlight_word (ds, word, bgcolor); } } diff --git a/libr/core/panels.c b/libr/core/panels.c index d0b1272cdc4c9..6652eeee78530 100644 --- a/libr/core/panels.c +++ b/libr/core/panels.c @@ -3923,7 +3923,7 @@ static char *__get_word_from_canvas_for_menu(RCore *core, RPanels *panels, int x tmp++; i++; } - char *ret = r_str_newlen (pos += strlen (padding), i - strlen (padding)); + char *ret = r_str_ndup (pos += strlen (padding), i - strlen (padding)); if (!ret) { ret = strdup (pos); } @@ -6569,7 +6569,7 @@ static char *__parse_panels_config(const char *cfg, int len) { if (R_STR_ISEMPTY (cfg) || len < 2) { return NULL; } - char *tmp = r_str_newlen (cfg, len + 1); + char *tmp = r_str_ndup (cfg, len + 1); if (!tmp) { return NULL; } diff --git a/libr/util/file.c b/libr/util/file.c index a7567f7ef837e..3b54735fb87dd 100644 --- a/libr/util/file.c +++ b/libr/util/file.c @@ -1549,11 +1549,11 @@ R_API RList* r_file_glob(const char *_globbed_path, int maxdepth) { if (last_slash) { glob_ptr = last_slash + 1; if (globbed_path[0] == '~') { - char *rpath = r_str_newlen (globbed_path + 2, last_slash - globbed_path - 1); + char *rpath = r_str_ndup (globbed_path + 2, last_slash - globbed_path - 1); path = r_file_home (r_str_get (rpath)); free (rpath); } else { - path = r_str_newlen (globbed_path, last_slash - globbed_path + 1); + path = r_str_ndup (globbed_path, last_slash - globbed_path + 1); } } else { glob_ptr = globbed_path; diff --git a/libr/util/str.c b/libr/util/str.c index 950d8aafd470e..9532a42a69adb 100644 --- a/libr/util/str.c +++ b/libr/util/str.c @@ -672,7 +672,7 @@ R_API char *r_str_trunc_ellipsis(const char *str, int len) { if (strlen (str) < len) { return strdup (str); } - char *buf = r_str_newlen (str, len); + char *buf = r_str_ndup (str, len); if (buf && len > 4) { strcpy (buf + len - 4, "..."); } @@ -817,7 +817,7 @@ R_API char *r_str_prepend(char *ptr, const char *string) { R_API char *r_str_appendlen(char *ptr, const char *string, int slen) { r_return_val_if_fail (string, NULL); - char *msg = r_str_newlen (string, slen); + char *msg = r_str_ndup (string, slen); char *ret = r_str_append (ptr, msg); free (msg); return ret; @@ -2417,7 +2417,7 @@ R_API bool r_str_glob(const char* str, const char *glob) { needle_end++; } // Find the pattern in between wildcards - char* needle = r_str_ndup(glob, needle_end - glob); + char* needle = r_str_ndup (glob, needle_end - glob); const char *advance_to = strstr (str, needle); free (needle); if (!advance_to) { diff --git a/libr/util/strbuf.c b/libr/util/strbuf.c index 855b5f3165336..4feb85086626d 100644 --- a/libr/util/strbuf.c +++ b/libr/util/strbuf.c @@ -130,7 +130,7 @@ R_API bool r_strbuf_slice(RStrBuf *sb, int from, int len) { const char *s = r_strbuf_get (sb); const char *fr = r_str_ansi_chrn (s, from + 1); const char *to = r_str_ansi_chrn (s, from + len + 1); - char *r = r_str_newlen (fr, to - fr); + char *r = r_str_ndup (fr, to - fr); r_strbuf_fini (sb); r_strbuf_init (sb); if (from >= len) { diff --git a/shlr/ar/ar.c b/shlr/ar/ar.c index 77a9421cba18d..c2617ec1af0e4 100644 --- a/shlr/ar/ar.c +++ b/shlr/ar/ar.c @@ -64,7 +64,7 @@ static char *name_from_table(ut64 off, filetable *tbl) { if (i == off) { return NULL; } - return r_str_newlen (buf + off, i - off - 1); + return r_str_ndup (buf + off, i - off - 1); } #define VERIFY_AR_NUM_FIELD(x, s) \ From 69f6cac4662e87f675363a32ce6f0d2ae1fb1a45 Mon Sep 17 00:00:00 2001 From: satk0 Date: Tue, 23 Jul 2024 12:57:10 +0200 Subject: [PATCH 03/31] Avoid R_STR_DUP when possible --- libr/anal/value.c | 2 +- libr/arch/arch_value.c | 2 +- libr/arch/p/dalvik/plugin.c | 4 ++-- libr/arch/p/pyc/opcode_arg_fmt.c | 2 +- libr/bin/format/mach0/mach0.c | 4 ++-- libr/core/cbin.c | 2 +- libr/core/cmd.c | 2 +- libr/core/core.c | 2 +- libr/util/axml.c | 4 ++-- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/libr/anal/value.c b/libr/anal/value.c index 53adf2d969355..c10234c5759ee 100644 --- a/libr/anal/value.c +++ b/libr/anal/value.c @@ -66,7 +66,7 @@ R_API const char *r_anal_value_type_tostring(RAnalValue *value) { R_API char *r_anal_value_tostring(RAnalValue *value) { char *out = NULL; if (value) { - out = R_STR_DUP (""); + out = strdup (""); if (!value->base && !value->reg) { if (value->imm != -1LL) { out = r_str_appendf (out, "0x%"PFMT64x, value->imm); diff --git a/libr/arch/arch_value.c b/libr/arch/arch_value.c index 6ecf88b534623..5f4f654650a89 100644 --- a/libr/arch/arch_value.c +++ b/libr/arch/arch_value.c @@ -100,7 +100,7 @@ R_API bool r_arch_value_set_ut64(RArchValue *val, RReg *reg, RIOBind *iob, ut64 R_API char *r_arch_value_tostring(RArchValue *value) { char *out = NULL; if (value) { - out = R_STR_DUP (""); + out = strdup (""); if (!value->base && !value->reg) { if (value->imm != -1LL) { out = r_str_appendf (out, "0x%"PFMT64x, value->imm); diff --git a/libr/arch/p/dalvik/plugin.c b/libr/arch/p/dalvik/plugin.c index a2caab7a767c6..a6e47940f2d96 100644 --- a/libr/arch/p/dalvik/plugin.c +++ b/libr/arch/p/dalvik/plugin.c @@ -763,7 +763,7 @@ static int dalvik_disassemble(RArchSession *as, RAnalOp *op, ut64 addr, const ut } op->mnemonic = R_STR_DUP (r_str_get_fail (strasm, "invalid")); } else if (len > 0) { - op->mnemonic = R_STR_DUP ("invalid"); + op->mnemonic = strdup ("invalid"); size = len; } @@ -794,7 +794,7 @@ static bool decode(RArchSession *as, RAnalOp *op, RAnalOpMask mask) { int sz = dalvik_opcodes[data[0]].len; if (!op || sz > len) { if (mask & R_ARCH_OP_MASK_DISASM) { - op->mnemonic = R_STR_DUP ("invalid"); + op->mnemonic = strdup ("invalid"); } return false; } diff --git a/libr/arch/p/pyc/opcode_arg_fmt.c b/libr/arch/p/pyc/opcode_arg_fmt.c index 1b6064a15b975..bd4ae35f0809d 100644 --- a/libr/arch/p/pyc/opcode_arg_fmt.c +++ b/libr/arch/p/pyc/opcode_arg_fmt.c @@ -29,7 +29,7 @@ static const char *MAKE_FUNCTION_FLAGS[] = { "default", "keyword-only", "annotat char *format_MAKE_FUNCTION_arg_36(ut32 oparg) { size_t i; - char *ret = R_STR_DUP (" "); + char *ret = strdup (" "); for (i = 0; i < sizeof (MAKE_FUNCTION_FLAGS) / sizeof (char *); ++i) { if (oparg & 0x1) { ret = r_str_appendf (ret, ", %s", MAKE_FUNCTION_FLAGS[i]); diff --git a/libr/bin/format/mach0/mach0.c b/libr/bin/format/mach0/mach0.c index b8eb5c4e157d8..23bdbf72909a8 100644 --- a/libr/bin/format/mach0/mach0.c +++ b/libr/bin/format/mach0/mach0.c @@ -4184,9 +4184,9 @@ ut64 MACH0_(get_baddr)(struct MACH0_(obj_t) *mo) { char *MACH0_(get_class)(struct MACH0_(obj_t) *mo) { #if R_BIN_MACH064 - return R_STR_DUP ("MACH064"); + return strdup ("MACH064"); #else - return R_STR_DUP ("MACH0"); + return strdup ("MACH0"); #endif } diff --git a/libr/core/cbin.c b/libr/core/cbin.c index 9617474961eac..8b7f07cdce9f0 100644 --- a/libr/core/cbin.c +++ b/libr/core/cbin.c @@ -2969,7 +2969,7 @@ static bool bin_map_sections_to_segments(RBin *bin, PJ *pj, int mode) { r_list_foreach (segments, iter, segment) { RInterval segment_itv = (RInterval){segment->vaddr, segment->size}; - char *tmp2 = R_STR_DUP (""); + char *tmp2 = strdup (""); r_list_foreach (sections, iter2, section) { RInterval section_itv = (RInterval){section->vaddr, section->size}; if (r_itv_begin (section_itv) >= r_itv_begin (segment_itv) && r_itv_end (section_itv) <= r_itv_end (segment_itv) && section->name[0]) { diff --git a/libr/core/cmd.c b/libr/core/cmd.c index 98ca437ba9a51..c64c1cf90e00b 100644 --- a/libr/core/cmd.c +++ b/libr/core/cmd.c @@ -2522,7 +2522,7 @@ static int cmd_kuery(void *data, const char *input) { RLine *line = core->cons->line; if (!line->sdbshell_hist) { line->sdbshell_hist = r_list_newf (free); - r_list_append (line->sdbshell_hist, R_STR_DUP ("\0")); + r_list_append (line->sdbshell_hist, strdup ("\0")); } RList *sdb_hist = line->sdbshell_hist; r_line_set_hist_callback (line, &r_line_hist_sdb_up, &r_line_hist_sdb_down); diff --git a/libr/core/core.c b/libr/core/core.c index 120fc9f21342f..bec97239b7758 100644 --- a/libr/core/core.c +++ b/libr/core/core.c @@ -1190,7 +1190,7 @@ static void autocomplete_ms_path(RLineCompletion *completion, RCore *core, const if (p) { *p = 0; if (p == lpath) { // /xxx - dirname = R_STR_DUP ("/"); + dirname = strdup ("/"); } else if (lpath[0] == '.') { // ./xxx/yyy dirname = r_str_newf ("%s%s", pwd, R_SYS_DIR); } else if (lpath[0] == '/') { // /xxx/yyy diff --git a/libr/util/axml.c b/libr/util/axml.c index c088f8917c9c0..8f3d917eb9fe2 100644 --- a/libr/util/axml.c +++ b/libr/util/axml.c @@ -196,7 +196,7 @@ static char *resource_value(string_pool_t *pool, const ut8 *data, ut64 data_size resource_value_t *value) { switch (value->type) { case RESOURCE_NULL: - return R_STR_DUP (""); + return strdup (""); case RESOURCE_REFERENCE: return r_str_newf ("@0x%x", value->data.d); case RESOURCE_STRING: @@ -213,7 +213,7 @@ static char *resource_value(string_pool_t *pool, const ut8 *data, ut64 data_size R_LOG_WARN ("Resource type is not recognized: %#x", value->type); break; } - return R_STR_DUP ("null"); + return strdup ("null"); } static bool dump_element(PJ *pj, RStrBuf *sb, string_pool_t *pool, namespace_t *namespace, From 9462af83edac9cb176d191d0aad405097aca5f00 Mon Sep 17 00:00:00 2001 From: satk0 Date: Tue, 23 Jul 2024 14:28:32 +0200 Subject: [PATCH 04/31] Fix tests --- libr/anal/var.c | 12 ++++++++++-- libr/bin/p/bin_lua.c | 6 +++++- libr/core/cmd_help.inc.c | 12 ++++++++++-- libr/core/disasm.c | 6 +++++- libr/core/panels.c | 14 ++++++++++++-- libr/util/file.c | 13 +++++++++++-- libr/util/str.c | 12 ++++++++++-- libr/util/strbuf.c | 5 ++++- shlr/ar/ar.c | 6 +++++- 9 files changed, 72 insertions(+), 14 deletions(-) diff --git a/libr/anal/var.c b/libr/anal/var.c index f93b55e06a9f0..1581746e81beb 100644 --- a/libr/anal/var.c +++ b/libr/anal/var.c @@ -334,7 +334,11 @@ R_API RList *r_anal_var_deserialize(const char *ser) { } nxt++; } - v->name = r_str_ndup (ser, i); + if (i >= 1) { + v->name = r_str_ndup (ser, i); + } else { + v->name = NULL; + } if (!v->name) { goto bad_serial; } @@ -345,7 +349,11 @@ R_API RList *r_anal_var_deserialize(const char *ser) { for (i = 0; *nxt && *nxt != ','; i++) { nxt++; } - v->type = r_str_ndup (ser, i); + if (i >= 1) { + v->type = r_str_ndup (ser, i); + } else { + v->type = NULL; + } if (!v->type) { goto bad_serial; } diff --git a/libr/bin/p/bin_lua.c b/libr/bin/p/bin_lua.c index a18c0c33fa671..233c9928f512f 100644 --- a/libr/bin/p/bin_lua.c +++ b/libr/bin/p/bin_lua.c @@ -144,7 +144,11 @@ static void addString(const ut8 *buf, ut64 offset, ut64 length, ParseStruct *par return; } - binstring->string = r_str_ndup ((char *) buf + offset, length); + if (length >= 1) { + binstring->string = r_str_ndup ((char *) buf + offset, length); + } else { + binstring->string = NULL; + } binstring->vaddr = binstring->paddr = offset; binstring->ordinal = 0; binstring->size = length; diff --git a/libr/core/cmd_help.inc.c b/libr/core/cmd_help.inc.c index f3a0910b48593..aaeaaa0583d4d 100644 --- a/libr/core/cmd_help.inc.c +++ b/libr/core/cmd_help.inc.c @@ -455,7 +455,11 @@ static char *filterFlags(RCore *core, const char *msg) { // find } end = strchr (dollar + 2, '}'); if (end) { - word = r_str_ndup (dollar+2, end-dollar-2); + if (end-dollar-2 >= 1) { + word = r_str_ndup (dollar+2, end-dollar-2); + } else { + word = NULL; + } end++; } else { msg = dollar + 1; @@ -471,7 +475,11 @@ static char *filterFlags(RCore *core, const char *msg) { if (!end) { end = dollar + strlen (dollar); } - word = r_str_ndup (dollar+1, end-dollar-1); + if (end-dollar-1 >=1 ) { + word = r_str_ndup (dollar+1, end-dollar-1); + } else { + word = NULL; + } } if (end && word) { ut64 val = r_num_math (core->num, word); diff --git a/libr/core/disasm.c b/libr/core/disasm.c index e278b6dfa4eb0..48d3218f980ab 100644 --- a/libr/core/disasm.c +++ b/libr/core/disasm.c @@ -1283,7 +1283,11 @@ static void ds_build_op_str(RDisasmState *ds, bool print_color) { char **wc_array = r_str_argv (wcdata, &argc); for (i = 0; i < argc; i++) { bgcolor = strchr (wc_array[i], '\x1b'); - word = r_str_ndup (wc_array[i], bgcolor - wc_array[i]); + if (bgcolor - wc_array[i] >= 1) { + word = r_str_ndup (wc_array[i], bgcolor - wc_array[i]); + } else { + word = NULL; + } ds_highlight_word (ds, word, bgcolor); } } diff --git a/libr/core/panels.c b/libr/core/panels.c index 6652eeee78530..5534e1658729a 100644 --- a/libr/core/panels.c +++ b/libr/core/panels.c @@ -3923,7 +3923,12 @@ static char *__get_word_from_canvas_for_menu(RCore *core, RPanels *panels, int x tmp++; i++; } - char *ret = r_str_ndup (pos += strlen (padding), i - strlen (padding)); + char *ret; + if (i - strlen (padding) >= 1) { + ret = r_str_ndup (pos += strlen (padding), i - strlen (padding)); + } else { + ret = NULL; + } if (!ret) { ret = strdup (pos); } @@ -6569,7 +6574,12 @@ static char *__parse_panels_config(const char *cfg, int len) { if (R_STR_ISEMPTY (cfg) || len < 2) { return NULL; } - char *tmp = r_str_ndup (cfg, len + 1); + char *tmp; + if (len + 1) { + tmp = r_str_ndup (cfg, len + 1); + } else { + tmp = NULL; + } if (!tmp) { return NULL; } diff --git a/libr/util/file.c b/libr/util/file.c index 3b54735fb87dd..1ae934ed0615e 100644 --- a/libr/util/file.c +++ b/libr/util/file.c @@ -1549,11 +1549,20 @@ R_API RList* r_file_glob(const char *_globbed_path, int maxdepth) { if (last_slash) { glob_ptr = last_slash + 1; if (globbed_path[0] == '~') { - char *rpath = r_str_ndup (globbed_path + 2, last_slash - globbed_path - 1); + char *rpath; + if (last_slash - globbed_path - 1) { + rpath = r_str_ndup (globbed_path + 2, last_slash - globbed_path - 1); + } else { + rpath = NULL; + } path = r_file_home (r_str_get (rpath)); free (rpath); } else { - path = r_str_ndup (globbed_path, last_slash - globbed_path + 1); + if (last_slash - globbed_path + 1) { + path = r_str_ndup (globbed_path, last_slash - globbed_path + 1); + } else { + path = NULL; + } } } else { glob_ptr = globbed_path; diff --git a/libr/util/str.c b/libr/util/str.c index 9532a42a69adb..7ee0b3695a512 100644 --- a/libr/util/str.c +++ b/libr/util/str.c @@ -672,7 +672,12 @@ R_API char *r_str_trunc_ellipsis(const char *str, int len) { if (strlen (str) < len) { return strdup (str); } - char *buf = r_str_ndup (str, len); + char *buf; + if (len) { + buf = r_str_ndup (str, len); + } else { + buf = NULL; + } if (buf && len > 4) { strcpy (buf + len - 4, "..."); } @@ -817,7 +822,10 @@ R_API char *r_str_prepend(char *ptr, const char *string) { R_API char *r_str_appendlen(char *ptr, const char *string, int slen) { r_return_val_if_fail (string, NULL); - char *msg = r_str_ndup (string, slen); + char *msg = NULL; + if (slen) { + msg = r_str_ndup (string, slen); + } char *ret = r_str_append (ptr, msg); free (msg); return ret; diff --git a/libr/util/strbuf.c b/libr/util/strbuf.c index 4feb85086626d..b37f40cc87283 100644 --- a/libr/util/strbuf.c +++ b/libr/util/strbuf.c @@ -130,7 +130,10 @@ R_API bool r_strbuf_slice(RStrBuf *sb, int from, int len) { const char *s = r_strbuf_get (sb); const char *fr = r_str_ansi_chrn (s, from + 1); const char *to = r_str_ansi_chrn (s, from + len + 1); - char *r = r_str_ndup (fr, to - fr); + char *r = NULL; + if (to - fr) { + r = r_str_ndup (fr, to - fr); + } r_strbuf_fini (sb); r_strbuf_init (sb); if (from >= len) { diff --git a/shlr/ar/ar.c b/shlr/ar/ar.c index c2617ec1af0e4..6ae728d4b9452 100644 --- a/shlr/ar/ar.c +++ b/shlr/ar/ar.c @@ -64,7 +64,11 @@ static char *name_from_table(ut64 off, filetable *tbl) { if (i == off) { return NULL; } - return r_str_ndup (buf + off, i - off - 1); + if (i - off - 1) { + return r_str_ndup (buf + off, i - off - 1); + } else { + return NULL; + } } #define VERIFY_AR_NUM_FIELD(x, s) \ From a04be5c71ddb58b0a144b2cd4122f152fa628642 Mon Sep 17 00:00:00 2001 From: satk0 Date: Tue, 23 Jul 2024 14:45:18 +0200 Subject: [PATCH 05/31] Fix linting --- libr/anal/var.c | 10 ++++------ libr/bin/p/bin_lua.c | 5 ++--- libr/core/cmd_help.inc.c | 10 ++++------ libr/core/disasm.c | 5 ++--- libr/core/panels.c | 10 +++------- libr/util/file.c | 7 ++----- libr/util/str.c | 4 +--- 7 files changed, 18 insertions(+), 33 deletions(-) diff --git a/libr/anal/var.c b/libr/anal/var.c index 1581746e81beb..183c8ca69e78a 100644 --- a/libr/anal/var.c +++ b/libr/anal/var.c @@ -334,10 +334,9 @@ R_API RList *r_anal_var_deserialize(const char *ser) { } nxt++; } - if (i >= 1) { + v->name = NULL; + if (i) { v->name = r_str_ndup (ser, i); - } else { - v->name = NULL; } if (!v->name) { goto bad_serial; @@ -349,10 +348,9 @@ R_API RList *r_anal_var_deserialize(const char *ser) { for (i = 0; *nxt && *nxt != ','; i++) { nxt++; } - if (i >= 1) { + v->type = NULL; + if (i) { v->type = r_str_ndup (ser, i); - } else { - v->type = NULL; } if (!v->type) { goto bad_serial; diff --git a/libr/bin/p/bin_lua.c b/libr/bin/p/bin_lua.c index 233c9928f512f..d2b0d21c86c63 100644 --- a/libr/bin/p/bin_lua.c +++ b/libr/bin/p/bin_lua.c @@ -144,10 +144,9 @@ static void addString(const ut8 *buf, ut64 offset, ut64 length, ParseStruct *par return; } - if (length >= 1) { + binstring->string = NULL; + if (length) { binstring->string = r_str_ndup ((char *) buf + offset, length); - } else { - binstring->string = NULL; } binstring->vaddr = binstring->paddr = offset; binstring->ordinal = 0; diff --git a/libr/core/cmd_help.inc.c b/libr/core/cmd_help.inc.c index aaeaaa0583d4d..e99b2e929c458 100644 --- a/libr/core/cmd_help.inc.c +++ b/libr/core/cmd_help.inc.c @@ -455,10 +455,9 @@ static char *filterFlags(RCore *core, const char *msg) { // find } end = strchr (dollar + 2, '}'); if (end) { - if (end-dollar-2 >= 1) { + word = NULL; + if (end-dollar-2) { word = r_str_ndup (dollar+2, end-dollar-2); - } else { - word = NULL; } end++; } else { @@ -475,10 +474,9 @@ static char *filterFlags(RCore *core, const char *msg) { if (!end) { end = dollar + strlen (dollar); } - if (end-dollar-1 >=1 ) { + word = NULL; + if (end-dollar-1) { word = r_str_ndup (dollar+1, end-dollar-1); - } else { - word = NULL; } } if (end && word) { diff --git a/libr/core/disasm.c b/libr/core/disasm.c index 48d3218f980ab..0e4c2bee4a1d3 100644 --- a/libr/core/disasm.c +++ b/libr/core/disasm.c @@ -1283,10 +1283,9 @@ static void ds_build_op_str(RDisasmState *ds, bool print_color) { char **wc_array = r_str_argv (wcdata, &argc); for (i = 0; i < argc; i++) { bgcolor = strchr (wc_array[i], '\x1b'); - if (bgcolor - wc_array[i] >= 1) { + word = NULL; + if (bgcolor - wc_array[i]) { word = r_str_ndup (wc_array[i], bgcolor - wc_array[i]); - } else { - word = NULL; } ds_highlight_word (ds, word, bgcolor); } diff --git a/libr/core/panels.c b/libr/core/panels.c index 5534e1658729a..f70f79b705ad9 100644 --- a/libr/core/panels.c +++ b/libr/core/panels.c @@ -3923,11 +3923,9 @@ static char *__get_word_from_canvas_for_menu(RCore *core, RPanels *panels, int x tmp++; i++; } - char *ret; - if (i - strlen (padding) >= 1) { + char *ret = NULL; + if (i - strlen (padding)) { ret = r_str_ndup (pos += strlen (padding), i - strlen (padding)); - } else { - ret = NULL; } if (!ret) { ret = strdup (pos); @@ -6574,11 +6572,9 @@ static char *__parse_panels_config(const char *cfg, int len) { if (R_STR_ISEMPTY (cfg) || len < 2) { return NULL; } - char *tmp; + char *tmp = NULL; if (len + 1) { tmp = r_str_ndup (cfg, len + 1); - } else { - tmp = NULL; } if (!tmp) { return NULL; diff --git a/libr/util/file.c b/libr/util/file.c index 1ae934ed0615e..2fedd6e729d12 100644 --- a/libr/util/file.c +++ b/libr/util/file.c @@ -1549,19 +1549,16 @@ R_API RList* r_file_glob(const char *_globbed_path, int maxdepth) { if (last_slash) { glob_ptr = last_slash + 1; if (globbed_path[0] == '~') { - char *rpath; + char *rpath = NULL; if (last_slash - globbed_path - 1) { rpath = r_str_ndup (globbed_path + 2, last_slash - globbed_path - 1); - } else { - rpath = NULL; } path = r_file_home (r_str_get (rpath)); free (rpath); } else { + path = NULL; if (last_slash - globbed_path + 1) { path = r_str_ndup (globbed_path, last_slash - globbed_path + 1); - } else { - path = NULL; } } } else { diff --git a/libr/util/str.c b/libr/util/str.c index 7ee0b3695a512..0443c88d0efdf 100644 --- a/libr/util/str.c +++ b/libr/util/str.c @@ -672,11 +672,9 @@ R_API char *r_str_trunc_ellipsis(const char *str, int len) { if (strlen (str) < len) { return strdup (str); } - char *buf; + char *buf = NULL; if (len) { buf = r_str_ndup (str, len); - } else { - buf = NULL; } if (buf && len > 4) { strcpy (buf + len - 4, "..."); From fe47a2ec16726e109479bbb8f0b27c645cc52500 Mon Sep 17 00:00:00 2001 From: satk0 Date: Tue, 23 Jul 2024 15:56:45 +0200 Subject: [PATCH 06/31] Fixes according to previous review --- libr/arch/p/8051/8051_disas.c | 2 +- libr/arch/p/dalvik/plugin.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libr/arch/p/8051/8051_disas.c b/libr/arch/p/8051/8051_disas.c index ee06ad47ea76d..e2fc4cc86517e 100644 --- a/libr/arch/p/8051/8051_disas.c +++ b/libr/arch/p/8051/8051_disas.c @@ -31,7 +31,7 @@ static char *r_8051_disas(ut64 pc, const ut8 *buf, int len, int *olen) { // op @Ri; op Rn disasm = r_str_newf (name, buf[0] & mask); } else { - disasm = R_STR_DUP (name); + disasm = strdup (name); } break; case 2: diff --git a/libr/arch/p/dalvik/plugin.c b/libr/arch/p/dalvik/plugin.c index a6e47940f2d96..7bee6d30bafcb 100644 --- a/libr/arch/p/dalvik/plugin.c +++ b/libr/arch/p/dalvik/plugin.c @@ -761,7 +761,7 @@ static int dalvik_disassemble(RArchSession *as, RAnalOp *op, ut64 addr, const ut R_FREE (strasm); size = 2; } - op->mnemonic = R_STR_DUP (r_str_get_fail (strasm, "invalid")); + op->mnemonic = strdup (r_str_get_fail (strasm, "invalid")); } else if (len > 0) { op->mnemonic = strdup ("invalid"); size = len; From 7775f4fc0930431f12c2497e0cd16269fed3cc34 Mon Sep 17 00:00:00 2001 From: pancake Date: Wed, 24 Jul 2024 19:26:13 +0200 Subject: [PATCH 07/31] Update libr/arch/p/pyc/opcode_arg_fmt.c --- libr/arch/p/pyc/opcode_arg_fmt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libr/arch/p/pyc/opcode_arg_fmt.c b/libr/arch/p/pyc/opcode_arg_fmt.c index bd4ae35f0809d..ead4bef322a19 100644 --- a/libr/arch/p/pyc/opcode_arg_fmt.c +++ b/libr/arch/p/pyc/opcode_arg_fmt.c @@ -22,7 +22,7 @@ char *format_CALL_FUNCTION_KW_36(ut32 oparg) { } char *format_CALL_FUNCTION_EX_36(ut32 oparg) { - return R_STR_DUP ((oparg & 0x01)? "keyword args": ""); + return strdup ((oparg & 0x01)? "keyword args": ""); } static const char *MAKE_FUNCTION_FLAGS[] = { "default", "keyword-only", "annotation", "closure" }; From e25725e7209675e8ceb84c8aea6f2fa48e6e5f10 Mon Sep 17 00:00:00 2001 From: satk0 Date: Thu, 25 Jul 2024 01:34:15 +0200 Subject: [PATCH 08/31] Change according to review --- libr/util/table.c | 2 +- shlr/ar/ar.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libr/util/table.c b/libr/util/table.c index 8e626c8b1c7cf..8ef8885ddacb9 100644 --- a/libr/util/table.c +++ b/libr/util/table.c @@ -267,7 +267,7 @@ R_API void r_table_add_rowf(RTable *t, const char *fmt, ...) { r_list_append (list, r_str_newf ("%.03lf", va_arg (ap, double))); break; case 'b': - r_list_append (list, R_STR_DUP (r_str_bool (va_arg (ap, int)))); + r_list_append (list, strdup (r_str_bool (va_arg (ap, int)))); break; case 'i': case 'd': diff --git a/shlr/ar/ar.c b/shlr/ar/ar.c index 6ae728d4b9452..423677b65979f 100644 --- a/shlr/ar/ar.c +++ b/shlr/ar/ar.c @@ -64,11 +64,11 @@ static char *name_from_table(ut64 off, filetable *tbl) { if (i == off) { return NULL; } + char *res = NULL; if (i - off - 1) { - return r_str_ndup (buf + off, i - off - 1); - } else { - return NULL; + res = r_str_ndup (buf + off, i - off - 1); } + return res; } #define VERIFY_AR_NUM_FIELD(x, s) \ From 8156b094f479193090a9c8a20c36f8473f532d80 Mon Sep 17 00:00:00 2001 From: satk0 Date: Sat, 27 Jul 2024 13:23:16 +0200 Subject: [PATCH 09/31] Fix according to review --- libr/anal/sign.c | 4 ++-- libr/core/canal.c | 2 +- libr/core/cmd_cmp.inc.c | 2 +- libr/core/cmd_debug.inc.c | 2 +- libr/core/cmd_zign.inc.c | 2 +- libr/core/core.c | 12 ++++++------ libr/core/disasm.c | 2 +- libr/core/fortune.c | 2 +- libr/core/panels.c | 14 +++++++------- libr/main/ravc2.c | 2 +- libr/util/rvc_git.c | 2 +- libr/util/rvc_rvc.c | 6 +++--- libr/util/str.c | 2 +- libr/util/strbuf.c | 2 +- libr/util/syscmd.c | 2 +- shlr/ar/ar.c | 2 +- 16 files changed, 30 insertions(+), 30 deletions(-) diff --git a/libr/anal/sign.c b/libr/anal/sign.c index b1b9c0b831a11..4657db3e145c1 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 0138bc2ee9426..c9f40df8e87cf 100644 --- a/libr/core/canal.c +++ b/libr/core/canal.c @@ -2452,7 +2452,7 @@ static void add_single_addr_xrefs(RCore *core, ut64 addr, RGraph *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 0ab1afe131d30..8012f153819f7 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 9fb727559674b..ff1e3ef43afe9 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 28c517c89fbaf..40821bcbdfb2a 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 bec97239b7758..7e69fdf476252 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 0e4c2bee4a1d3..6ba554f49392e 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 654a399d5bbc5..a4ee1673e4195 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 f70f79b705ad9..f11c2ef247d92 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 49fb4405c47d4..c63e502cd7330 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 7e69bfcbd22a4..dd4866375a066 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 f080ae433c010..3929081fcba22 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 0443c88d0efdf..ea6aa7773ce9c 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 b37f40cc87283..a681b7883ca2c 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 f5105653f4e00..238f1862fa20b 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 423677b65979f..1b30afae197ec 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; From b61f3e4e2fe382f7c23ef160c6ad646f79e820a7 Mon Sep 17 00:00:00 2001 From: satk0 Date: Thu, 1 Aug 2024 13:23:07 +0200 Subject: [PATCH 10/31] Use strdup when not nullable --- libr/anal/sign.c | 2 +- libr/util/rvc_rvc.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libr/anal/sign.c b/libr/anal/sign.c index 4657db3e145c1..af2d84ba5f7d5 100644 --- a/libr/anal/sign.c +++ b/libr/anal/sign.c @@ -343,7 +343,7 @@ R_API bool r_sign_deserialize(RAnal *a, RSignItem *it, const char *k, const char if (token[0] != 0) { it->hash = R_NEW0 (RSignHash); if (it->hash) { - it->hash->bbhash = R_STR_DUP (token); + it->hash->bbhash = strdup (token); } } break; diff --git a/libr/util/rvc_rvc.c b/libr/util/rvc_rvc.c index 3929081fcba22..ddb52ef4e8593 100644 --- a/libr/util/rvc_rvc.c +++ b/libr/util/rvc_rvc.c @@ -352,7 +352,7 @@ static RvcBlob *bfadd(Rvc *rvc, const char *fname) { return NULL; } if (!r_file_exists (absp)) { - ret->fhash = R_STR_DUP (NULLVAL); + ret->fhash = strdup (NULLVAL); if (!ret->fhash) { goto fail_ret; } @@ -642,7 +642,7 @@ static char *find_blob_hash(Rvc *rvc, const char *fname) { RvcBlob *b; r_list_foreach_prev (blobs, i, b) { if (!strcmp (b->fname, fname)) { - char *bhash = R_STR_DUP (b->fhash); + char *bhash = strdup (b->fhash); free_blobs (blobs); return bhash; } From 48f9f6a2f6cf005d5a41610f696f29054fee4b4d Mon Sep 17 00:00:00 2001 From: satk0 Date: Thu, 1 Aug 2024 13:41:31 +0200 Subject: [PATCH 11/31] Delete unused code --- libr/core/cmd.c | 1 - 1 file changed, 1 deletion(-) diff --git a/libr/core/cmd.c b/libr/core/cmd.c index c64c1cf90e00b..0cffd7ce54028 100644 --- a/libr/core/cmd.c +++ b/libr/core/cmd.c @@ -2522,7 +2522,6 @@ static int cmd_kuery(void *data, const char *input) { RLine *line = core->cons->line; if (!line->sdbshell_hist) { line->sdbshell_hist = r_list_newf (free); - r_list_append (line->sdbshell_hist, strdup ("\0")); } RList *sdb_hist = line->sdbshell_hist; r_line_set_hist_callback (line, &r_line_hist_sdb_up, &r_line_hist_sdb_down); From d929fae595e1a2fa93ac2437921309bdbe28d76d Mon Sep 17 00:00:00 2001 From: pancake Date: Fri, 2 Aug 2024 00:10:45 +0200 Subject: [PATCH 12/31] Apply suggestions from code review --- libr/arch/p/pyc/pyc_dis.c | 2 +- libr/bin/p/bin_lua.c | 2 +- libr/core/cmd_anal.inc.c | 2 +- libr/core/cmd_help.inc.c | 6 +++--- libr/core/panels.c | 4 ++-- libr/main/rax2.c | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/libr/arch/p/pyc/pyc_dis.c b/libr/arch/p/pyc/pyc_dis.c index 6e20259e0e8c3..0ab97c5acc7bc 100644 --- a/libr/arch/p/pyc/pyc_dis.c +++ b/libr/arch/p/pyc/pyc_dis.c @@ -167,7 +167,7 @@ static char *parse_arg(pyc_opcode_object *op, ut32 oparg, pyc_code_object *cobj, if (oparg < 0 || oparg >= CMP_OP_SIZE) { return NULL; } - arg = R_STR_DUP (cmp_op[oparg]); + arg = strdup (cmp_op[oparg]); } if (op->type & HASFREE) { if (!cellvars || !freevars) { diff --git a/libr/bin/p/bin_lua.c b/libr/bin/p/bin_lua.c index d2b0d21c86c63..c1660878a36d8 100644 --- a/libr/bin/p/bin_lua.c +++ b/libr/bin/p/bin_lua.c @@ -145,7 +145,7 @@ static void addString(const ut8 *buf, ut64 offset, ut64 length, ParseStruct *par } binstring->string = NULL; - if (length) { + if (length > 0) { binstring->string = r_str_ndup ((char *) buf + offset, length); } binstring->vaddr = binstring->paddr = offset; diff --git a/libr/core/cmd_anal.inc.c b/libr/core/cmd_anal.inc.c index d2130bd094768..5d51712d15238 100644 --- a/libr/core/cmd_anal.inc.c +++ b/libr/core/cmd_anal.inc.c @@ -10183,7 +10183,7 @@ static char *get_buf_asm(RCore *core, ut64 from, ut64 addr, RAnalFunction *fcn, buf_asm = r_print_colorize_opcode (core->print, str, core->cons->context->pal.reg, core->cons->context->pal.num, false, fcn ? fcn->addr : 0); } else { - buf_asm = R_STR_DUP (str); + buf_asm = strdup (str); } return buf_asm; } diff --git a/libr/core/cmd_help.inc.c b/libr/core/cmd_help.inc.c index e99b2e929c458..6976009893d1c 100644 --- a/libr/core/cmd_help.inc.c +++ b/libr/core/cmd_help.inc.c @@ -456,8 +456,8 @@ static char *filterFlags(RCore *core, const char *msg) { end = strchr (dollar + 2, '}'); if (end) { word = NULL; - if (end-dollar-2) { - word = r_str_ndup (dollar+2, end-dollar-2); + if (end - dollar - 2 > 0) { + word = r_str_ndup (dollar + 2, end - dollar - 2); } end++; } else { @@ -475,7 +475,7 @@ static char *filterFlags(RCore *core, const char *msg) { end = dollar + strlen (dollar); } word = NULL; - if (end-dollar-1) { + if (end - dollar - 1 > 0) { word = r_str_ndup (dollar+1, end-dollar-1); } } diff --git a/libr/core/panels.c b/libr/core/panels.c index f11c2ef247d92..6cdfb9598ca10 100644 --- a/libr/core/panels.c +++ b/libr/core/panels.c @@ -627,7 +627,7 @@ static void __set_decompiler_cache(RCore *core, char *s) { } 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); + sdb_ptr_set (sdb, r_num_as_string (NULL, func->addr, false), strdup (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, strdup (pdc_now), sdb, 0); @@ -5236,7 +5236,7 @@ static void __add_menu(RCore *core, const char *parent, const char *name, RPanel } item->n_sub = 0; item->selectedIndex = 0; - item->name = name ? R_STR_DUP (name) : NULL; + item->name = R_STR_DUP (name); item->sub = NULL; item->cb = cb; item->p = R_NEW0 (RPanel); diff --git a/libr/main/rax2.c b/libr/main/rax2.c index af58185016804..e07aab28bb225 100644 --- a/libr/main/rax2.c +++ b/libr/main/rax2.c @@ -688,7 +688,7 @@ static bool rax(RNum *num, char *str, int len, int last, RaxActions *flags, RaxM } if (flags->octal2raw) { // -o char *modified_str = (*str == '0') - ? R_STR_DUP (str) + ? strdup (str) : r_str_newf ("0%s", str); const char *errstr = NULL; ut64 n = r_num_calc (num, modified_str, &errstr); From 1d99bd40e8bd312b3a757a7832368a6c9b60b299 Mon Sep 17 00:00:00 2001 From: satk0 Date: Fri, 2 Aug 2024 21:10:08 +0200 Subject: [PATCH 13/31] New macro to handle zero length --- libr/anal/var.c | 10 ++-------- libr/bin/p/bin_lua.c | 5 +---- libr/core/cmd_help.inc.c | 10 ++-------- libr/core/disasm.c | 5 +---- libr/core/panels.c | 10 ++-------- libr/include/r_util/r_str.h | 2 +- libr/util/file.c | 5 +---- libr/util/str.c | 10 ++-------- libr/util/strbuf.c | 5 +---- shlr/ar/ar.c | 5 +---- 10 files changed, 14 insertions(+), 53 deletions(-) diff --git a/libr/anal/var.c b/libr/anal/var.c index 183c8ca69e78a..91b335580c7af 100644 --- a/libr/anal/var.c +++ b/libr/anal/var.c @@ -334,10 +334,7 @@ R_API RList *r_anal_var_deserialize(const char *ser) { } nxt++; } - v->name = NULL; - if (i) { - v->name = r_str_ndup (ser, i); - } + v->name = R_STR_NDUP (ser, i); if (!v->name) { goto bad_serial; } @@ -348,10 +345,7 @@ R_API RList *r_anal_var_deserialize(const char *ser) { for (i = 0; *nxt && *nxt != ','; i++) { nxt++; } - v->type = NULL; - if (i) { - v->type = r_str_ndup (ser, i); - } + v->type = R_STR_NDUP (ser, i); if (!v->type) { goto bad_serial; } diff --git a/libr/bin/p/bin_lua.c b/libr/bin/p/bin_lua.c index c1660878a36d8..515402ec0c8ec 100644 --- a/libr/bin/p/bin_lua.c +++ b/libr/bin/p/bin_lua.c @@ -144,10 +144,7 @@ static void addString(const ut8 *buf, ut64 offset, ut64 length, ParseStruct *par return; } - binstring->string = NULL; - if (length > 0) { - binstring->string = r_str_ndup ((char *) buf + offset, length); - } + binstring->string = R_STR_NDUP ((char *) buf + offset, length); binstring->vaddr = binstring->paddr = offset; binstring->ordinal = 0; binstring->size = length; diff --git a/libr/core/cmd_help.inc.c b/libr/core/cmd_help.inc.c index 6976009893d1c..f5ad85e3a4589 100644 --- a/libr/core/cmd_help.inc.c +++ b/libr/core/cmd_help.inc.c @@ -455,10 +455,7 @@ static char *filterFlags(RCore *core, const char *msg) { // find } end = strchr (dollar + 2, '}'); if (end) { - word = NULL; - if (end - dollar - 2 > 0) { - word = r_str_ndup (dollar + 2, end - dollar - 2); - } + word = R_STR_NDUP (dollar + 2, end - dollar - 2); end++; } else { msg = dollar + 1; @@ -474,10 +471,7 @@ static char *filterFlags(RCore *core, const char *msg) { if (!end) { end = dollar + strlen (dollar); } - word = NULL; - if (end - dollar - 1 > 0) { - word = r_str_ndup (dollar+1, end-dollar-1); - } + word = R_STR_NDUP (dollar + 1, end - dollar - 1); } if (end && word) { ut64 val = r_num_math (core->num, word); diff --git a/libr/core/disasm.c b/libr/core/disasm.c index 6ba554f49392e..ba956ab216765 100644 --- a/libr/core/disasm.c +++ b/libr/core/disasm.c @@ -1283,10 +1283,7 @@ static void ds_build_op_str(RDisasmState *ds, bool print_color) { char **wc_array = r_str_argv (wcdata, &argc); for (i = 0; i < argc; i++) { bgcolor = strchr (wc_array[i], '\x1b'); - word = NULL; - if (bgcolor - wc_array[i]) { - word = r_str_ndup (wc_array[i], bgcolor - wc_array[i]); - } + word = R_STR_NDUP (wc_array[i], bgcolor - wc_array[i]); ds_highlight_word (ds, word, bgcolor); } } diff --git a/libr/core/panels.c b/libr/core/panels.c index 6cdfb9598ca10..614702752113d 100644 --- a/libr/core/panels.c +++ b/libr/core/panels.c @@ -3923,10 +3923,7 @@ static char *__get_word_from_canvas_for_menu(RCore *core, RPanels *panels, int x tmp++; i++; } - char *ret = NULL; - if (i - strlen (padding)) { - ret = r_str_ndup (pos += strlen (padding), i - strlen (padding)); - } + char *ret = R_STR_NDUP (pos += strlen (padding), i - strlen (padding)); if (!ret) { ret = strdup (pos); } @@ -6572,10 +6569,7 @@ static char *__parse_panels_config(const char *cfg, int len) { if (R_STR_ISEMPTY (cfg) || len < 2) { return NULL; } - char *tmp = NULL; - if (len + 1) { - tmp = r_str_ndup (cfg, len + 1); - } + char *tmp = R_STR_NDUP (cfg, len + 1); if (!tmp) { return NULL; } diff --git a/libr/include/r_util/r_str.h b/libr/include/r_util/r_str.h index bface5c64901a..a592e17a070c3 100644 --- a/libr/include/r_util/r_str.h +++ b/libr/include/r_util/r_str.h @@ -65,8 +65,8 @@ typedef struct r_charset_t { #define R_STR_ISEMPTY(x) (!(x) || !*(x)) #define R_STR_ISNOTEMPTY(x) ((x) && *(x)) -// XXX must deprecate #define R_STR_DUP(x) (((x) != NULL) ? strdup ((x)) : NULL) +#define R_STR_NDUP(x, len) ((len > 0) ? r_str_ndup (x, len) : NULL) #define r_str_array(x,y) ((y >= 0 && y < (sizeof (x) / sizeof (*(x))))?(x)[(y)]: "") R_API RCharset *r_charset_new(void); R_API void r_charset_free(RCharset *charset); diff --git a/libr/util/file.c b/libr/util/file.c index 2fedd6e729d12..2d0e42ff10111 100644 --- a/libr/util/file.c +++ b/libr/util/file.c @@ -1549,10 +1549,7 @@ R_API RList* r_file_glob(const char *_globbed_path, int maxdepth) { if (last_slash) { glob_ptr = last_slash + 1; if (globbed_path[0] == '~') { - char *rpath = NULL; - if (last_slash - globbed_path - 1) { - rpath = r_str_ndup (globbed_path + 2, last_slash - globbed_path - 1); - } + char *rpath = R_STR_NDUP (globbed_path + 2, last_slash - globbed_path - 1); path = r_file_home (r_str_get (rpath)); free (rpath); } else { diff --git a/libr/util/str.c b/libr/util/str.c index ea6aa7773ce9c..d6c3480bac05c 100644 --- a/libr/util/str.c +++ b/libr/util/str.c @@ -672,10 +672,7 @@ R_API char *r_str_trunc_ellipsis(const char *str, int len) { if (strlen (str) < len) { return strdup (str); } - char *buf = NULL; - if (len > 0) { - buf = r_str_ndup (str, len); - } + char *buf = R_STR_NDUP (str, len); if (buf && len > 4) { strcpy (buf + len - 4, "..."); } @@ -820,10 +817,7 @@ R_API char *r_str_prepend(char *ptr, const char *string) { R_API char *r_str_appendlen(char *ptr, const char *string, int slen) { r_return_val_if_fail (string, NULL); - char *msg = NULL; - if (slen) { - msg = r_str_ndup (string, slen); - } + char *msg = R_STR_NDUP (string, slen); char *ret = r_str_append (ptr, msg); free (msg); return ret; diff --git a/libr/util/strbuf.c b/libr/util/strbuf.c index a681b7883ca2c..05c9020f7ebaa 100644 --- a/libr/util/strbuf.c +++ b/libr/util/strbuf.c @@ -130,10 +130,7 @@ R_API bool r_strbuf_slice(RStrBuf *sb, int from, int len) { const char *s = r_strbuf_get (sb); 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) { - r = r_str_ndup (fr, to - fr); - } + char *r = R_STR_NDUP (fr, to - fr); r_strbuf_fini (sb); r_strbuf_init (sb); if (from >= len) { diff --git a/shlr/ar/ar.c b/shlr/ar/ar.c index 1b30afae197ec..bf34b6c97a7be 100644 --- a/shlr/ar/ar.c +++ b/shlr/ar/ar.c @@ -64,10 +64,7 @@ static char *name_from_table(ut64 off, filetable *tbl) { if (i == off) { return NULL; } - char *res = NULL; - if (i - off - 1 > 0) { - res = r_str_ndup (buf + off, i - off - 1); - } + char *res = R_STR_NDUP (buf + off, i - off - 1); return res; } From 94ad228daf9379e1f7f87c2bede1941e46375a69 Mon Sep 17 00:00:00 2001 From: satk0 <54475808+satk0@users.noreply.github.com> Date: Fri, 2 Aug 2024 21:42:26 +0200 Subject: [PATCH 14/31] Update libr/include/r_util/r_str.h according to the review Co-authored-by: pancake --- libr/include/r_util/r_str.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libr/include/r_util/r_str.h b/libr/include/r_util/r_str.h index a592e17a070c3..9d1d625451f0d 100644 --- a/libr/include/r_util/r_str.h +++ b/libr/include/r_util/r_str.h @@ -66,7 +66,7 @@ typedef struct r_charset_t { #define R_STR_ISEMPTY(x) (!(x) || !*(x)) #define R_STR_ISNOTEMPTY(x) ((x) && *(x)) #define R_STR_DUP(x) (((x) != NULL) ? strdup ((x)) : NULL) -#define R_STR_NDUP(x, len) ((len > 0) ? r_str_ndup (x, len) : NULL) +#define R_STR_NDUP(x, len) ({ int _len = (len); ((_len) > 0) ? r_str_ndup ((x), (_len)) : NULL; }) #define r_str_array(x,y) ((y >= 0 && y < (sizeof (x) / sizeof (*(x))))?(x)[(y)]: "") R_API RCharset *r_charset_new(void); R_API void r_charset_free(RCharset *charset); From 0a2e7b702e21953dddb91f3ce1241c497d0923a0 Mon Sep 17 00:00:00 2001 From: pancake Date: Fri, 2 Aug 2024 22:42:45 +0200 Subject: [PATCH 15/31] Update libr/include/r_util/r_str.h --- libr/include/r_util/r_str.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libr/include/r_util/r_str.h b/libr/include/r_util/r_str.h index 9d1d625451f0d..6114f96c56449 100644 --- a/libr/include/r_util/r_str.h +++ b/libr/include/r_util/r_str.h @@ -66,7 +66,7 @@ typedef struct r_charset_t { #define R_STR_ISEMPTY(x) (!(x) || !*(x)) #define R_STR_ISNOTEMPTY(x) ((x) && *(x)) #define R_STR_DUP(x) (((x) != NULL) ? strdup ((x)) : NULL) -#define R_STR_NDUP(x, len) ({ int _len = (len); ((_len) > 0) ? r_str_ndup ((x), (_len)) : NULL; }) +static inline R_STR_NDUP(const char *x, int len) { int _len = len; (_len > 0) ? r_str_ndup (x, _len) : NULL; } #define r_str_array(x,y) ((y >= 0 && y < (sizeof (x) / sizeof (*(x))))?(x)[(y)]: "") R_API RCharset *r_charset_new(void); R_API void r_charset_free(RCharset *charset); From e9d0b752c79a6084e501c338874747697f4939e1 Mon Sep 17 00:00:00 2001 From: pancake Date: Fri, 2 Aug 2024 22:43:10 +0200 Subject: [PATCH 16/31] Update libr/include/r_util/r_str.h --- libr/include/r_util/r_str.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libr/include/r_util/r_str.h b/libr/include/r_util/r_str.h index 6114f96c56449..5dee527883072 100644 --- a/libr/include/r_util/r_str.h +++ b/libr/include/r_util/r_str.h @@ -66,7 +66,7 @@ typedef struct r_charset_t { #define R_STR_ISEMPTY(x) (!(x) || !*(x)) #define R_STR_ISNOTEMPTY(x) ((x) && *(x)) #define R_STR_DUP(x) (((x) != NULL) ? strdup ((x)) : NULL) -static inline R_STR_NDUP(const char *x, int len) { int _len = len; (_len > 0) ? r_str_ndup (x, _len) : NULL; } +static inline char *R_STR_NDUP(const char *x, int len) { int _len = len; (_len > 0) ? r_str_ndup (x, _len) : NULL; } #define r_str_array(x,y) ((y >= 0 && y < (sizeof (x) / sizeof (*(x))))?(x)[(y)]: "") R_API RCharset *r_charset_new(void); R_API void r_charset_free(RCharset *charset); From e4e50d072b4bceed277ac0984739173d0511680f Mon Sep 17 00:00:00 2001 From: pancake Date: Fri, 2 Aug 2024 22:44:20 +0200 Subject: [PATCH 17/31] Update libr/include/r_util/r_str.h --- libr/include/r_util/r_str.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libr/include/r_util/r_str.h b/libr/include/r_util/r_str.h index 5dee527883072..7aa5f476a0774 100644 --- a/libr/include/r_util/r_str.h +++ b/libr/include/r_util/r_str.h @@ -66,7 +66,9 @@ typedef struct r_charset_t { #define R_STR_ISEMPTY(x) (!(x) || !*(x)) #define R_STR_ISNOTEMPTY(x) ((x) && *(x)) #define R_STR_DUP(x) (((x) != NULL) ? strdup ((x)) : NULL) -static inline char *R_STR_NDUP(const char *x, int len) { int _len = len; (_len > 0) ? r_str_ndup (x, _len) : NULL; } +static inline char *R_STR_NDUP(R_NULLABLE const char *x, int len) { + return (x && len > 0) ? r_str_ndup (x, len) : NULL; +} #define r_str_array(x,y) ((y >= 0 && y < (sizeof (x) / sizeof (*(x))))?(x)[(y)]: "") R_API RCharset *r_charset_new(void); R_API void r_charset_free(RCharset *charset); From 94e0dd1bbdfbc89cba5ae3e225bc0e5bf0fcd02c Mon Sep 17 00:00:00 2001 From: satk0 Date: Sat, 3 Aug 2024 00:08:45 +0200 Subject: [PATCH 18/31] Fix R_STR_NDUP macro to make msvc satisfied --- libr/include/r_util/r_str.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libr/include/r_util/r_str.h b/libr/include/r_util/r_str.h index 7aa5f476a0774..b3940d593030d 100644 --- a/libr/include/r_util/r_str.h +++ b/libr/include/r_util/r_str.h @@ -66,9 +66,6 @@ typedef struct r_charset_t { #define R_STR_ISEMPTY(x) (!(x) || !*(x)) #define R_STR_ISNOTEMPTY(x) ((x) && *(x)) #define R_STR_DUP(x) (((x) != NULL) ? strdup ((x)) : NULL) -static inline char *R_STR_NDUP(R_NULLABLE const char *x, int len) { - return (x && len > 0) ? r_str_ndup (x, len) : NULL; -} #define r_str_array(x,y) ((y >= 0 && y < (sizeof (x) / sizeof (*(x))))?(x)[(y)]: "") R_API RCharset *r_charset_new(void); R_API void r_charset_free(RCharset *charset); @@ -303,6 +300,9 @@ R_UNUSED static const char *r_str_skip_prefix(const char *str, const char *prefi } return str; } +static inline char *R_STR_NDUP(R_NULLABLE const char *x, int len) { + int _len = len; return (_len > 0) ? r_str_ndup (x, _len) : NULL; +} R_API bool r_str_endswith(const char *str, const char *needle); R_API bool r_str_isnumber(const char *str); R_API const char *r_str_last(const char *in, const char *ch); From 2212961b0759a49fef288cb5a0d1b9047c5704bc Mon Sep 17 00:00:00 2001 From: satk0 Date: Sat, 3 Aug 2024 12:49:33 +0200 Subject: [PATCH 19/31] Add test for r_str_ndup 0 len --- test/unit/test_str.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/unit/test_str.c b/test/unit/test_str.c index aac979e735652..e7d5e616c07ec 100644 --- a/test/unit/test_str.c +++ b/test/unit/test_str.c @@ -671,6 +671,15 @@ bool test_r_mem_to_binstring(void) { mu_end; } +bool test_r_str_ndup_zero_len (void) { + char str[] = "deadbeef"; + + mu_assert_null (R_STR_NDUP (str, 0), "uppercase yields NULL"); + mu_assert_streq (r_str_ndup (str, 0), "", "lowercase yields empty string"); + + mu_end; +} + bool all_tests(void) { mu_run_test (test_r_str_wrap); mu_run_test (test_r_str_newf); @@ -707,6 +716,7 @@ bool all_tests(void) { mu_run_test (test_r_str_tok_r); mu_run_test (test_r_mem_from_binstring); mu_run_test (test_r_mem_to_binstring); + mu_run_test (test_r_str_ndup_zero_len); return tests_passed != tests_run; } From d2e9e3c0b52d92c05fbc4278b394e0a20e0a4e37 Mon Sep 17 00:00:00 2001 From: satk0 <54475808+satk0@users.noreply.github.com> Date: Sat, 3 Aug 2024 17:01:15 +0200 Subject: [PATCH 20/31] Update libr/bin/format/xnu/r_cf_dict.c Co-authored-by: pancake --- libr/bin/format/xnu/r_cf_dict.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libr/bin/format/xnu/r_cf_dict.c b/libr/bin/format/xnu/r_cf_dict.c index 039fa5df37b4c..a1686885839ca 100644 --- a/libr/bin/format/xnu/r_cf_dict.c +++ b/libr/bin/format/xnu/r_cf_dict.c @@ -673,7 +673,7 @@ static RCFValue *r_cf_value_clone(RCFValue *value) { RListIter *iter; RCFKeyValue *item; r_list_foreach (((RCFValueDict *)value)->pairs, iter, item) { - char *key = R_STR_DUP (item->key); + char *key = strdup (item->key); if (key) { RCFValue *clone = r_cf_value_clone (item->value); if (clone) { From e57bd7c73d3207550df802d7240d08e34e333161 Mon Sep 17 00:00:00 2001 From: satk0 <54475808+satk0@users.noreply.github.com> Date: Sat, 3 Aug 2024 17:01:56 +0200 Subject: [PATCH 21/31] Update libr/bin/p/bin_lua.c Co-authored-by: pancake --- libr/bin/p/bin_lua.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libr/bin/p/bin_lua.c b/libr/bin/p/bin_lua.c index 515402ec0c8ec..a18c0c33fa671 100644 --- a/libr/bin/p/bin_lua.c +++ b/libr/bin/p/bin_lua.c @@ -144,7 +144,7 @@ static void addString(const ut8 *buf, ut64 offset, ut64 length, ParseStruct *par return; } - binstring->string = R_STR_NDUP ((char *) buf + offset, length); + binstring->string = r_str_ndup ((char *) buf + offset, length); binstring->vaddr = binstring->paddr = offset; binstring->ordinal = 0; binstring->size = length; From c283aa8e81638c5729c1cc873c9cdcc03575f591 Mon Sep 17 00:00:00 2001 From: satk0 <54475808+satk0@users.noreply.github.com> Date: Sat, 3 Aug 2024 17:02:34 +0200 Subject: [PATCH 22/31] Update libr/core/canal.c Co-authored-by: pancake --- libr/core/canal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libr/core/canal.c b/libr/core/canal.c index c9f40df8e87cf..0e70b2c28fadc 100644 --- a/libr/core/canal.c +++ b/libr/core/canal.c @@ -2472,7 +2472,7 @@ static void add_single_addr_xrefs(RCore *core, ut64 addr, RGraph *graph) { continue; } RFlagItem *item = r_flag_get_i (core->flags, ref->addr); - char *src = item? R_STR_DUP (item->name): r_str_newf ("0x%08" PFMT64x, ref->addr); + char *src = item? strdup (item->name): r_str_newf ("0x%08" PFMT64x, ref->addr); RGraphNode *reference_from = r_graph_add_node_info (graph, src, NULL, ref->addr); free (src); r_graph_add_edge (graph, reference_from, curr_node); From 512a5fe6ef1cbf551c83faa5094b63e6f2f843c0 Mon Sep 17 00:00:00 2001 From: satk0 <54475808+satk0@users.noreply.github.com> Date: Sat, 3 Aug 2024 17:03:06 +0200 Subject: [PATCH 23/31] Update libr/core/cmd_help.inc.c Co-authored-by: pancake --- libr/core/cmd_help.inc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libr/core/cmd_help.inc.c b/libr/core/cmd_help.inc.c index f5ad85e3a4589..9a204ea953f72 100644 --- a/libr/core/cmd_help.inc.c +++ b/libr/core/cmd_help.inc.c @@ -455,7 +455,7 @@ static char *filterFlags(RCore *core, const char *msg) { // find } end = strchr (dollar + 2, '}'); if (end) { - word = R_STR_NDUP (dollar + 2, end - dollar - 2); + word = r_str_ndup (dollar + 2, end - dollar - 2); end++; } else { msg = dollar + 1; From 8f5fd8a1a714da022a951d93afe463b04b40864d Mon Sep 17 00:00:00 2001 From: satk0 <54475808+satk0@users.noreply.github.com> Date: Sat, 3 Aug 2024 17:03:38 +0200 Subject: [PATCH 24/31] Update libr/core/cmd_help.inc.c Co-authored-by: pancake --- libr/core/cmd_help.inc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libr/core/cmd_help.inc.c b/libr/core/cmd_help.inc.c index 9a204ea953f72..5544dcfe574fb 100644 --- a/libr/core/cmd_help.inc.c +++ b/libr/core/cmd_help.inc.c @@ -471,7 +471,7 @@ static char *filterFlags(RCore *core, const char *msg) { if (!end) { end = dollar + strlen (dollar); } - word = R_STR_NDUP (dollar + 1, end - dollar - 1); + word = r_str_ndup (dollar + 1, end - dollar - 1); } if (end && word) { ut64 val = r_num_math (core->num, word); From d1c4175f999f9954e9b060803d4f3b03ed370778 Mon Sep 17 00:00:00 2001 From: satk0 <54475808+satk0@users.noreply.github.com> Date: Sat, 3 Aug 2024 17:04:27 +0200 Subject: [PATCH 25/31] Update libr/core/cmd_zign.inc.c Co-authored-by: pancake --- libr/core/cmd_zign.inc.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libr/core/cmd_zign.inc.c b/libr/core/cmd_zign.inc.c index 40821bcbdfb2a..94a7d8aace351 100644 --- a/libr/core/cmd_zign.inc.c +++ b/libr/core/cmd_zign.inc.c @@ -842,7 +842,7 @@ static double get_zb_threshold(RCore *core) { static bool bestmatch_fcn(RCore *core, const char *input, bool json) { r_return_val_if_fail (input && core, false); - char *argv = R_STR_DUP (input); + char *argv = strdup (input); if (!argv) { return false; } From 48ecfd8b53e560c3285975e016343422322dcf93 Mon Sep 17 00:00:00 2001 From: satk0 <54475808+satk0@users.noreply.github.com> Date: Sat, 3 Aug 2024 17:05:38 +0200 Subject: [PATCH 26/31] Update libr/core/core.c Co-authored-by: pancake --- libr/core/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libr/core/core.c b/libr/core/core.c index 7e69fdf476252..7c2dbeabc050a 100644 --- a/libr/core/core.c +++ b/libr/core/core.c @@ -1185,7 +1185,7 @@ static void autocomplete_ms_path(RLineCompletion *completion, RCore *core, const char *pwd = strdup (core->rfs->cwd? (const char *)core->rfs->cwd: "."); int n = 0; RFSFile *file; - char *lpath = R_STR_DUP (path); + char *lpath = strdup (path); char *p = (char *)r_str_last (lpath, R_SYS_DIR); if (p) { *p = 0; From 34e5b92a10c6ced563207c230bc22bb436af4bb2 Mon Sep 17 00:00:00 2001 From: satk0 <54475808+satk0@users.noreply.github.com> Date: Sat, 3 Aug 2024 17:06:17 +0200 Subject: [PATCH 27/31] Update libr/core/core.c Co-authored-by: pancake --- libr/core/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libr/core/core.c b/libr/core/core.c index 7c2dbeabc050a..039825272bbe6 100644 --- a/libr/core/core.c +++ b/libr/core/core.c @@ -1372,7 +1372,7 @@ static void autocomplete_process_path(RLineCompletion *completion, const char *s #endif dirname = r_str_newf (fmt, R_SYS_DIR, lpath, R_SYS_DIR); } - basename = R_STR_DUP (p + 1); + basename = strdup (p + 1); } else { // xxx dirname = r_str_newf (".%s", R_SYS_DIR); basename = R_STR_DUP (lpath); From dd1a6b126c2229ceb338072e1356eadbc47f7197 Mon Sep 17 00:00:00 2001 From: satk0 <54475808+satk0@users.noreply.github.com> Date: Sat, 3 Aug 2024 17:06:45 +0200 Subject: [PATCH 28/31] Update libr/core/core.c Co-authored-by: pancake --- libr/core/core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libr/core/core.c b/libr/core/core.c index 039825272bbe6..b4fb5e3689c58 100644 --- a/libr/core/core.c +++ b/libr/core/core.c @@ -1375,7 +1375,7 @@ static void autocomplete_process_path(RLineCompletion *completion, const char *s basename = strdup (p + 1); } else { // xxx dirname = r_str_newf (".%s", R_SYS_DIR); - basename = R_STR_DUP (lpath); + basename = strdup (lpath); } if (!dirname || !basename) { From 1f658c656841b7acb3f46749e320f1b4e8e48861 Mon Sep 17 00:00:00 2001 From: pancake Date: Sun, 4 Aug 2024 11:40:41 +0200 Subject: [PATCH 29/31] Apply suggestions from code review --- libr/lang/p/lib.c | 4 ++-- libr/util/file.c | 5 +---- libr/util/rvc_git.c | 2 +- libr/util/str.c | 4 ++-- shlr/ar/ar.c | 2 +- 5 files changed, 7 insertions(+), 10 deletions(-) diff --git a/libr/lang/p/lib.c b/libr/lang/p/lib.c index 2022c4dafba18..761f03951c670 100644 --- a/libr/lang/p/lib.c +++ b/libr/lang/p/lib.c @@ -3,9 +3,9 @@ #include static bool lang_lib_file_run(RLangSession *user, const char *file) { - char *libpath; + char *libpath = R_STR_DUP (file); void *lib; - if (!(libpath = R_STR_DUP (file))) { + if (!libpath) { return false; } if (!r_str_startswith (libpath, "/") && !r_str_startswith (libpath, "./")) { diff --git a/libr/util/file.c b/libr/util/file.c index 2d0e42ff10111..86a39fa1935d7 100644 --- a/libr/util/file.c +++ b/libr/util/file.c @@ -1553,10 +1553,7 @@ R_API RList* r_file_glob(const char *_globbed_path, int maxdepth) { path = r_file_home (r_str_get (rpath)); free (rpath); } else { - path = NULL; - if (last_slash - globbed_path + 1) { - path = r_str_ndup (globbed_path, last_slash - globbed_path + 1); - } + path = R_STR_NDUP (globbed_path, last_slash - globbed_path + 1); } } else { glob_ptr = globbed_path; diff --git a/libr/util/rvc_git.c b/libr/util/rvc_git.c index dd4866375a066..cb80b74e300b3 100644 --- a/libr/util/rvc_git.c +++ b/libr/util/rvc_git.c @@ -182,7 +182,7 @@ R_API RList *branches_git(Rvc *rvc) { char *name; r_list_foreach (ret, iter, name) { if (*(char *)iter->data == '*') { - iter->data = R_STR_DUP (name + 2); + iter->data = strdup (name + 2); free (name); } diff --git a/libr/util/str.c b/libr/util/str.c index d6c3480bac05c..9532a42a69adb 100644 --- a/libr/util/str.c +++ b/libr/util/str.c @@ -672,7 +672,7 @@ R_API char *r_str_trunc_ellipsis(const char *str, int len) { if (strlen (str) < len) { return strdup (str); } - char *buf = R_STR_NDUP (str, len); + char *buf = r_str_ndup (str, len); if (buf && len > 4) { strcpy (buf + len - 4, "..."); } @@ -817,7 +817,7 @@ R_API char *r_str_prepend(char *ptr, const char *string) { R_API char *r_str_appendlen(char *ptr, const char *string, int slen) { r_return_val_if_fail (string, NULL); - char *msg = R_STR_NDUP (string, slen); + char *msg = r_str_ndup (string, slen); char *ret = r_str_append (ptr, msg); free (msg); return ret; diff --git a/shlr/ar/ar.c b/shlr/ar/ar.c index bf34b6c97a7be..896ee4b16961d 100644 --- a/shlr/ar/ar.c +++ b/shlr/ar/ar.c @@ -64,7 +64,7 @@ static char *name_from_table(ut64 off, filetable *tbl) { if (i == off) { return NULL; } - char *res = R_STR_NDUP (buf + off, i - off - 1); + return R_STR_NDUP (buf + off, i - off - 1); return res; } From 3599ef7d8c14dadbd0b953e8d76d8f101bf21b20 Mon Sep 17 00:00:00 2001 From: pancake Date: Sun, 4 Aug 2024 11:48:46 +0200 Subject: [PATCH 30/31] Update shlr/ar/ar.c --- shlr/ar/ar.c | 1 - 1 file changed, 1 deletion(-) diff --git a/shlr/ar/ar.c b/shlr/ar/ar.c index 896ee4b16961d..24172012206cb 100644 --- a/shlr/ar/ar.c +++ b/shlr/ar/ar.c @@ -65,7 +65,6 @@ static char *name_from_table(ut64 off, filetable *tbl) { return NULL; } return R_STR_NDUP (buf + off, i - off - 1); - return res; } #define VERIFY_AR_NUM_FIELD(x, s) \ From 541d12c2861a160df168277d2109662cb4e62d6e Mon Sep 17 00:00:00 2001 From: pancake Date: Sun, 4 Aug 2024 12:07:29 +0200 Subject: [PATCH 31/31] Update libr/util/str.c --- libr/util/str.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libr/util/str.c b/libr/util/str.c index 9532a42a69adb..6378de5e0de96 100644 --- a/libr/util/str.c +++ b/libr/util/str.c @@ -817,7 +817,7 @@ R_API char *r_str_prepend(char *ptr, const char *string) { R_API char *r_str_appendlen(char *ptr, const char *string, int slen) { r_return_val_if_fail (string, NULL); - char *msg = r_str_ndup (string, slen); + char *msg = R_STR_NDUP (string, slen); // only fails for token.c char *ret = r_str_append (ptr, msg); free (msg); return ret;