Call remove_offsetmap only if the flagItem is not new ##flags

* Call remove_offsetmap only if the flagItem is not new

It does not have sense to call that function on new FlagItems, it just
slows down things for nothing, since item->offset has not been set yet.

* force and is_new must be two separate things

When setting a flag (which may be even a set of some properties of an
existing flagitem) we want to force the update of all the RFlag
properties, but remove_offsetmap should not be called when the flagitem
is new. So we need to track the two properties separately.
This commit is contained in:
Riccardo Schirone 2019-05-08 14:11:34 +02:00 committed by radare
parent 5d646d3551
commit 8cd9851c98

View File

@ -139,9 +139,11 @@ static void set_name(RFlagItem *item, char *name) {
item->realname = item->name;
}
static bool update_flag_item_offset(RFlag *f, RFlagItem *item, ut64 newoff, bool force) {
static bool update_flag_item_offset(RFlag *f, RFlagItem *item, ut64 newoff, bool is_new, bool force) {
if (item->offset != newoff || force) {
remove_offsetmap (f, item);
if (!is_new) {
remove_offsetmap (f, item);
}
item->offset = newoff;
RFlagsAtOffset *flagsAtOffset = flags_at_offset (f, newoff);
@ -716,6 +718,7 @@ R_API RFlagItem *r_flag_set_next(RFlag *f, const char *name, ut64 off, ut32 size
R_API RFlagItem *r_flag_set(RFlag *f, const char *name, ut64 off, ut32 size) {
r_return_val_if_fail (f && name && *name, NULL);
bool is_new = false;
char *itemname = filter_item_name (name);
if (!itemname) {
return NULL;
@ -733,12 +736,13 @@ R_API RFlagItem *r_flag_set(RFlag *f, const char *name, ut64 off, ut32 size) {
if (!item) {
goto err;
}
is_new = true;
}
item->space = r_flag_space_cur (f);
item->size = size;
update_flag_item_offset (f, item, off + f->base, true);
update_flag_item_offset (f, item, off + f->base, is_new, true);
update_flag_item_name (f, item, name, true);
return item;
err:
@ -856,7 +860,7 @@ static bool flag_relocate_foreach(RFlagItem *fi, void *user) {
if (fn == on) {
ut64 fm = fi->offset & u->off_mask;
ut64 om = u->to & u->off_mask;
update_flag_item_offset (u->f, fi, (u->to & u->neg_mask) + fm + om, false);
update_flag_item_offset (u->f, fi, (u->to & u->neg_mask) + fm + om, false, false);
u->n++;
}
return true;