[PATCH] Make the UNALIGNED_X_Y() macro more robust against errors.
Jan Dubiec <[email protected]>
| Newsgroups | gmane.comp.lib.newlib |
|---|---|
| Message-ID | <[email protected]> |
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 <[email protected]> --- 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