fix all implicit conversion between signed/unsigned pointers
authorRich Felker <dalias@aerifal.cx>
Fri, 25 Mar 2011 20:34:03 +0000 (16:34 -0400)
committerRich Felker <dalias@aerifal.cx>
Fri, 25 Mar 2011 20:34:03 +0000 (16:34 -0400)
sadly the C language does not specify any such implicit conversion, so
this is not a matter of just fixing warnings (as gcc treats it) but
actual errors. i would like to revisit a number of these changes and
possibly revise the types used to reduce the number of casts required.

19 files changed:
src/locale/iconv.c
src/misc/crypt.c
src/multibyte/mbrtowc.c
src/network/getaddrinfo.c
src/signal/siglongjmp.c
src/stdio/fputwc.c
src/stdio/ungetwc.c
src/stdio/vdprintf.c
src/stdio/vfprintf.c
src/stdio/vsnprintf.c
src/stdio/vswprintf.c
src/stdlib/strtold.c
src/stdlib/strtoumax.c
src/string/strcasecmp.c
src/string/strcspn.c
src/string/strncasecmp.c
src/string/strncmp.c
src/string/strspn.c
src/string/strstr.c

index ce2c364..f9f8017 100644 (file)
@@ -283,7 +283,7 @@ static const unsigned char charmaps[] =
 
 
 
