diff options
author | Jan Dubiec <jdx@o2.pl> | 2025-03-02 18:20:13 +0100 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2025-03-03 11:45:36 +0100 |
commit | 7962e3b26e5d6e8a1228baa63350321c8d9f31de (patch) | |
tree | a3c0491421dde3b9b8b565f01ef5063263adc365 /newlib/libc/stdlib | |
parent | 627785b540bd9e119ad76cdac2dbe39221fdd2f2 (diff) | |
download | newlib-7962e3b26e5d6e8a1228baa63350321c8d9f31de.zip newlib-7962e3b26e5d6e8a1228baa63350321c8d9f31de.tar.gz newlib-7962e3b26e5d6e8a1228baa63350321c8d9f31de.tar.bz2 |
Silence -Wshift-count-overflow warnings
This patch fixes a few "left shift count >= width of type
[-Wshift-count-overflow]" warnings. Before shifting a char 16 (or more)
bits left first it explicitly casts the char to uint32_t. The existing
code relies on implicit casts to int and assumes that ints are 32-bit.
This is not always true because the C standard does not require int to
be 32-bit and there are targets (e.g. H8/300) where by default int is
indeed 16-bit.
2025-03-02 Jan Dubiec <jdx@o2.pl>
newlib/ChangeLog:
* libc/stdlib/gdtoa-gdtoa.c (gdtoa): Cast to __ULong before left shift.
* libc/string/memmem.c (memmem): Cast to uint32_t before left shift.
* libc/string/strstr.c (strstr2): Ditto.
(strstr3): Ditto.
(strstr4): Ditto.
newlib/libc/stdlib/gdtoa-gdtoa.c | 2 +-
newlib/libc/string/memmem.c | 3 ++-
newlib/libc/string/strstr.c | 6 +++---
3 files changed, 6 insertions(+), 5 deletions(-)
Diffstat (limited to 'newlib/libc/stdlib')
-rw-r--r-- | newlib/libc/stdlib/gdtoa-gdtoa.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/newlib/libc/stdlib/gdtoa-gdtoa.c b/newlib/libc/stdlib/gdtoa-gdtoa.c index da2338c..d29a81e 100644 --- a/newlib/libc/stdlib/gdtoa-gdtoa.c +++ b/newlib/libc/stdlib/gdtoa-gdtoa.c @@ -261,7 +261,7 @@ gdtoa dval(d) *= 1 << j1; word0(d) += j << Exp_shift - 2 & Exp_mask; #else - word0(d) += (be + bbits - 1) << Exp_shift; + word0(d) += (__ULong)(be + bbits - 1) << Exp_shift; #endif if (k >= 0 && k <= Ten_pmax) { if (dval(d) < tens[k]) |