Skip to content

Commit e06aa69

Browse files
myxoidmasahir0y
authored andcommitted
gendwarfksyms: use preferred form of sizeof for allocation
The preferred form is to use the variable being allocated to, rather than explicitly supplying a type name which might become stale. Also do this for memset. Suggested-by: Masahiro Yamada <[email protected]> Signed-off-by: Giuliano Procida <[email protected]> Reviewed-by: Sami Tolvanen <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]>
1 parent 87433e3 commit e06aa69

File tree

6 files changed

+8
-8
lines changed

6 files changed

+8
-8
lines changed

scripts/gendwarfksyms/cache.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void cache_set(struct cache *cache, unsigned long key, int value)
1515
{
1616
struct cache_item *ci;
1717

18-
ci = xmalloc(sizeof(struct cache_item));
18+
ci = xmalloc(sizeof(*ci));
1919
ci->key = key;
2020
ci->value = value;
2121
hash_add(cache->cache, &ci->hash, hash_32(key));

scripts/gendwarfksyms/die.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ static struct die *create_die(Dwarf_Die *die, enum die_state state)
3333
{
3434
struct die *cd;
3535

36-
cd = xmalloc(sizeof(struct die));
36+
cd = xmalloc(sizeof(*cd));
3737
init_die(cd);
3838
cd->addr = (uintptr_t)die->addr;
3939

@@ -123,7 +123,7 @@ static struct die_fragment *append_item(struct die *cd)
123123
{
124124
struct die_fragment *df;
125125

126-
df = xmalloc(sizeof(struct die_fragment));
126+
df = xmalloc(sizeof(*df));
127127
df->type = FRAGMENT_EMPTY;
128128
list_add_tail(&df->list, &cd->fragments);
129129
return df;

scripts/gendwarfksyms/dwarf.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ static int get_union_kabi_status(Dwarf_Die *die, Dwarf_Die *placeholder,
634634
* Note that the user of this feature is responsible for ensuring
635635
* that the structure actually remains ABI compatible.
636636
*/
637-
memset(&state.kabi, 0, sizeof(struct kabi_state));
637+
memset(&state.kabi, 0, sizeof(state.kabi));
638638

639639
res = checkp(process_die_container(&state, NULL, die,
640640
check_union_member_kabi_status,

scripts/gendwarfksyms/kabi.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ void kabi_read_rules(int fd)
228228
if (type == KABI_RULE_TYPE_UNKNOWN)
229229
error("unsupported kABI rule type: '%s'", field);
230230

231-
rule = xmalloc(sizeof(struct rule));
231+
rule = xmalloc(sizeof(*rule));
232232

233233
rule->type = type;
234234
rule->target = xstrdup(get_rule_field(&rule_str, &left));

scripts/gendwarfksyms/symbols.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ void symbol_read_exports(FILE *file)
146146
continue;
147147
}
148148

149-
sym = xcalloc(1, sizeof(struct symbol));
149+
sym = xcalloc(1, sizeof(*sym));
150150
sym->name = name;
151151
sym->addr.section = SHN_UNDEF;
152152
sym->state = SYMBOL_UNPROCESSED;

scripts/gendwarfksyms/types.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static int type_list_append(struct list_head *list, const char *s, void *owned)
4343
if (!s)
4444
return 0;
4545

46-
entry = xmalloc(sizeof(struct type_list_entry));
46+
entry = xmalloc(sizeof(*entry));
4747
entry->str = s;
4848
entry->owned = owned;
4949
list_add_tail(&entry->list, list);
@@ -120,7 +120,7 @@ static struct type_expansion *type_map_add(const char *name,
120120
struct type_expansion *e;
121121

122122
if (__type_map_get(name, &e)) {
123-
e = xmalloc(sizeof(struct type_expansion));
123+
e = xmalloc(sizeof(*e));
124124
type_expansion_init(e);
125125
e->name = xstrdup(name);
126126

0 commit comments

Comments
 (0)