Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

state: fix -Walloc-size #401

Merged
merged 1 commit into from
Nov 6, 2023
Merged

state: fix -Walloc-size #401

merged 1 commit into from
Nov 6, 2023

Conversation

thesamesam
Copy link
Contributor

GCC 14 introduces a new -Walloc-size included in -Wextra which gives:

src/state.c:589:9: warning: allocation of insufficient size ‘1’ for type ‘struct xkb_state’ with size ‘128’ [-Walloc-size]

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 xkb_state). GCC then sees we're not doing anything wrong.

GCC 14 introduces a new -Walloc-size included in -Wextra which gives:
```
src/state.c:589:9: warning: allocation of insufficient size ‘1’ for type ‘struct xkb_state’ with size ‘128’ [-Walloc-size]
```

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 xkb_state)`. GCC then sees we're not
doing anything wrong.

Signed-off-by: Sam James <[email protected]>
@whot whot merged commit fed9637 into xkbcommon:master Nov 6, 2023
4 checks passed
@whot
Copy link
Contributor

whot commented Nov 6, 2023

merged, thanks!

@thesamesam thesamesam deleted the alloc-size branch November 6, 2023 09:34
@thesamesam
Copy link
Contributor Author

Thanks!

@wismill wismill added this to the 1.7.0 milestone Nov 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants