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

Message ID 20250722214540.1234541-1-paul@crapouillou.net
State New
Headers
Series sys/cdefs.h: Protect parameters to __builtin_is_aligned() |

Commit Message

Paul Cercueil July 22, 2025, 9:45 p.m. UTC
  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(-)
  

Comments

Corinna Vinschen July 23, 2025, 9:13 a.m. UTC | #1
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
  

Patch

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)	\