use unsigned char more consistently, silence -Wextra compiler warnings (#188)

This commit is contained in:
Steven G. Johnson 2020-03-29 10:44:42 -04:00 committed by GitHub
parent 243875b456
commit c6858e955c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 18 deletions

View File

@ -11,7 +11,7 @@ PERL=perl
CFLAGS ?= -O2 CFLAGS ?= -O2
PICFLAG = -fPIC PICFLAG = -fPIC
C99FLAG = -std=c99 C99FLAG = -std=c99
WCFLAGS = -Wall -pedantic WCFLAGS = -Wall -Wextra -pedantic
UCFLAGS = $(CPPFLAGS) $(CFLAGS) $(PICFLAG) $(C99FLAG) $(WCFLAGS) -DUTF8PROC_EXPORTS $(UTF8PROC_DEFINES) UCFLAGS = $(CPPFLAGS) $(CFLAGS) $(PICFLAG) $(C99FLAG) $(WCFLAGS) -DUTF8PROC_EXPORTS $(UTF8PROC_DEFINES)
LDFLAG_SHARED = -shared LDFLAG_SHARED = -shared
SOFLAG = -Wl,-soname SOFLAG = -Wl,-soname

View File

@ -2,7 +2,7 @@
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
char buf[8192]; unsigned char buf[8192];
FILE *f = argc > 1 ? fopen(argv[1], "r") : NULL; FILE *f = argc > 1 ? fopen(argv[1], "r") : NULL;
utf8proc_uint8_t src[1024]; utf8proc_uint8_t src[1024];
@ -18,18 +18,18 @@ int main(int argc, char **argv)
while (buf[bi]) { while (buf[bi]) {
bi = skipspaces(buf, bi); bi = skipspaces(buf, bi);
if ((uint8_t)buf[bi] == 0xc3 && (uint8_t)buf[bi+1] == 0xb7) { /* U+00f7 = grapheme break */ if (buf[bi] == 0xc3 && buf[bi+1] == 0xb7) { /* U+00f7 = grapheme break */
src[si++] = '/'; src[si++] = '/';
bi += 2; bi += 2;
} }
else if ((uint8_t)buf[bi] == 0xc3 && (uint8_t)buf[bi+1] == 0x97) { /* U+00d7 = no break */ else if (buf[bi] == 0xc3 && buf[bi+1] == 0x97) { /* U+00d7 = no break */
bi += 2; bi += 2;
} }
else if (buf[bi] == '#') { /* start of comments */ else if (buf[bi] == '#') { /* start of comments */
break; break;
} }
else { /* hex-encoded codepoint */ else { /* hex-encoded codepoint */
size_t len = encode((char*) (src + si), buf + bi) - 1; size_t len = encode((unsigned char*) (src + si), buf + bi) - 1;
while (src[si]) ++si; /* advance to NUL termination */ while (src[si]) ++si; /* advance to NUL termination */
bi += len; bi += len;
} }

View File

@ -35,6 +35,8 @@ int main(int argc, char **argv)
uint32_t byt; uint32_t byt;
unsigned char buf[16]; unsigned char buf[16];
(void) argc; (void) argv; /* unused */
tests = error = 0; tests = error = 0;
// Check valid sequences that were considered valid erroneously before // Check valid sequences that were considered valid erroneously before
@ -54,7 +56,7 @@ int main(int argc, char **argv)
CHECKVALID(3, 0xbe, 4); CHECKVALID(3, 0xbe, 4);
CHECKVALID(3, 0xbf, 4); CHECKVALID(3, 0xbf, 4);
} }
// Continuation byte not after lead // Continuation byte not after lead
for (byt = 0x80; byt < 0xc0; byt++) { for (byt = 0x80; byt < 0xc0; byt++) {
CHECKINVALID(0, byt, 1); CHECKINVALID(0, byt, 1);

View File

@ -1,17 +1,17 @@
#include "tests.h" #include "tests.h"
#define CHECK_NORM(NRM, norm, src) { \ #define CHECK_NORM(NRM, norm, src) { \
char *src_norm = (char*) utf8proc_ ## NRM((utf8proc_uint8_t*) src); \ unsigned char *src_norm = (unsigned char*) utf8proc_ ## NRM((utf8proc_uint8_t*) src); \
check(!strcmp(norm, src_norm), \ check(!strcmp((char *) norm, (char *) src_norm), \
"normalization failed for %s -> %s", src, norm); \ "normalization failed for %s -> %s", src, norm); \
free(src_norm); \ free(src_norm); \
} }
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
char buf[8192]; unsigned char buf[8192];
FILE *f = argc > 1 ? fopen(argv[1], "r") : NULL; FILE *f = argc > 1 ? fopen(argv[1], "r") : NULL;
char source[1024], NFC[1024], NFD[1024], NFKC[1024], NFKD[1024]; unsigned char source[1024], NFC[1024], NFD[1024], NFKC[1024], NFKD[1024];
check(f != NULL, "error opening NormalizationTest.txt"); check(f != NULL, "error opening NormalizationTest.txt");
while (simple_getline(buf, f) > 0) { while (simple_getline(buf, f) > 0) {

View File

@ -17,7 +17,7 @@ void check(int cond, const char *format, ...)
} }
} }
size_t skipspaces(const char *buf, size_t i) size_t skipspaces(const unsigned char *buf, size_t i)
{ {
while (isspace(buf[i])) ++i; while (isspace(buf[i])) ++i;
return i; return i;
@ -27,7 +27,7 @@ size_t skipspaces(const char *buf, size_t i)
separated by whitespace, and terminated by any character not in separated by whitespace, and terminated by any character not in
[0-9a-fA-F] or whitespace, then stores the corresponding utf8 string [0-9a-fA-F] or whitespace, then stores the corresponding utf8 string
in dest, returning the number of bytes read from buf */ in dest, returning the number of bytes read from buf */
size_t encode(char *dest, const char *buf) size_t encode(unsigned char *dest, const unsigned char *buf)
{ {
size_t i = 0, j, d = 0; size_t i = 0, j, d = 0;
for (;;) { for (;;) {
@ -39,19 +39,19 @@ size_t encode(char *dest, const char *buf)
dest[d] = 0; /* NUL-terminate destination string */ dest[d] = 0; /* NUL-terminate destination string */
return i + 1; return i + 1;
} }
check(sscanf(buf + i, "%x", (unsigned int *)&c) == 1, "invalid hex input %s", buf+i); check(sscanf((char *) (buf + i), "%x", (unsigned int *)&c) == 1, "invalid hex input %s", buf+i);
i = j; /* skip to char after hex input */ i = j; /* skip to char after hex input */
d += utf8proc_encode_char(c, (utf8proc_uint8_t *) (dest + d)); d += utf8proc_encode_char(c, (utf8proc_uint8_t *) (dest + d));
} }
} }
/* simplistic, portable replacement for getline, sufficient for our tests */ /* simplistic, portable replacement for getline, sufficient for our tests */
size_t simple_getline(char buf[8192], FILE *f) { size_t simple_getline(unsigned char buf[8192], FILE *f) {
size_t i = 0; size_t i = 0;
while (i < 8191) { while (i < 8191) {
int c = getc(f); int c = getc(f);
if (c == EOF || c == '\n') break; if (c == EOF || c == '\n') break;
buf[i++] = (char) ((uint8_t) c); buf[i++] = (unsigned char) c;
} }
buf[i] = 0; buf[i] = 0;
return i; return i;

View File

@ -22,6 +22,6 @@
extern size_t lineno; extern size_t lineno;
void check(int cond, const char *format, ...); void check(int cond, const char *format, ...);
size_t skipspaces(const char *buf, size_t i); size_t skipspaces(const unsigned char *buf, size_t i);
size_t encode(char *dest, const char *buf); size_t encode(unsigned char *dest, const unsigned char *buf);
size_t simple_getline(char buf[8192], FILE *f); size_t simple_getline(unsigned char buf[8192], FILE *f);