Replace some strstr() calls with strchr()

This commit is contained in:
Paul I 2019-12-15 21:05:42 +03:00 committed by radare
parent 5870b5df85
commit 9a4578a915
15 changed files with 26 additions and 26 deletions

View File

@ -266,7 +266,7 @@ R_API bool r_anal_var_delete_byname(RAnal *a, RAnalFunction *fcn, int kind, cons
if (varlist && *varlist) {
do {
char *word = sdb_anext (ptr, &next);
char *sign = strstr (word, "_");
char *sign = strchr (word, '_');
const char *vardef = sdb_const_get (DB, sdb_fmt (
"var.0x%"PFMT64x ".%c.%s",
fcn->addr, kind, word), 0);

View File

@ -154,7 +154,7 @@ R_IPI int mips_assemble(const char *str, ut64 pc, ut8 *out) {
*out = 0;
*w0=*w1=*w2=*w3=0;
if (!strncmp (s, "jalr", 4) && !strstr (s, ",")) {
if (!strncmp (s, "jalr", 4) && !strchr (s, ',')) {
char opstr[32];
const char *arg = strchr (s, ' ');
if (arg) {

View File

@ -280,10 +280,10 @@ static bool bin_strfilter(RBin *bin, const char *str) {
break;
case 'e': // emails
if (str && *str) {
if (!strstr (str + 1, "@")) {
if (!strchr (str + 1, '@')) {
return false;
}
if (!strstr (str + 1, ".")) {
if (!strchr (str + 1, '.')) {
return false;
}
} else {
@ -292,7 +292,7 @@ static bool bin_strfilter(RBin *bin, const char *str) {
break;
case 'f': // format-string
if (str && *str) {
if (!strstr (str + 1, "%")) {
if (!strchr (str + 1, '%')) {
return false;
}
} else {

View File

@ -422,7 +422,7 @@ static int get_template(char *buf, SStrInfo *str_info) {
copy_string(&type_code_str, name->str_ptr, name->len);
r_list_free (names_l);
} else {
char *tmp = strstr(buf, "@");
char *tmp = strchr(buf, '@');
if (!tmp) {
goto get_template_err;
}

View File

@ -140,7 +140,7 @@ static char *swift_demangle_cmd(const char *s) {
}
}
if (swift_demangle) {
if (strstr (s, "'") || strstr (s, "\\")) {
if (strchr (s, '\'') || strchr (s, '\\')) {
/* nice try */
return NULL;
}
@ -567,7 +567,7 @@ R_API char *r_bin_demangle_swift(const char *s, bool syscmd) {
if (n) {
q = n + 1;
} else {
n = strstr (q, "_");
n = strchr (q, '_');
if (n) {
q = n + 1;
} else {

View File

@ -2708,7 +2708,7 @@ static void __updateStats(RCore *core, Sdb *db, ut64 addr, int statsMode) {
sdb_num_inc (db, type, 1, 0);
} else {
char *mnem = strdup (op->mnemonic);
char *sp = strstr (mnem, " ");
char *sp = strchr (mnem, ' ');
if (sp) {
*sp = 0;
//memmove (mnem, sp + 1, strlen (sp));
@ -2810,7 +2810,7 @@ static void __core_cmd_anal_fcn_allstats(RCore *core, const char *input) {
RList *dbs = r_list_newf ((RListFree)sdb_free);
Sdb *d = sdb_new0 ();
ut64 oseek = core->offset;
bool isJson = strstr (input, "j") != NULL;
bool isJson = strchr (input, 'j') != NULL;
char *inp = r_str_newf ("*%s", input);
r_list_foreach (core->anal->fcns, iter, fcn) {

View File

@ -970,7 +970,7 @@ void r_comment_vars(RCore *core, const char *input) {
break;
case ' ': { // "Cv "
// TODO check that idx exist
char *comment = strstr (name, " ");
char *comment = strchr (name, ' ');
if (comment) { // new comment given
if (*comment) {
*comment++ = 0;

View File

@ -2571,7 +2571,7 @@ r_cons_pop();
for (i = 0; i < count; i++) {
ut64 addr = UT64_MAX;
ox = strstr (line, "0x");
qo = strstr (line, "\"");
qo = strchr (line, '\"');
R_FREE (string);
if (ox) {
addr = r_num_get (NULL, ox);
@ -2697,7 +2697,7 @@ r_cons_pop();
}
if (str) {
str = strdup (str);
char *qoe = strstr (str, ";");
char *qoe = strchr (str, ';');
if (qoe) {
char* t = str;
str = r_str_ndup (str, qoe - str);

View File

@ -1031,7 +1031,7 @@ static RList *construct_rop_gadget(RCore *core, ut64 addr, ut8 *buf, int buflen,
if (grep) {
start = grep;
end = strstr (grep, ";");
end = strchr (grep, ';');
if (!end) { // We filter on a single opcode, so no ";"
end = start + strlen (grep);
}
@ -1100,7 +1100,7 @@ static RList *construct_rop_gadget(RCore *core, ut64 addr, ut8 *buf, int buflen,
if (search_hit) {
if (end[0] == ';') { // fields are semicolon-separated
start = end + 1; // skip the ;
end = strstr (start, ";");
end = strchr (start, ';');
end = end? end: start + strlen (start); // latest field?
free (grep_str);
grep_str = calloc (1, end - start + 1);
@ -2204,7 +2204,7 @@ static void do_asm_search(RCore *core, struct search_parameters *param, const ch
RIOMap *map;
bool regexp = input[1] == '/'; // "/c/"
bool everyByte = regexp && input[2] == 'a';
char *end_cmd = strstr (input, " ");
char *end_cmd = strchr (input, ' ');
switch ((end_cmd ? *(end_cmd - 1) : input[1])) {
case 'j':
param->outmode = R_MODE_JSON;

View File

@ -1383,11 +1383,11 @@ static void autocomplete_sdb (RCore *core, RLineCompletion *completion, const ch
str = r_str_trim_ro (pipe + 1);
}
lpath = r_str_new (str);
p1 = strstr (lpath, "/");
p1 = strchr (lpath, '/');
if (p1) {
*p1 = 0;
char *ns = p1 + 1;
p2 = strstr (ns, "/");
p2 = strchr (ns, '/');
if (!p2) { // anal/m
char *tmp = p1 + 1;
int n = strlen (tmp);
@ -1412,7 +1412,7 @@ static void autocomplete_sdb (RCore *core, RLineCompletion *completion, const ch
} else { // anal/meta/*
char *tmp = p2 + 1;
int n = strlen (tmp);
char *spltr = strstr (ns, "/");
char *spltr = strchr (ns, '/');
*spltr = 0;
next_cmd = r_str_newf ("anal/%s/*", ns);
out = sdb_querys (sdb, NULL, 0, next_cmd);
@ -1426,7 +1426,7 @@ static void autocomplete_sdb (RCore *core, RLineCompletion *completion, const ch
break;
}
temp_cmd = r_str_ndup (out, temp_pos - out); // contains the key=value pair
key = strstr (temp_cmd, "=");
key = strchr (temp_cmd, '=');
*key = 0;
if (!strncmp (tmp, temp_cmd, n)) {
char *cmplt = r_str_newf ("anal/%s/%s", ns, temp_cmd);

View File

@ -1082,7 +1082,7 @@ static void ds_build_op_str(RDisasmState *ds, bool print_color) {
// HACK to do varsub outside rparse becacuse the whole rparse api must be rewritten
char *ox = strstr (ds->str, "0x");
if (ox) {
char *e = strstr (ox, "]");
char *e = strchr (ox, ']');
if (e) {
e = strdup (e);
ut64 addr = r_num_get (NULL, ox);
@ -3100,7 +3100,7 @@ static void ds_cdiv_optimization(RDisasmState *ds) {
case R_ANAL_OP_TYPE_MUL:
esil = R_STRBUF_SAFEGET (&ds->analop.esil);
while (esil) {
comma = strstr (esil, ",");
comma = strchr (esil, ',');
if (!comma) {
break;
}

View File

@ -312,7 +312,7 @@ static int r_debug_bochs_wait(RDebug *dbg, int pid) {
ripStop = 0;
if ((x = strstr (desc->data, "Next at"))) {
if ((ini = strstr (x, "[0x"))) {
if ((fin = strstr (ini,"]"))) {
if ((fin = strchr (ini, ']'))) {
int len = fin - ini - 1;
strncpy (strIP, ini+1, len);
strIP[len] = 0;

View File

@ -35,7 +35,7 @@ static RIODesc *__open(RIO *io, const char *file, int rw, int mode) {
return riobochs;
}
i = strstr (file + 8, "#");
i = strchr (file + 8, '#');
if (i) {
l = i - file - 8;
fileBochs = r_str_ndup (file + 8, l);

View File

@ -1111,7 +1111,7 @@ R_API int r_main_radiff2(int argc, char **argv) {
depth = 64;
}
char *words = strdup (addr? addr: "0");
char *second = strstr (words, ",");
char *second = strchr (words, ',');
if (second) {
*second++ = 0;
ut64 off = r_num_math (c->num, words);

View File

@ -732,7 +732,7 @@ static RList *_extract_regs(char *regstr, RList *flags, char *pc_alias) {
// applies on all of the following registers until </feature>
if (r_str_startswith (regstr, "<feature")) {
// Verify that we found the feature in the current node
feature_end = strstr (regstr, ">");
feature_end = strchr (regstr, '>');
// To parse features of other architectures refer to:
// https://sourceware.org/gdb/onlinedocs/gdb/Standard-Target-Features.html#Standard-Target-Features
// - x86