Skip to content

Avoid invalid gcc 14.3 warning about array bounds in mbedtls_xor #73

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

Open
wants to merge 1 commit into
base: zephyr
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions library/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ static inline void mbedtls_xor(unsigned char *r,
return;
}
#endif
#if defined(MBEDTLS_COMPILER_IS_GCC) && __has_builtin(__builtin_constant_p)
if (__builtin_constant_p(n) && n % 16 == 0)
return;
#endif
#elif defined(MBEDTLS_ARCH_IS_X64) || defined(MBEDTLS_ARCH_IS_ARM64)
/* This codepath probably only makes sense on architectures with 64-bit registers */
for (; (i + 8) <= n; i += 8) {
Expand All @@ -219,6 +223,10 @@ static inline void mbedtls_xor(unsigned char *r,
return;
}
#endif
#if defined(MBEDTLS_COMPILER_IS_GCC) && __has_builtin(__builtin_constant_p)
if (__builtin_constant_p(n) && n % 8 == 0)
return;
#endif
#else
for (; (i + 4) <= n; i += 4) {
uint32_t x = mbedtls_get_unaligned_uint32(a + i) ^ mbedtls_get_unaligned_uint32(b + i);
Expand All @@ -229,6 +237,10 @@ static inline void mbedtls_xor(unsigned char *r,
return;
}
#endif
#if defined(MBEDTLS_COMPILER_IS_GCC) && __has_builtin(__builtin_constant_p)
if (__builtin_constant_p(n) && n % 4 == 0)
return;
#endif
#endif
#endif
for (; i < n; i++) {
Expand Down