Fix -Werror=alloc-size-larger-than in metrixReset - #152
Open
hector-cao wants to merge 1 commit into
Open
Conversation
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>
daweiq
reviewed
Aug 13, 2026
daweiq
left a comment
Contributor
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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)));