-static int fuzzycmp(const char *a, const char *b)
+static int fuzzycmp(const unsigned char *a, const unsigned char *b)
 {
        for (; *a && *b; a++, b++) {
                while (*a && (*a|32U)-'a'>26 && *a-'0'>10U) a++;
@@ -292,15 +292,15 @@ static int fuzzycmp(const char *a, const char *b)
        return *a != *b;
 }
 
-static size_t find_charmap(const char *name)
+static size_t find_charmap(const void *name)
 {
        const unsigned char *s;
        for (s=charmaps; *s; ) {
                if (!fuzzycmp(name, s)) {
-                       for (; *s; s+=strlen(s)+1);
+                       for (; *s; s+=strlen((void *)s)+1);
                        return s+1-charmaps;
                }
-               s += strlen(s)+1;
+               s += strlen((void *)s)+1;
                if (!*s) s += ((128-s[2])*s[1]+7)/8 + 3;
        }
        return -1;
@@ -440,7 +440,7 @@ size_t iconv(iconv_t cd0, char **in, size_t *inb, char **out, size_t *outb)
                case UTF_32LE:
                        l = 4;
                        if (*inb < 4) goto starved;
-                       c = get_32(*in, type);
+                       c = get_32((void *)*in, type);
                        }
                        if (c-0xd800u < 0x800u || c >= 0x110000u) goto ilseq;
                        break;
@@ -450,13 +450,13 @@ size_t iconv(iconv_t cd0, char **in, size_t *inb, char **out, size_t *outb)
                case UTF_16LE:
                        l = 2;
                        if (*inb < 2) goto starved;
-                       c = get_16(*in, type);
+                       c = get_16((void *)*in, type);
                        if ((unsigned)(c-0xdc00) < 0x400) goto ilseq;
                        if ((unsigned)(c-0xd800) < 0x400) {
                                if (type-UCS2BE < 2U) goto ilseq;
                                l = 4;
                                if (*inb < 4) goto starved;
-                               d = get_16(*in + 2, from);
+                               d = get_16((void *)(*in + 2), from);
                                if ((unsigned)(c-0xdc00) >= 0x400) goto ilseq;
                                c = ((c-0xd800)<<10) | (d-0xdc00);
                        }
@@ -531,22 +531,22 @@ size_t iconv(iconv_t cd0, char **in, size_t *inb, char **out, size_t *outb)
                case UTF_16LE:
                        if (c < 0x10000) {
                                if (*outb < 2) goto toobig;
-                               put_16(*out, c, totype);
+                               put_16((void *)*out, c, totype);
                                *out += 2;
                                *outb -= 2;
                                break;
                        }
                        if (type-UCS2BE < 2U) goto ilseq;
                        if (*outb < 4) goto toobig;
-                       put_16(*out, (c>>10)|0xd800, totype);
-                       put_16(*out + 2, (c&0x3ff)|0xdc00, totype);
+                       put_16((void *)*out, (c>>10)|0xd800, totype);
+                       put_16((void *)(*out + 2), (c&0x3ff)|0xdc00, totype);
                        *out += 4;
                        *outb -= 4;
                        break;
                case UTF_32BE:
                case UTF_32LE:
                        if (*outb < 4) goto toobig;
-                       put_32(*out, c, totype);
+                       put_32((void *)*out, c, totype);
                        *out += 4;
                        *outb -= 4;
                        break;
index 42918ef..f50aadf 100644 (file)
@@ -2488,7 +2488,7 @@ des_crypt(struct des_ctx *ctx, char output[DES_OUT_BUFSIZE],
                        key++;
                q++;
        }
-       des_setkey(ctx, (char *)keybuf);
+       des_setkey(ctx, (void *)keybuf);
 
        /*
         * setting - 2 bytes of salt
@@ -2566,7 +2566,7 @@ char *__crypt_r(const char *clear, const char *salt, struct crypt_data *data)
 #endif
 
        des_init(&des_ctx);
-       return des_crypt(&des_ctx, (char *)data, clear, salt);
+       return des_crypt(&des_ctx, (char *)data, (void *)clear, (void *)salt);
 }
 
 weak_alias(__crypt_r, crypt_r);
index a354573..291537f 100644 (file)
@@ -22,7 +22,7 @@ size_t mbrtowc(wchar_t *wc, const char *src, size_t n, mbstate_t *st)
        c = *(unsigned *)st;
        
        if (!s) {
-               s = "";
+               s = (void *)"";
                wc = (void *)&wc;
                n = 1;
        } else if (!wc) wc = (void *)&wc;
index 90e85f6..8126236 100644 (file)
@@ -13,7 +13,7 @@ static int is_valid(const char *host)
 {
        const unsigned char *s;
        if (strlen(host)-1 > 254 || mbstowcs(0, host, 0) > 255) return 0;
-       for (s=host; *s>=0x80 || *s=='.' || *s=='-' || isalnum(*s); s++);
+       for (s=(void *)host; *s>=0x80 || *s=='.' || *s=='-' || isalnum(*s); s++);
        return !*s;
 }
 
index 33ac30e..1712917 100644 (file)
@@ -4,7 +4,7 @@
 
 void siglongjmp(sigjmp_buf buf, int ret)
 {
-       long *flag = buf + sizeof(jmp_buf)/sizeof(long);
+       unsigned long *flag = buf + sizeof(jmp_buf)/sizeof(long);
        sigset_t *mask = (void *)(flag + 1);
        if (*flag)
                sigprocmask (SIG_SETMASK, mask, NULL);
index b48bb74..ec49b5c 100644 (file)
@@ -11,12 +11,12 @@ wint_t __fputwc_unlocked(wchar_t c, FILE *f)
                if (c != f->lbf && f->wpos + 1 < f->wend) *f->wpos++ = c;
                else c = __overflow(f, c);
        } else if (f->wpos + MB_LEN_MAX < f->wend) {
-               l = wctomb(f->wpos, c);
+               l = wctomb((void *)f->wpos, c);
                if (l < 0) c = WEOF;
                else f->wpos += l;
        } else {
                l = wctomb(mbc, c);
-               if (l < 0 || __fwritex(mbc, l, f) < l) c = WEOF;
+               if (l < 0 || __fwritex((void *)mbc, l, f) < l) c = WEOF;
        }
        return c;
 }
index f7cde2e..6871d03 100644 (file)
@@ -8,7 +8,7 @@ wint_t ungetwc(wint_t c, FILE *f)
        if (c == WEOF) return c;
 
        /* Try conversion early so we can fail without locking if invalid */
-       if (!isascii(c) && (l = wctomb(mbc, c)) < 0)
+       if (!isascii(c) && (l = wctomb((void *)mbc, c)) < 0)
                return WEOF;
 
        FLOCK(f);
index 35ed6e0..68562e0 100644 (file)
@@ -8,7 +8,7 @@ static size_t wrap_write(FILE *f, const unsigned char *buf, size_t len)
 int vdprintf(int fd, const char *fmt, va_list ap)
 {
        int r;
-       char buf[BUFSIZ];
+       unsigned char buf[BUFSIZ];
        FILE f = {
                .fd = fd, .lbf = EOF, .write = wrap_write,
                .buf = buf+UNGET, .buf_size = sizeof buf - UNGET
index 19afd6c..b6bb3bc 100644 (file)
@@ -149,7 +149,7 @@ static void pop_arg(union arg *arg, int type, va_list *ap)
 
 static void out(FILE *f, const char *s, size_t l)
 {
-       __fwritex(s, l, f);
+       __fwritex((void *)s, l, f);
 }
 
 static void pad(FILE *f, char c, int w, int l, int fl)
index 5d3f0c5..1f316ca 100644 (file)
@@ -23,8 +23,8 @@ int vsnprintf(char *s, size_t n, const char *fmt, va_list ap)
                return -1;
        } else if (n > 0) {
                if (n > (char *)0+SIZE_MAX-s) n = (char *)0+SIZE_MAX-s;
-               f.wpos = s;
-               f.wbase = f.wend = s+n-1;
+               f.wpos = (void *)s;
+               f.wbase = f.wend = (void *)(s+n-1);
                f.wstop = f.wend - 1;
        }
        r = vfprintf(&f, fmt, ap);
index 31ea187..2d9f200 100644 (file)
@@ -10,7 +10,7 @@ static size_t sw_write(FILE *f, const unsigned char *s, size_t l)
        size_t l0 = l;
        int i = 0;
        struct cookie *c = f->cookie;
-       while (c->l && l && (i=mbtowc(c->ws, s, l))>=0) {
+       while (c->l && l && (i=mbtowc(c->ws, (void *)s, l))>=0) {
                s+=i;
                l-=i;
                c->l--;
index 54f8046..73f2b08 100644 (file)
@@ -4,7 +4,7 @@
 
 long double strtold(const char *s1, char **p)
 {
-       const unsigned char *s = s1;
+       const unsigned char *s = (void *)s1;
        long double x = 0;
        long double frac;
        int sign = 0;
@@ -53,7 +53,7 @@ long double strtold(const char *s1, char **p)
                        }
                }
                if ((*s|32) == 'p') {
-                       e = strtol(s+1, (void *)&s, 10);
+                       e = strtol((void *)(s+1), (void *)&s, 10);
                        for (; e>0; e--) x *= 2.0;
                        for (; e<0; e++) x *= 0.5;
                }
@@ -82,7 +82,7 @@ long double strtold(const char *s1, char **p)
                }
        }
        if ((*s|32)=='e') {
-               e = strtol(++s, (void *)&s, 10);
+               e = strtol((void *)++s, (void *)&s, 10);
                for (; e>0; e--) x *= 10.0;
                for (; e<0; e++) x /= 10.0;
        }
index a529f6e..f190247 100644 (file)
@@ -26,7 +26,7 @@ static const unsigned char digits[] = {
 
 uintmax_t strtoumax(const char *s1, char **p, int base)
 {
-       const unsigned char *s = s1;
+       const unsigned char *s = (void *)s1;
        size_t x1, z1;
        uintmax_t x, z=0;
        int sign = 0;
index dd87905..02fd5f8 100644 (file)
@@ -3,7 +3,7 @@
 
 int strcasecmp(const char *_l, const char *_r)
 {
-       const unsigned char *l=_l, *r=_r;
+       const unsigned char *l=(void *)_l, *r=(void *)_r;
        for (; *l && *r && (*l == *r || tolower(*l) == tolower(*r)); l++, r++);
        return tolower(*l) - tolower(*r);
 }
index 439b7be..c843ff9 100644 (file)
@@ -3,18 +3,16 @@
 #define BITOP(a,b,op) \
  ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a))))
 
