[v2] Silence -Wpointer-to-int-cast warnings in newlib/libc/string/local.h.
Commit Message
On 21.07.2026 23:35, Jeff Johnston wrote:
> Hi Jan,
>
> The fallback for intptr_t is unnecessary. According to libc/include/
> sys/_intsup.h, gcc 3.2 or higher should support
> the intptr info we need plus there is an #error statement if it isn't.
> So, the code should just use intptr_t.
>
> -- Jeff J.
Thanks. Below is a simplified version of the patch.
/J.D.
Signed-off-by: Jan Dubiec <jdx@o2.pl>
---
newlib/libc/string/local.h | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
Comments
Patch applied. Thanks.
-- Jeff J.
On Tue, Jul 21, 2026 at 7:52 PM Jan Dubiec <jdx@o2.pl> wrote:
> On 21.07.2026 23:35, Jeff Johnston wrote:
> > Hi Jan,
> >
> > The fallback for intptr_t is unnecessary. According to libc/include/
> > sys/_intsup.h, gcc 3.2 or higher should support
> > the intptr info we need plus there is an #error statement if it isn't.
> > So, the code should just use intptr_t.
> >
> > -- Jeff J.
>
> Thanks. Below is a simplified version of the patch.
>
> /J.D.
>
>
> Signed-off-by: Jan Dubiec <jdx@o2.pl>
> ---
> newlib/libc/string/local.h | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/newlib/libc/string/local.h b/newlib/libc/string/local.h
> index 012a30d16..94c7c4a8f 100644
> --- a/newlib/libc/string/local.h
> +++ b/newlib/libc/string/local.h
> @@ -1,5 +1,6 @@
> #include <_ansi.h>
> #include <../ctype/local.h>
> +#include <stdint.h>
>
> /* internal function to compute width of wide char. */
> int __wcwidth (wint_t);
> @@ -21,7 +22,7 @@ int __wcwidth (wint_t);
> * This macro is used to skip a few bytes to find an aligned pointer.
> * It's better to keep it as is even if _HAVE_HW_MISALIGNED_ACCESS is
> enabled,
> * to avoid small performance penalties (if they are not zero). */
> -#define UNALIGNED_X(X) ((long)(X) & (sizeof (long) - 1))
> +#define UNALIGNED_X(X) ((long)(intptr_t)(X) & (sizeof (long) - 1))
>
> #ifdef _HAVE_HW_MISALIGNED_ACCESS
> /* Hardware performs unaligned operations with little
> @@ -30,7 +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)X & (sizeof (long) - 1)) | ((long)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.54.0
>
>
On 2026-07-22 01:48, Jan Dubiec wrote:
> On 21.07.2026 23:35, Jeff Johnston wrote:
>> Hi Jan,
>>
>> The fallback for intptr_t is unnecessary. According to libc/include/
>> sys/_intsup.h, gcc 3.2 or higher should support
>> the intptr info we need plus there is an #error statement if it isn't.
>> So, the code should just use intptr_t.
>>
>> -- Jeff J.
>
> Thanks. Below is a simplified version of the patch.
>
> /J.D.
>
>
> Signed-off-by: Jan Dubiec <jdx@o2.pl>
> ---
> newlib/libc/string/local.h | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/newlib/libc/string/local.h b/newlib/libc/string/local.h
> index 012a30d16..94c7c4a8f 100644
> --- a/newlib/libc/string/local.h
> +++ b/newlib/libc/string/local.h
> @@ -1,5 +1,6 @@
> #include <_ansi.h>
> #include <../ctype/local.h>
> +#include <stdint.h>
>
> /* internal function to compute width of wide char. */
> int __wcwidth (wint_t);
> @@ -21,7 +22,7 @@ int __wcwidth (wint_t);
> * This macro is used to skip a few bytes to find an aligned pointer.
> * It's better to keep it as is even if _HAVE_HW_MISALIGNED_ACCESS is enabled,
> * to avoid small performance penalties (if they are not zero). */
> -#define UNALIGNED_X(X) ((long)(X) & (sizeof (long) - 1))
> +#define UNALIGNED_X(X) ((long)(intptr_t)(X) & (sizeof (long) - 1))
>
> #ifdef _HAVE_HW_MISALIGNED_ACCESS
> /* Hardware performs unaligned operations with little
> @@ -30,7 +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)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?
Kind regards,
Torbjörn
@@ -1,5 +1,6 @@
#include <_ansi.h>
#include <../ctype/local.h>
+#include <stdint.h>
/* internal function to compute width of wide char. */
int __wcwidth (wint_t);
@@ -21,7 +22,7 @@ int __wcwidth (wint_t);
* This macro is used to skip a few bytes to find an aligned pointer.
* It's better to keep it as is even if _HAVE_HW_MISALIGNED_ACCESS is enabled,
* to avoid small performance penalties (if they are not zero). */
-#define UNALIGNED_X(X) ((long)(X) & (sizeof (long) - 1))
+#define UNALIGNED_X(X) ((long)(intptr_t)(X) & (sizeof (long) - 1))
#ifdef _HAVE_HW_MISALIGNED_ACCESS
/* Hardware performs unaligned operations with little
@@ -30,7 +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)X & (sizeof (long) - 1)) | ((long)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. */