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
PICFLAG = -fPIC
C99FLAG = -std=c99
WCFLAGS = -Wall -pedantic
WCFLAGS = -Wall -Wextra -pedantic
UCFLAGS = $(CPPFLAGS) $(CFLAGS) $(PICFLAG) $(C99FLAG) $(WCFLAGS) -DUTF8PROC_EXPORTS $(UTF8PROC_DEFINES)
LDFLAG_SHARED = -shared
SOFLAG = -Wl,-soname

View File

@ -2,7 +2,7 @@
int main(int argc, char **argv)
{
char buf[8192];
unsigned char buf[8192];
FILE *f = argc > 1 ? fopen(argv[1], "r") : NULL;
utf8proc_uint8_t src[1024];
@ -18,18 +18,18 @@ int main(int argc, char **argv)
while (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++] = '/';
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;
}
else if (buf[bi] == '#') { /* start of comments */
break;
}
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 */
bi += len;
}

View File

@ -35,6 +35,8 @@ int main(int argc, char **argv)
uint32_t byt;
unsigned char buf[16];
(void) argc; (void) argv; /* unused */
tests = error = 0;
// Check valid sequences that were considered valid erroneously before

View File

@ -1,17 +1,17 @@
#include "tests.h"
#define CHECK_NORM(NRM, norm, src) { \
char *src_norm = (char*) utf8proc_ ## NRM((utf8proc_uint8_t*) src); \
check(!strcmp(norm, src_norm), \
unsigned char *src_norm = (unsigned char*) utf8proc_ ## NRM((utf8proc_uint8_t*) src); \
check(!strcmp((char *) norm, (char *) src_norm), \
"normalization failed for %s -> %s", src, norm); \
free(src_norm); \
}
int main(int argc, char **argv)
{
char buf[8192];
unsigned char buf[8192];
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");
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;
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
[0-9a-fA-F] or whitespace, then stores the corresponding utf8 string
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;
for (;;) {
@ -39,19 +39,19 @@ size_t encode(char *dest, const char *buf)
dest[d] = 0; /* NUL-terminate destination string */
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 */
d += utf8proc_encode_char(c, (utf8proc_uint8_t *) (dest + d));
}
}
/* 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;
while (i < 8191) {
int c = getc(f);
if (c == EOF || c == '\n') break;
buf[i++] = (char) ((uint8_t) c);
buf[i++] = (unsigned char) c;
}
buf[i] = 0;
return i;

View File

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