Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert rz_str_new to rz_str_dup #4178

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions librz/analysis/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ static RzAnalysisClassErr rz_analysis_class_add_attr_unique(RzAnalysis *analysis

static char *flagname_method(const char *class_name, const char *meth_name) {
if (rz_str_startswith(meth_name, "method.")) {
return rz_str_new(meth_name);
return rz_str_dup(meth_name);
}
return flagname_attr("method", class_name, meth_name);
}
Expand All @@ -628,9 +628,9 @@ RZ_API void rz_analysis_class_method_recover(RzAnalysis *analysis, RzBinClass *c
method.addr = sym->vaddr;
method.vtable_offset = -1;
RzAnalysisFunction *fcn = rz_analysis_get_function_at(analysis, sym->vaddr);
char *method_name = rz_str_new(sym->name);
char *method_name = rz_str_dup(sym->name);
rz_str_split(method_name, '(');
method.name = fcn ? rz_str_new(fcn->name) : rz_str_new(method_name);
method.name = fcn ? rz_str_dup(fcn->name) : rz_str_dup(method_name);
// this replace is required due SDB using commas to split the stored data.
// some c++ function names might have templates like foo<char, int>()
// which breaks the decoding from the SDB data
Expand Down Expand Up @@ -675,11 +675,11 @@ RZ_API RzAnalysisClassErr rz_analysis_class_method_get_by_addr(RzAnalysis *analy
RzAnalysisMethod *meth;
rz_vector_foreach(vec, meth) {
if (meth->addr == addr) {
method->name = rz_str_new(meth->name);
method->name = rz_str_dup(meth->name);
method->addr = meth->addr;
method->method_type = meth->method_type;
method->vtable_offset = meth->vtable_offset;
method->real_name = rz_str_new(meth->real_name);
method->real_name = rz_str_dup(meth->real_name);
rz_vector_free(vec);
return RZ_ANALYSIS_CLASS_ERR_SUCCESS;
}
Expand Down Expand Up @@ -725,7 +725,7 @@ RZ_API RzAnalysisClassErr rz_analysis_class_method_get(RzAnalysis *analysis, con
}
sdb_anext(cur, NULL);

meth->real_name = rz_str_new(cur);
meth->real_name = rz_str_dup(cur);
// this replace is required due SDB using commas to split the stored data.
// some c++ function names might have templates like foo<char, int>()
// which breaks the decoding from the SDB data
Expand Down Expand Up @@ -803,7 +803,7 @@ RZ_API RzAnalysisClassErr rz_analysis_class_method_set(RzAnalysis *analysis, con
RZ_API RzAnalysisClassErr rz_analysis_class_method_rename(RzAnalysis *analysis, const char *class_name, const char *old_meth_name, const char *new_meth_name) {
RzAnalysisMethod meth;
if (rz_analysis_class_method_get(analysis, class_name, old_meth_name, &meth) == RZ_ANALYSIS_CLASS_ERR_SUCCESS) {
meth.real_name = rz_str_new(new_meth_name);
meth.real_name = rz_str_dup(new_meth_name);
rz_analysis_class_method_set(analysis, class_name, &meth);
rz_analysis_class_method_fini(&meth);
}
Expand Down
6 changes: 3 additions & 3 deletions librz/analysis/dwarf_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -1033,7 +1033,7 @@ static void RzType_from_base_type(RzType *t, RzBaseType *b) {
rz_return_if_fail(t && b);
t->kind = RZ_TYPE_KIND_IDENTIFIER;
free(t->identifier.name);
t->identifier.name = rz_str_new(b->name);
t->identifier.name = rz_str_dup(b->name);
switch (b->kind) {
case RZ_BASE_TYPE_KIND_STRUCT:
t->identifier.kind = RZ_TYPE_IDENTIFIER_KIND_STRUCT;
Expand Down Expand Up @@ -1268,7 +1268,7 @@ static RzType *type_parse_from_abstract_origin(Context *ctx, ut64 offset, char *
}
const char *prefer_name = select_name(NULL, linkname, name, ctx->unit->language);
if (prefer_name && name_out) {
*name_out = rz_str_new(prefer_name);
*name_out = rz_str_dup(prefer_name);
}
beach:
free(name);
Expand Down Expand Up @@ -2004,7 +2004,7 @@ static bool store_base_type(void *u, const void *k, const void *v) {
}
free(a->type->identifier.name);
char *newname = rz_str_newf("%s_0", name);
a->type->identifier.name = rz_str_new(newname);
a->type->identifier.name = rz_str_dup(newname);
update_base_type(analysis->typedb, a);

db_save_renamed(analysis->typedb, rz_base_type_clone(b), newname);
Expand Down
6 changes: 3 additions & 3 deletions librz/analysis/pdb_process.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ static RzType *type_new_identify(const char *name, RzTypeIdentifierKind k) {
return NULL;
}
t->kind = RZ_TYPE_KIND_IDENTIFIER;
t->identifier.name = rz_str_new(name);
t->identifier.name = rz_str_dup(name);
t->identifier.kind = k;
return t;
}
Expand Down Expand Up @@ -341,7 +341,7 @@ static RzTypeStructMember *class_member_parse(
}
case TpiKind_NESTTYPE: {
name = rz_bin_pdb_get_type_name(t);
type = nest_parse(typedb, stream, t, rz_str_new(name));
type = nest_parse(typedb, stream, t, rz_str_dup(name));
break;
}
case TpiKind_VBCLASS:
Expand Down Expand Up @@ -527,7 +527,7 @@ static RzTypeUnionMember *union_member_parse(const RzTypeDB *typedb, RzPdbTpiStr
}
case TpiKind_NESTTYPE: {
name = rz_bin_pdb_get_type_name(type_info);
type = nest_parse(typedb, stream, type_info, rz_str_new(name));
type = nest_parse(typedb, stream, type_info, rz_str_dup(name));
break;
}
default:
Expand Down
8 changes: 4 additions & 4 deletions librz/analysis/rtti_itanium.c
Original file line number Diff line number Diff line change
Expand Up @@ -776,16 +776,16 @@ static void recovery_apply_vtable(RVTableContext *context, const char *class_nam
meth.addr = vmeth->addr;
meth.vtable_offset = vmeth->vtable_offset;
RzAnalysisFunction *fcn = rz_analysis_get_function_at(context->analysis, vmeth->addr);
meth.name = fcn ? rz_str_new(fcn->name) : rz_str_newf("virtual_%" PFMT64d, meth.vtable_offset);
meth.name = fcn ? rz_str_dup(fcn->name) : rz_str_newf("virtual_%" PFMT64d, meth.vtable_offset);
// Temporarily set as attr name
meth.real_name = fcn ? rz_str_new(fcn->name) : rz_str_newf("virtual_%" PFMT64d, meth.vtable_offset);
meth.real_name = fcn ? rz_str_dup(fcn->name) : rz_str_newf("virtual_%" PFMT64d, meth.vtable_offset);
meth.method_type = RZ_ANALYSIS_CLASS_METHOD_VIRTUAL;
} else {
RzAnalysisMethod exist_meth;
if (rz_analysis_class_method_get_by_addr(context->analysis, class_name, vmeth->addr, &exist_meth) == RZ_ANALYSIS_CLASS_ERR_SUCCESS) {
meth.addr = vmeth->addr;
meth.name = rz_str_new(exist_meth.name);
meth.real_name = rz_str_new(exist_meth.real_name);
meth.name = rz_str_dup(exist_meth.name);
meth.real_name = rz_str_dup(exist_meth.real_name);
meth.vtable_offset = vmeth->vtable_offset;
meth.method_type = RZ_ANALYSIS_CLASS_METHOD_VIRTUAL;
rz_analysis_class_method_fini(&exist_meth);
Expand Down
8 changes: 4 additions & 4 deletions librz/analysis/rtti_msvc.c
Original file line number Diff line number Diff line change
Expand Up @@ -830,16 +830,16 @@ static void recovery_apply_vtable(RVTableContext *context, const char *class_nam
meth.addr = vmeth->addr;
meth.vtable_offset = vmeth->vtable_offset;
RzAnalysisFunction *fcn = rz_analysis_get_function_at(context->analysis, vmeth->addr);
meth.name = fcn ? rz_str_new(fcn->name) : rz_str_newf("virtual_%" PFMT64d, meth.vtable_offset);
meth.name = fcn ? rz_str_dup(fcn->name) : rz_str_newf("virtual_%" PFMT64d, meth.vtable_offset);
// Temporarily set as attr name
meth.real_name = fcn ? rz_str_new(fcn->name) : rz_str_newf("virtual_%" PFMT64d, meth.vtable_offset);
meth.real_name = fcn ? rz_str_dup(fcn->name) : rz_str_newf("virtual_%" PFMT64d, meth.vtable_offset);
meth.method_type = RZ_ANALYSIS_CLASS_METHOD_VIRTUAL;
} else {
RzAnalysisMethod exist_meth;
if (rz_analysis_class_method_get_by_addr(context->analysis, class_name, vmeth->addr, &exist_meth) == RZ_ANALYSIS_CLASS_ERR_SUCCESS) {
meth.addr = vmeth->addr;
meth.name = rz_str_new(exist_meth.name);
meth.real_name = rz_str_new(exist_meth.real_name);
meth.name = rz_str_dup(exist_meth.name);
meth.real_name = rz_str_dup(exist_meth.real_name);
meth.vtable_offset = vmeth->vtable_offset;
meth.method_type = RZ_ANALYSIS_CLASS_METHOD_VIRTUAL;
rz_analysis_class_method_fini(&exist_meth);
Expand Down
2 changes: 1 addition & 1 deletion librz/analysis/value.c
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ RZ_API int rz_analysis_value_set_ut64(RzAnalysis *analysis, RzAnalysisValue *val
RZ_API char *rz_analysis_value_to_string(RzAnalysisValue *value) {
char *out = NULL;
if (value) {
out = rz_str_new("");
out = rz_str_dup("");
if (!value->base && !value->reg) {
if (value->imm != -1LL) {
out = rz_str_appendf(out, "0x%" PFMT64x, value->imm);
Expand Down
2 changes: 1 addition & 1 deletion librz/asm/aop.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ RZ_API void rz_asm_op_setf_asm(RZ_NONNULL RzAsmOp *op, RZ_NONNULL const char *fm

RZ_API int rz_asm_op_set_hex(RZ_NONNULL RzAsmOp *op, RZ_NONNULL const char *str) {
rz_return_val_if_fail(op && str, 0);
ut8 *bin = (ut8 *)rz_str_new(str);
ut8 *bin = (ut8 *)rz_str_dup(str);
if (!bin) {
return 0;
}
Expand Down
2 changes: 1 addition & 1 deletion librz/asm/arch/8051/8051_disas.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ static char *rz_8051_disas(ut64 pc, const ut8 *buf, int len, int *olen) {
// op @Ri; op Rn
disasm = rz_str_newf(name, buf[0] & mask);
} else {
disasm = rz_str_new(name);
disasm = rz_str_dup(name);
}
break;
case 2:
Expand Down
2 changes: 1 addition & 1 deletion librz/asm/arch/luac/v53/disassembly_53.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ int lua53_disasm(RzAsmOp *op, const ut8 *buf, int len, LuaOpNameList opnames) {
asm_string = luaop_new_str_1arg(opnames[opcode], ax);
break;
default:
asm_string = rz_str_new("invalid");
asm_string = rz_str_dup("invalid");
break;
}

Expand Down
8 changes: 4 additions & 4 deletions librz/asm/arch/pyc/opcode_arg_fmt.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ const char *format_CALL_FUNCTION_KW_36(ut32 oparg) {
}

const char *format_CALL_FUNCTION_EX_36(ut32 oparg) {
return rz_str_new((oparg & 0x01) ? "keyword args" : "");
return rz_str_dup((oparg & 0x01) ? "keyword args" : "");
}

static const char *MAKE_FUNCTION_FLAGS[] = { "default", "keyword-only", "annotation", "closure" };

const char *format_MAKE_FUNCTION_arg_36(ut32 oparg) {
size_t i;
char *ret = rz_str_new(" ");
char *ret = rz_str_dup(" ");
for (i = 0; i < sizeof(MAKE_FUNCTION_FLAGS) / sizeof(char *); ++i) {
if (oparg & 0x1) {
rz_str_appendf(ret, ", %s", MAKE_FUNCTION_FLAGS[i]);
} else {
free(ret);
ret = rz_str_new(MAKE_FUNCTION_FLAGS[i]);
ret = rz_str_dup(MAKE_FUNCTION_FLAGS[i]);
}
oparg >>= 1;
}
Expand All @@ -63,7 +63,7 @@ const char *format_value_flags_36(ut32 oparg) {
// empty fmt_spec.
ret = "";
}
return rz_str_new(ret);
return rz_str_dup(ret);
}

const char *format_extended_arg_36(ut32 oparg) {
Expand Down
10 changes: 5 additions & 5 deletions librz/asm/arch/pyc/pyc_dis.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ static const char *parse_arg(pyc_opcode_object *op, ut32 oparg, RzList /*<pyc_ob
arg = rz_str_newf("'%s'", (char *)t->data);
break;
default:
arg = rz_str_new(t->data);
arg = rz_str_dup(t->data);
}
}
if (op->type & HASNAME) {
t = (pyc_object *)rz_list_get_n(names, oparg);
if (t == NULL) {
return NULL;
}
arg = rz_str_new(t->data);
arg = rz_str_dup(t->data);
}
if ((op->type & HASJREL) || (op->type & HASJABS)) {
arg = rz_str_newf("%u", oparg);
Expand All @@ -116,10 +116,10 @@ static const char *parse_arg(pyc_opcode_object *op, ut32 oparg, RzList /*<pyc_ob
t = (pyc_object *)rz_list_get_n(varnames, oparg);
if (!t)
return NULL;
arg = rz_str_new(t->data);
arg = rz_str_dup(t->data);
}
if (op->type & HASCOMPARE) {
arg = rz_str_new(cmp_op[oparg]);
arg = rz_str_dup(cmp_op[oparg]);
}
if (op->type & HASFREE) {
if (!cellvars || !freevars) {
Expand All @@ -139,7 +139,7 @@ static const char *parse_arg(pyc_opcode_object *op, ut32 oparg, RzList /*<pyc_ob
return NULL;
}

arg = rz_str_new(t->data);
arg = rz_str_dup(t->data);
}
if (op->type & HASNARGS) {
arg = rz_str_newf("%u", oparg);
Expand Down
14 changes: 9 additions & 5 deletions librz/asm/p/asm_mips_gnu.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,23 @@ static int disassemble(struct rz_asm_t *a, struct rz_asm_op_t *op, const ut8 *bu
} else if (!rz_str_casecmp(a->cpu, "mips32")) {
ctx->disasm_obj.mach = bfd_mach_mipsisa32;
}
pre_cpu = rz_str_dup(pre_cpu, a->cpu);
char *tmp = rz_str_dup(a->cpu);
free(pre_cpu);
pre_cpu = tmp;
}

if (a->features && (!pre_features || !strcmp(a->features, pre_features))) {
free(ctx->disasm_obj.disassembler_options);
if (strstr(a->features, "n64")) {
ctx->disasm_obj.disassembler_options = rz_str_new("abi=n64");
ctx->disasm_obj.disassembler_options = rz_str_dup("abi=n64");
} else if (strstr(a->features, "n32")) {
ctx->disasm_obj.disassembler_options = rz_str_new("abi=n32");
ctx->disasm_obj.disassembler_options = rz_str_dup("abi=n32");
} else if (strstr(a->features, "o32")) {
ctx->disasm_obj.disassembler_options = rz_str_new("abi=o32");
ctx->disasm_obj.disassembler_options = rz_str_dup("abi=o32");
}
pre_features = rz_str_dup(pre_features, a->features);
char *tmp = rz_str_dup(a->features);
free(pre_features);
pre_features = tmp;
}

mips_mode = a->bits;
Expand Down
14 changes: 7 additions & 7 deletions librz/bin/bin.c
Original file line number Diff line number Diff line change
Expand Up @@ -940,9 +940,9 @@ RZ_API RzBinField *rz_bin_field_new(ut64 paddr, ut64 vaddr, int size, const char
return NULL;
}

ptr->name = rz_str_new(name);
ptr->comment = rz_str_new(comment);
ptr->format = rz_str_new(format);
ptr->name = rz_str_dup(name);
ptr->comment = rz_str_dup(comment);
ptr->format = rz_str_dup(format);
ptr->format_named = format_named;
ptr->paddr = paddr;
ptr->size = size;
Expand Down Expand Up @@ -970,10 +970,10 @@ RZ_API RzBinClassField *rz_bin_class_field_new(ut64 vaddr, ut64 paddr, const cha

ptr->vaddr = vaddr ? vaddr : UT64_MAX;
ptr->paddr = paddr;
ptr->name = rz_str_new(name);
ptr->classname = rz_str_new(classname);
ptr->libname = rz_str_new(libname);
ptr->type = rz_str_new(type);
ptr->name = rz_str_dup(name);
ptr->classname = rz_str_dup(classname);
ptr->libname = rz_str_dup(libname);
ptr->type = rz_str_dup(type);
return ptr;
}

Expand Down
4 changes: 2 additions & 2 deletions librz/bin/bobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ static RzBinClass *bin_class_new(RzBinObject *o, const char *name, const char *s
}

c->name = strdup(name);
c->super = rz_str_new(super);
c->super = rz_str_dup(super);
c->methods = rz_list_newf((RzListFree)rz_bin_symbol_free);
c->fields = rz_list_newf((RzListFree)rz_bin_class_field_free);
c->addr = address;
Expand Down Expand Up @@ -384,7 +384,7 @@ RZ_API RZ_BORROW RzBinSymbol *rz_bin_object_add_method(RZ_NONNULL RzBinObject *o
if (!symbol) {
return NULL;
}
symbol->classname = rz_str_new(klass);
symbol->classname = rz_str_dup(klass);

if (!c->methods->sorted) {
rz_list_sort(c->methods, (RzListComparator)rz_bin_compare_method);
Expand Down
2 changes: 1 addition & 1 deletion librz/bin/bobj_process_class.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ static void process_class_field(RzBinObject *o, RzBinClassField *field) {

static void process_handle_class(RzBinObject *o, RzBinClass *klass) {
if (!klass->name) {
klass->name = rz_str_new("unknown_class");
klass->name = rz_str_dup("unknown_class");
}
RzBinClass *found = ht_pp_find(o->name_to_class_object, klass->name, NULL);
if (!found) {
Expand Down
2 changes: 1 addition & 1 deletion librz/bin/dwarf/dwarf.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static inline RzBinDWARF *dwarf_from_debuglink(
if (RZ_STR_ISNOTEMPTY(file_directory) && strlen(file_directory) >= 2 && file_directory[1] == ':') {
file_dir = rz_str_newf("/%c%s", file_directory[0], file_directory + 2);
} else {
file_dir = rz_str_new(file_directory);
file_dir = rz_str_dup(file_directory);
}
RzListIter *it = NULL;
const char *debug_file_directory = NULL;
Expand Down
4 changes: 2 additions & 2 deletions librz/bin/dwarf/endian_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ RZ_IPI RzBinSection *rz_bin_dwarf_section_by_name(RzBinFile *binfile, const char
if (!o || !o->sections || RZ_STR_ISEMPTY(sn)) {
return NULL;
}
char *name = is_dwo ? rz_str_newf("%s.dwo", sn) : rz_str_new(sn);
char *name = is_dwo ? rz_str_newf("%s.dwo", sn) : rz_str_dup(sn);
if (!name) {
return NULL;
}
Expand Down Expand Up @@ -145,7 +145,7 @@ RZ_IPI RzBinEndianReader *RzBinEndianReader_from_file(RzBinFile *binfile, const

reader->buffer = buf;
reader->big_endian = bf_bigendian(binfile);
reader->section_name = rz_str_new(section->name);
reader->section_name = rz_str_dup(section->name);
reader->relocations = relocations;
return reader;
}
Expand Down
2 changes: 1 addition & 1 deletion librz/bin/dwarf/line.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ static char *full_file_path(
} else if (dir) {
file_path_abs = rz_str_newf("%s/%s", dir, file->path_name);
} else {
file_path_abs = rz_str_new(file->path_name);
file_path_abs = rz_str_dup(file->path_name);
}
return file_path_abs;
}
Expand Down
2 changes: 1 addition & 1 deletion librz/bin/format/elf/elf_sections.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ RZ_OWN RzVector /*<Elf_(Shdr)>*/ *Elf_(rz_bin_elf_sections_new)(RZ_NONNULL ELFOB
RZ_OWN char *Elf_(rz_bin_elf_section_type_to_string)(ut64 type) {
for (size_t i = 0; i < RZ_ARRAY_SIZE(type_translation_table); i++) {
if (type == type_translation_table[i].type) {
return rz_str_new(type_translation_table[i].name);
return rz_str_dup(type_translation_table[i].name);
}
}

Expand Down
2 changes: 1 addition & 1 deletion librz/bin/format/elf/elf_symbols.c
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ static bool is_section_local_symbol(ELFOBJ *bin, Elf_(Sym) * symbol) {

static bool set_elf_symbol_name(ELFOBJ *bin, struct symbols_segment *segment, RzBinElfSymbol *elf_symbol, Elf_(Sym) * symbol, RzBinElfSection *section) {
if (section && is_section_local_symbol(bin, symbol)) {
elf_symbol->name = rz_str_new(section->name);
elf_symbol->name = rz_str_dup(section->name);
return elf_symbol->name;
}

Expand Down
Loading
Loading