[PATCH v2] Silence -Wpointer-to-int-cast warnings in newlib/libc/string/local.h.

Jan Dubiec <[email protected]> Wed, 22 Jul 2026 01:48:53 +0200
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
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 <[email protected]>
---
 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