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

Jeff Johnston <[email protected]> Wed, 22 Jul 2026 17:16:54 -0400
Newsgroups gmane.comp.lib.newlib
Message-ID <CAOox84tv0QFyOVjpu2_f8z7J+VyBZ6b8yiUNYp6GhkoBnS3tiQ@mail.gmail.com>
--0000000000005bf024065739a90a
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Patch applied.  Thanks.

-- Jeff J.

On Tue, Jul 21, 2026 at 7:52=E2=80=AFPM Jan Dubiec <[email protected]> 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 <[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
>
>

--0000000000005bf024065739a90a
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div class=3D"gmail_default" style=3D"font-family:verdana,=
sans-serif">Patch applied.=C2=A0 Thanks.</div><div class=3D"gmail_default" =
style=3D"font-family:verdana,sans-serif"><br></div><div class=3D"gmail_defa=
ult" style=3D"font-family:verdana,sans-serif">-- Jeff J.</div></div><br><di=
v class=3D"gmail_quote gmail_quote_container"><div dir=3D"ltr" class=3D"gma=
il_attr">On Tue, Jul 21, 2026 at 7:52=E2=80=AFPM Jan Dubiec &lt;<a href=3D"=
mailto:[email protected]">[email protected]</a>&gt; wrote:<br></div><blockquote class=3D"gm=
ail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,=
204,204);padding-left:1ex">On 21.07.2026 23:35, Jeff Johnston wrote:<br>
&gt; Hi Jan,<br>
&gt; <br>
&gt; The fallback for intptr_t is unnecessary.=C2=A0 According to libc/incl=
ude/ <br>
&gt; sys/_intsup.h, gcc 3.2 or higher should support<br>
&gt; the intptr info we need plus there is an #error statement if it isn&#3=
9;t.=C2=A0 <br>
&gt; So, the code should just use intptr_t.<br>
&gt; <br>
&gt; -- Jeff J.<br>
<br>
Thanks. Below is a simplified version of the patch.<br>
<br>
/J.D.<br>
<br>
<br>
Signed-off-by: Jan Dubiec &lt;<a href=3D"mailto:[email protected]" target=3D"_blank=
">[email protected]</a>&gt;<br>
---<br>
=C2=A0newlib/libc/string/local.h | 6 ++++--<br>
=C2=A01 file changed, 4 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/newlib/libc/string/local.h b/newlib/libc/string/local.h<br>
index 012a30d16..94c7c4a8f 100644<br>
--- a/newlib/libc/string/local.h<br>
+++ b/newlib/libc/string/local.h<br>
@@ -1,5 +1,6 @@<br>
=C2=A0#include &lt;_ansi.h&gt;<br>
=C2=A0#include &lt;../ctype/local.h&gt;<br>
+#include &lt;stdint.h&gt;<br>
<br>
=C2=A0/* internal function to compute width of wide char. */<br>
=C2=A0int __wcwidth (wint_t);<br>
@@ -21,7 +22,7 @@ int __wcwidth (wint_t);<br>
=C2=A0 * This macro is used to skip a few bytes to find an aligned pointer.=
<br>
=C2=A0 * It&#39;s better to keep it as is even if _HAVE_HW_MISALIGNED_ACCES=
S is enabled,<br>
=C2=A0 * to avoid small performance penalties (if they are not zero).=C2=A0=
 */<br>
-#define UNALIGNED_X(X) ((long)(X) &amp; (sizeof (long) - 1))<br>
+#define UNALIGNED_X(X) ((long)(intptr_t)(X) &amp; (sizeof (long) - 1))<br>
<br>
=C2=A0#ifdef _HAVE_HW_MISALIGNED_ACCESS<br>
=C2=A0/* Hardware performs unaligned operations with little<br>
@@ -30,7 +31,8 @@ int __wcwidth (wint_t);<br>
=C2=A0#else /* _HAVE_HW_MISALIGNED_ACCESS */<br>
=C2=A0/* Nonzero if either X or Y is not aligned on a &quot;long&quot; boun=
dary.=C2=A0 */<br>
=C2=A0#define UNALIGNED_X_Y(X, Y) \<br>
-=C2=A0 (((long)X &amp; (sizeof (long) - 1)) | ((long)Y &amp; (sizeof (long=
) - 1)))<br>
+=C2=A0 (((long)(intptr_t)X &amp; (sizeof (long) - 1)) | \<br>
+=C2=A0 =C2=A0((long)(intptr_t)Y &amp; (sizeof (long) - 1)))<br>
=C2=A0#endif /* _HAVE_HW_MISALIGNED_ACCESS */<br>
<br>
=C2=A0/* How many bytes are copied each iteration of the word copy loop.=C2=
=A0 */<br>
-- <br>
2.54.0<br>
<br>
</blockquote></div>

--0000000000005bf024065739a90a--