From 0bc29c89c13a61806a28f054f04a01afd8242669 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Sat, 1 Jan 2022 20:34:23 -0800 Subject: Remove dependency on signed integer representation --- expr.c | 4 ++-- scan.c | 4 ++-- token.c | 4 ++-- utf.c | 2 +- utf.h | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/expr.c b/expr.c index 5a8086a..e969241 100644 --- a/expr.c +++ b/expr.c @@ -365,7 +365,7 @@ decodechar(const char *src, uint_least32_t *chr, bool *hexoct, const char *desc, uint_least32_t c; size_t n; int i; - const char *s = src; + const unsigned char *s = (const unsigned char *)src; if (*s == '\\') { ++s; @@ -406,7 +406,7 @@ decodechar(const char *src, uint_least32_t *chr, bool *hexoct, const char *desc, s += n; } *chr = c; - return s - src; + return s - (const unsigned char *)src; } static size_t diff --git a/scan.c b/scan.c index bd0435c..0e6e7b1 100644 --- a/scan.c +++ b/scan.c @@ -9,7 +9,7 @@ #include "cc.h" struct buffer { - char *str; + unsigned char *str; size_t len, cap; }; @@ -26,7 +26,7 @@ struct scanner { static struct scanner *scanner; static void -bufadd(struct buffer *b, char c) +bufadd(struct buffer *b, int c) { if (b->len >= b->cap) { b->cap = b->cap ? b->cap * 2 : 1<<8; diff --git a/token.c b/token.c index ae31ac4..6e80ff4 100644 --- a/token.c +++ b/token.c @@ -161,8 +161,8 @@ tokendesc(char *buf, size_t len, enum tokenkind kind, const char *lit) snprintf(buf, len, quote ? "%s '%s'" : "%s %s", class, lit); else if (class) snprintf(buf, len, "%s", class); - else if (kind == TOTHER && !isprint(lit[0])) - snprintf(buf, len, "", lit[0]); + else if (kind == TOTHER && !isprint(*(unsigned char *)lit)) + snprintf(buf, len, "", *(unsigned char *)lit); else if (lit) snprintf(buf, len, "'%s'", lit); else diff --git a/utf.c b/utf.c index 7891f7e..f6cefcd 100644 --- a/utf.c +++ b/utf.c @@ -33,7 +33,7 @@ utf8enc(unsigned char *s, uint_least32_t c) } size_t -utf8dec(uint_least32_t *c, const char *s, size_t n) +utf8dec(uint_least32_t *c, const unsigned char *s, size_t n) { size_t i, l; unsigned char b; diff --git a/utf.h b/utf.h index 77bd175..bbaeaf7 100644 --- a/utf.h +++ b/utf.h @@ -1,3 +1,3 @@ size_t utf8enc(unsigned char *, uint_least32_t); -size_t utf8dec(uint_least32_t *, const char *, size_t); +size_t utf8dec(uint_least32_t *, const unsigned char *, size_t); size_t utf16enc(uint_least16_t *, uint_least32_t); -- cgit v1.2.3