Skip to content

Commit

Permalink
thunk: assert nb_fields is valid
Browse files Browse the repository at this point in the history
thunk.c:91:32: warning: Call to 'malloc' has an allocation size of 0 bytes
        se->field_offsets[i] = malloc(nb_fields * sizeof(int));
                               ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reported-by: Clang Static Analyzer
Signed-off-by: Philippe Mathieu-Daudé <[email protected]>
Signed-off-by: Michael Tokarev <[email protected]>
  • Loading branch information
philmd authored and Michael Tokarev committed Jul 31, 2017
1 parent b929f7e commit a44af72
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion thunk.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ void thunk_register_struct(int id, const char *name, const argtype *types)
int nb_fields, offset, max_align, align, size, i, j;

assert(id < max_struct_entries);
se = struct_entries + id;

/* first we count the number of fields */
type_ptr = types;
Expand All @@ -76,6 +75,8 @@ void thunk_register_struct(int id, const char *name, const argtype *types)
type_ptr = thunk_type_next(type_ptr);
nb_fields++;
}
assert(nb_fields > 0);
se = struct_entries + id;
se->field_types = types;
se->nb_fields = nb_fields;
se->name = name;
Expand Down

0 comments on commit a44af72

Please sign in to comment.