-size_t strcspn(const char *_s, const char *_c)
+size_t strcspn(const char *s, const char *c)
 {
-       const unsigned char *s = _s;
-       const unsigned char *c = _c;
-       const unsigned char *a = s;
+       const char *a = s;
        size_t byteset[32/sizeof(size_t)];
 
        if (!c[0]) return strlen(s);
        if (!c[1]) return (s=strchr(s, *c)) ? s-a : strlen(a);
 
        memset(byteset, 0, sizeof byteset);
-       for (; *c && BITOP(byteset, *c, |=); c++);
-       for (; *s && !BITOP(byteset, *s, &); s++);
+       for (; *c && BITOP(byteset, *(unsigned char *)c, |=); c++);
+       for (; *s && !BITOP(byteset, *(unsigned char *)s, &); s++);
        return s-a;
 }
index 4f9230e..2465972 100644 (file)
@@ -3,7 +3,7 @@
 
 int strncasecmp(const char *_l, const char *_r, size_t n)
 {
-       const unsigned char *l=_l, *r=_r;
+       const unsigned char *l=(void *)_l, *r=(void *)_r;
        if (!n--) return 0;
        for (; *l && *r && n && (*l == *r || tolower(*l) == tolower(*r)); l++, r++, n--);
        return tolower(*l) - tolower(*r);
index 52ba032..e228843 100644 (file)
@@ -2,7 +2,7 @@
 
 int strncmp(const char *_l, const char *_r, size_t n)
 {
-       const unsigned char *l=_l, *r=_r;
+       const unsigned char *l=(void *)_l, *r=(void *)_r;
        if (!n--) return 0;
        for (; *l && *r && n && *l == *r ; l++, r++, n--);
        return *l - *r;
index 59b063e..9543dad 100644 (file)
@@ -3,11 +3,9 @@
 #define BITOP(a,b,op) \
  ((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a))))
 
