Skip to content

Fix -Werror=alloc-size-larger-than in metrixReset - #152

Open
hector-cao wants to merge 1 commit into
intel:masterfrom
hector-cao:fix-max-alloc-size-warning-1
Open

Fix -Werror=alloc-size-larger-than in metrixReset#152
hector-cao wants to merge 1 commit into
intel:masterfrom
hector-cao:fix-max-alloc-size-warning-1

Conversation

@hector-cao

@hector-cao hector-cao commented Aug 10, 2026

Copy link
Copy Markdown

LSM_MET_DEPTH was defined as (1 << lsm_met_len_shift), where the literal 1 is a signed int and lsm_met_len_shift is a runtime global. Recent GCC assumes the shift may yield a negative int (e.g. 1 << 31), which sign-extends to a huge size_t when passed to calloc(), triggering -Werror=alloc-size-larger-than and failing the build.

Cast the literal to size_t so the shift is done in unsigned 64-bit arithmetic, keeping the calloc size argument within a valid range.


On Ubuntu devel (26.10) (and Debian as well), we have this error while building QATzip:

In function 'metrixReset',
inlined from 'qzSetupSessionInternal' at qatzip_utils.c:390:9:
qatzip_utils.c:1589:28: error: argument 1 range [18446744071562067968, 18446744073709551615] exceeds maximum object size 9223372036854775807 [-Werror=alloc-size-larger-than=]
1589 | m->latency_array = calloc(LSM_MET_DEPTH, sizeof(*(m->latency_array)));

LSM_MET_DEPTH was defined as (1 << lsm_met_len_shift), where the
literal 1 is a signed int and lsm_met_len_shift is a runtime global.
Recent GCC assumes the shift may yield a negative int (e.g. 1 << 31), which
sign-extends to a huge size_t when passed to calloc(), triggering
-Werror=alloc-size-larger-than and failing the build.

Cast the literal to size_t so the shift is done in unsigned 64-bit
arithmetic, keeping the calloc size argument within a valid range.

Signed-off-by: Hector Cao <hector.cao@canonical.com>
@hector-cao
hector-cao requested a review from daweiq as a code owner August 10, 2026 23:22

@daweiq daweiq left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your patch!

We will try reproduce the issue and verify the patch internally first.
If it works, will include your fix in the following release.

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.

2 participants