[PATCH] Make the UNALIGNED_X_Y() macro more robust against errors.

Jeff Johnston jjohnstn@redhat.com
Mon Aug 10 18:49:18 GMT 2026


Patch merged.

-- Jeff J.

On Sun, Aug 9, 2026 at 5:15 PM Jan Dubiec <jdx@o2.pl> wrote:

> On 23.07.2026 13:33, Torbjorn SVENSSON wrote:
> > On 2026-07-22 01:48, Jan Dubiec wrote:[...]>>   /* Nonzero if either X
> or Y is not aligned on a "long" boundary.  */
> >>   #define UNALIGNED_X_Y(X, Y) \
> >> -  (((long)X & (sizeof (long) - 1)) | ((long)Y & (sizeof (long) - 1)))
> >> +  (((long)(intptr_t)X & (sizeof (long) - 1)) | \
> >> +   ((long)(intptr_t)Y & (sizeof (long) - 1)))
> >
> > Not really what you change, but ideally, shouldn't this be:
> >
> > +  (((long)(intptr_t)(X) & (sizeof (long) - 1)) | \
> > +   ((long)(intptr_t)(Y) & (sizeof (long) - 1)))
> >
> > i.e. putting parenthesis around the macro arguments?
>
> I totally agree. Thanks!
>
> /J.D.
>
>
> Signed-off-by: Jan Dubiec <jdx@o2.pl>
> ---
>  newlib/libc/string/local.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/newlib/libc/string/local.h b/newlib/libc/string/local.h
> index 94c7c4a8f..d9bff40ab 100644
> --- a/newlib/libc/string/local.h
> +++ b/newlib/libc/string/local.h
> @@ -31,8 +31,8 @@ int __wcwidth (wint_t);
>  #else /* _HAVE_HW_MISALIGNED_ACCESS */
>  /* Nonzero if either X or Y is not aligned on a "long" boundary.  */
>  #define UNALIGNED_X_Y(X, Y) \
> -  (((long)(intptr_t)X & (sizeof (long) - 1)) | \
> -   ((long)(intptr_t)Y & (sizeof (long) - 1)))
> +  (((long)(intptr_t)(X) & (sizeof (long) - 1)) | \
> +   ((long)(intptr_t)(Y) & (sizeof (long) - 1)))
>  #endif /* _HAVE_HW_MISALIGNED_ACCESS */
>
>  /* How many bytes are copied each iteration of the word copy loop.  */
> --
> 2.55.0
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/newlib/attachments/20260810/510296c7/attachment.htm>


More information about the Newlib mailing list