-size_t strspn(const char *_s, const char *_c)
+size_t strspn(const char *s, const char *c)
 {
-       const unsigned char *s = _s;
-       const unsigned char *c = _c;
-       const unsigned char *a = s;
+       const char *a = s;
        size_t byteset[32/sizeof(size_t)] = { 0 };
 
        if (!c[0]) return 0;
@@ -16,7 +14,7 @@ size_t strspn(const char *_s, const char *_c)
                return s-a;
        }
 
-       for (; *c && BITOP(byteset, *c, |=); c++);
-       for (; *s && BITOP(byteset, *s, &); s++);
+       for (; *c && BITOP(byteset, *(unsigned char *)c, |=); c++);
+       for (; *s && BITOP(byteset, *(unsigned char *)s, &); s++);
        return s-a;
 }
index 4d536a7..683cdd0 100644 (file)
@@ -109,7 +109,7 @@ static char *twoway_strstr(const unsigned char *h, const unsigned char *n)
                if (z-h < l) {
                        /* Fast estimate for MIN(l,63) */
                        size_t grow = l | 63;
-                       const char *z2 = memchr(z, 0, grow);
+                       const unsigned char *z2 = memchr(z, 0, grow);
                        if (z2) {
                                z = z2;
                                if (z-h < l) return 0;
@@ -156,11 +156,11 @@ char *strstr(const char *h, const char *n)
        h = strchr(h, *n);
        if (!h || !n[1]) return (char *)h;
        if (!h[1]) return 0;
-       if (!n[2]) return twobyte_strstr(h, n);
+       if (!n[2]) return twobyte_strstr((void *)h, (void *)n);
        if (!h[2]) return 0;
-       if (!n[3]) return threebyte_strstr(h, n);
+       if (!n[3]) return threebyte_strstr((void *)h, (void *)n);
        if (!h[3]) return 0;
-       if (!n[4]) return fourbyte_strstr(h, n);
+       if (!n[4]) return fourbyte_strstr((void *)h, (void *)n);
 
-       return twoway_strstr(h, n);
+       return twoway_strstr((void *)h, (void *)n);
 }