dracutdevs / dracut

dracut the event driven initramfs infrastructure
https://github.com/dracutdevs/dracut/wiki
GNU General Public License v2.0
597 stars 396 forks source link

install: fix -Walloc-size #2553

Open thesamesam opened 9 months ago

thesamesam commented 9 months ago

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

src/install/hashmap.c: In function ‘hashmap_new’:
src/install/hashmap.c:83:11: warning: allocation of insufficient size ‘1’ for type ‘Hashmap’ with size ‘40’ [-Walloc-size]
   83 |         h = malloc0(size);
      |           ^

malloc0 is a macro deifned by Dracut (and systemd, see below):

malloc0(n) (calloc((n), 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(...). GCC then sees we're not doing anything wrong.

This was fixed upstream in systemd in commit f80bb1f7eaf31476a44c2093d3ee02aba817a0b0 [0].

[0] https://github.com/systemd/systemd/commit/f80bb1f7eaf31476a44c2093d3ee02aba817a0b0

Changes

Fix malloc0 macro to comply with calloc prototype.

Checklist

Fixes #

LaszloGombos commented 9 months ago

Thanks @thesamesam . Can you please try to fix the commisery error as well ?


fix(install): fix -Walloc-size
              ^^^
commit_message:1:15: note: prefer using the imperative for verbs```
stale[bot] commented 4 months ago

This issue is being marked as stale because it has not had any recent activity. It will be closed if no further activity occurs. If this is still an issue in the latest release of Dracut and you would like to keep it open please comment on this issue within the next 7 days. Thank you for your contributions.