When setting non-bool config var, set false/true if r_str_is_false()/_is_true() (#15681)

* When setting non-bool config var, set false/true if r_str_is_false()/_is_true()

* Fix for cmd_open tests

* Fix for cmd_print test
This commit is contained in:
Khairul Azhar Kasmiran 2019-12-21 11:12:54 +08:00 committed by Anton Kochkov
parent 28ec4ca297
commit eb7b4b756b
3 changed files with 17 additions and 18 deletions

View File

@ -417,17 +417,23 @@ R_API RConfigNode* r_config_set(RConfig *cfg, const char *name, const char *valu
if (node->value == value) {
goto beach;
}
char *tmp = node->value;
node->value = strdup (value);
free (tmp);
if (IS_DIGIT (*value)) {
free (node->value);
if (r_str_is_false (value)) {
node->value = strdup ("false");
node->i_value = 0;
} else if (r_str_is_true (value)) {
node->value = strdup ("true");
node->i_value = 1;
} else {
node->value = strdup (value);
node->i_value = 2;
}
if (IS_DIGIT (*value) || (value[0] == '-' && IS_DIGIT (value[1]))) {
if (strchr (value, '/')) {
node->i_value = r_num_get (cfg->num, value);
} else {
node->i_value = r_num_math (cfg->num, value);
}
} else {
node->i_value = 0;
}
node->flags |= CN_INT;
}

View File

@ -2252,15 +2252,6 @@ static bool cb_seggrn(void *user, void *data) {
return true;
}
static bool cb_cmtoff(void *user, void *data) {
RConfigNode *node = (RConfigNode *) data;
if (node->i_value || r_str_is_false (node->value)) {
free (node->value);
node->value = strdup (r_str_bool (node->i_value));
}
return true;
}
static bool cb_stopthreads(void *user, void *data) {
RCore *core = (RCore *) user;
RConfigNode *node = (RConfigNode *) data;
@ -2707,7 +2698,8 @@ static bool cb_linesabs(void *user, void *data) {
core->print->lines_abs = node->i_value;
if (core->print->lines_abs && core->print->lines_cache_sz <= 0) {
ut64 from = (ut64)r_config_get_i (core->config, "lines.from");
ut64 to = (ut64)r_config_get_i (core->config, "lines.to");
const char *to_str = r_config_get (core->config, "lines.to");
ut64 to = r_num_math (core->num, (to_str && *to_str) ? to_str : "$s");
core->print->lines_cache_sz = r_core_lines_initcache (core, from, to);
if (core->print->lines_cache_sz == -1) {
eprintf ("ERROR: \"lines.from\" and \"lines.to\" must be set\n");
@ -3135,7 +3127,7 @@ R_API int r_core_config_init(RCore *core) {
SETPREF ("asm.marks", "true", "Show marks before the disassembly");
SETPREF ("asm.cmt.refs", "false", "Show flag and comments from refs in disasm");
SETPREF ("asm.cmt.patch", "false", "Show patch comments in disasm");
SETCB ("asm.cmt.off", "nodup", &cb_cmtoff, "Show offset comment in disasm (true, false, nodup)");
SETPREF ("asm.cmt.off", "nodup", "Show offset comment in disasm (true, false, nodup)");
SETPREF ("asm.payloads", "false", "Show payload bytes in disasm");
/* bin */

View File

@ -73,7 +73,8 @@ static void __init_seek_line(RCore *core) {
r_config_bump (core->config, "lines.to");
from = r_config_get_i (core->config, "lines.from");
to = r_config_get_i (core->config, "lines.to");
const char *to_str = r_config_get (core->config, "lines.to");
to = r_num_math (core->num, (to_str && *to_str) ? to_str : "$s");
if (r_core_lines_initcache (core, from, to) == -1) {
eprintf ("ERROR: \"lines.from\" and \"lines.to\" must be set\n");
}