aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2024-02-19 17:49:38 -0300
committerArnaldo Carvalho de Melo <acme@redhat.com>2024-02-19 17:49:38 -0300
commit7146ad04b72b08a5d663b9cb11735ed76d26f4cf (patch)
tree7dd68d06ec0ef2b9909981061b90e599d20b7bbd
parent97dce38eae062cf951f34a9e52fa5eb1c66614c1 (diff)
downloadpahole-7146ad04b72b08a5d663b9cb11735ed76d26f4cf.tar.gz
pahole: Do not use -1 to mean that a enumerator wasn't found in an enumeration
As -1 is a possible value for an enumerator, better to return the 'struct enumerator' pointer, that way either we return NULL if that enumerator wasn't found by name or in case of success just use enumerator->value. Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--pahole.c29
1 files changed, 15 insertions, 14 deletions
diff --git a/pahole.c b/pahole.c
index 0e079ae1..b6fd72c8 100644
--- a/pahole.c
+++ b/pahole.c
@@ -2163,35 +2163,36 @@ static struct enumerator *enumerations__lookup_entry_from_value(struct list_head
return NULL;
}
-static int64_t enumeration__lookup_enumerator(struct type *enumeration, const char *enumerator)
+static struct enumerator *enumeration__find_enumerator(struct type *enumeration, const char *name)
{
struct enumerator *entry;
type__for_each_enumerator(enumeration, entry) {
const char *entry_name = enumerator__name(entry);
- if (!strcmp(entry_name, enumerator))
- return entry->value;
+ if (!strcmp(entry_name, name))
+ return entry;
if (enumeration->member_prefix_len &&
- !strcmp(entry_name + enumeration->member_prefix_len, enumerator))
- return entry->value;
+ !strcmp(entry_name + enumeration->member_prefix_len, name))
+ return entry;
}
- return -1;
+ return NULL;
}
-static int64_t enumerations__lookup_enumerator(struct list_head *enumerations, const char *enumerator)
+static struct enumerator *enumerations__find_enumerator(struct list_head *enumerations, const char *name)
{
struct tag_cu_node *pos;
list_for_each_entry(pos, enumerations, node) {
- int64_t value = enumeration__lookup_enumerator(tag__type(pos->tc.tag), enumerator);
- if (value != -1)
- return value;
+ struct enumerator *enumerator = enumeration__find_enumerator(tag__type(pos->tc.tag), name);
+
+ if (enumerator != NULL)
+ return enumerator;
}
- return -1;
+ return NULL;
}
static int base_type__fprintf_enum_value(void *instance, int _sizeof, struct list_head *enumerations, FILE *fp)
@@ -2883,16 +2884,16 @@ static int class_member_filter__parse(struct class_member_filter *filter, struct
enumerations__calc_prefix(&type->type_enum);
- int64_t enumerator_value = enumerations__lookup_enumerator(&type->type_enum, value);
+ struct enumerator * enumerator = enumerations__find_enumerator(&type->type_enum, value);
- if (enumerator_value < 0) {
+ if (enumerator == NULL) {
if (global_verbose)
fprintf(stderr, "Couldn't resolve right operand ('%s') in '%s' with the specified 'type=%s' and type_enum' \n",
value, sfilter, class_member__name(type->type_member));
return -1;
}
- filter->right = enumerator_value;
+ filter->right = enumerator->value;
return 0;
}