Skip to content

Commit e2e1363

Browse files
thesamesamPeter Zijlstra
authored andcommitted
objtool: Fix calloc call for new -Walloc-size
GCC 14 introduces a new -Walloc-size included in -Wextra which errors out like: ``` check.c: In function ‘cfi_alloc’: check.c:294:33: error: allocation of insufficient size ‘1’ for type ‘struct cfi_state’ with size ‘320’ [-Werror=alloc-size] 294 | struct cfi_state *cfi = calloc(sizeof(struct cfi_state), 1); | ^~~~~~ ``` The calloc prototype is: ``` void *calloc(size_t nmemb, size_t size); ``` So, just swap the number of members and size arguments to match the prototype, as we're initialising 1 struct of size `sizeof(struct ...)`. GCC then sees we're not doing anything wrong. Signed-off-by: Sam James <sam@gentoo.org> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Acked-by: Josh Poimboeuf <jpoimboe@kernel.org> Link: https://lore.kernel.org/r/20231107205504.1470006-1-sam@gentoo.org
1 parent b85ea95 commit e2e1363

1 file changed

Lines changed: 1 addition & 1 deletion

File tree

tools/objtool/check.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ static void init_insn_state(struct objtool_file *file, struct insn_state *state,
291291

292292
static struct cfi_state *cfi_alloc(void)
293293
{
294-
struct cfi_state *cfi = calloc(sizeof(struct cfi_state), 1);
294+
struct cfi_state *cfi = calloc(1, sizeof(struct cfi_state));
295295
if (!cfi) {
296296
WARN("calloc failed");
297297
exit(1);

0 commit comments

Comments
 (0)