[PATCH] sys/cdefs.h: Protect parameters to __builtin_is_aligned()

Corinna Vinschen vinschen@redhat.com
Wed Jul 23 09:13:20 GMT 2025


On Jul 22 23:45, Paul Cercueil wrote:
> The macro was not protecting properly its first parameter, which caused
> it to silently return an invalid value when passing a composed
> parameter, ie.
> 
> __builtin_is_aligned(src | dst | len, 32);
> 
> Signed-off-by: Paul Cercueil <paul@crapouillou.net>
> ---
>  newlib/libc/include/sys/cdefs.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/newlib/libc/include/sys/cdefs.h b/newlib/libc/include/sys/cdefs.h
> index d13a92a79..20b3553dc 100644
> --- a/newlib/libc/include/sys/cdefs.h
> +++ b/newlib/libc/include/sys/cdefs.h
> @@ -736,7 +736,7 @@
>  /* Provide fallback versions for other compilers (GCC/Clang < 10): */
>  #if !__has_builtin(__builtin_is_aligned)
>  #define __builtin_is_aligned(x, align)	\
> -	(((__uintptr_t)x & ((align) - 1)) == 0)
> +	(((__uintptr_t)(x) & ((align) - 1)) == 0)
>  #endif
>  #if !__has_builtin(__builtin_align_up)
>  #define __builtin_align_up(x, align)	\
> -- 
> 2.47.2

Pushed.

Thanks,
Corinna



More information about the Newlib mailing list