scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit dd5135d1d9219d10651a14038ea2bbd1b1fe1c13
parent 09f7db04a294e858a3049bc719bf66af41452806
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Wed, 16 Mar 2022 13:31:26 +0100

libc: Fix signess of pointer in mbtowc()

We have to access the elements of the char array using
an unsigned pointer, because otherwise we can have
sign extension that can modify the behaviour of the
function.

Diffstat:
Msrc/libc/stdlib/mbtowc.c | 6++++--
1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/libc/stdlib/mbtowc.c b/src/libc/stdlib/mbtowc.c @@ -5,7 +5,7 @@ int mbtowc(wchar_t *restrict pwc, const char *restrict s, size_t n) { - const char *t = s; + unsigned char *t = (unsigned char *) s; unsigned long wc; unsigned c; size_t len; @@ -30,5 +30,7 @@ mbtowc(wchar_t *restrict pwc, const char *restrict s, size_t n) return_code: if (pwc) *pwc = wc; - return (*s) ? t - s : 0; + if (*s == '\0') + return 0; + return t - (unsigned char *) s; }