Skip to content

Commit

Permalink
Remove hidden static in rz_analysis_cc_max_arg
Browse files Browse the repository at this point in the history
  • Loading branch information
wargio committed Jan 5, 2024
1 parent e1af458 commit f203b18
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
33 changes: 15 additions & 18 deletions librz/analysis/cc.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ RZ_API void rz_analysis_cc_del(RzAnalysis *analysis, const char *name) {
sdb_unset(DB, name, 0);
cc_sdb_unsetf(DB, "cc.%s.ret", name);
cc_sdb_unsetf(DB, "cc.%s.argn", name);
cc_sdb_unsetf(DB, "cc.%s.maxargs", name);
for (int i = 0; i < RZ_ANALYSIS_CC_MAXARG; i++) {
cc_sdb_unsetf(DB, "cc.%s.arg%d", name, i);
}
Expand Down Expand Up @@ -77,6 +78,11 @@ RZ_API bool rz_analysis_cc_set(RzAnalysis *analysis, const char *expr) {
n++;
}
}
{
char maxargs[256];
rz_strf(maxargs, "%d", n);
cc_sdb_setf(DB, maxargs, "cc.%s.maxargs", ccname);
}
rz_list_free(ccArgs);
free(e);
free(args);
Expand Down Expand Up @@ -197,27 +203,18 @@ RZ_API void rz_analysis_cc_set_error(RzAnalysis *analysis, const char *conventio
}

RZ_API int rz_analysis_cc_max_arg(RzAnalysis *analysis, const char *cc) {
int i = 0;
rz_return_val_if_fail(analysis && DB && cc, 0);
static void *oldDB = NULL;
static char *oldCC = NULL;
static int oldArg = 0;
if (oldDB == DB && !strcmp(cc, oldCC)) {
return oldArg;
char *query = rz_str_newf("cc.%s.maxargs", cc);
if (!query) {
return 0;
}
oldDB = DB;
free(oldCC);
oldCC = strdup(cc);
for (i = 0; i < RZ_ANALYSIS_CC_MAXARG; i++) {
char *query = rz_str_newf("cc.%s.arg%d", cc, i);
const char *res = query ? sdb_const_get(DB, query, 0) : NULL;
free(query);
if (!res) {
break;
}
const char *res = sdb_const_get(DB, query, 0);
free(query);
int maxargs = res ? atoi(res) : 0;
if (maxargs < 0 || maxargs > RZ_ANALYSIS_CC_MAXARG) {
return 0;
}
oldArg = i;
return i;
return maxargs;
}

RZ_API const char *rz_analysis_cc_ret(RzAnalysis *analysis, const char *convention) {
Expand Down
8 changes: 5 additions & 3 deletions librz/analysis/var.c
Original file line number Diff line number Diff line change
Expand Up @@ -779,9 +779,11 @@ RZ_API int rz_analysis_var_get_argnum(RzAnalysisVar *var) {
if (!reg) {
return -1;
}
int i;
int arg_max = var->fcn->cc ? rz_analysis_cc_max_arg(analysis, var->fcn->cc) : 0;
for (i = 0; i < arg_max; i++) {
int arg_max = 0;
if (RZ_STR_ISNOTEMPTY(var->fcn->cc)) {
arg_max = rz_analysis_cc_max_arg(analysis, var->fcn->cc);
}
for (int i = 0; i < arg_max; i++) {
const char *reg_arg = rz_analysis_cc_arg(analysis, var->fcn->cc, i);
if (reg_arg && !strcmp(reg->name, reg_arg)) {
return i;
Expand Down

0 comments on commit f203b18

Please sign in to comment.