diff options
author | Matt <ukyg9e5r6k7gubiekd6@yahoo.com> | 2014-09-10 01:09:43 +1000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2014-09-10 09:10:02 -0400 |
commit | 280d52b7d78ad2ba695f5f6faa61f0679c447f3c (patch) | |
tree | 1159db868a8f914f9b5567473a6059f04f2fe974 | |
parent | 60583e9ee10b778934452845f004b94ce5c74205 (diff) | |
download | gpsd-280d52b7d78ad2ba695f5f6faa61f0679c447f3c.tar.gz |
Silence compiler warnings about array subscripts of type 'char'
Cygwin GCC complains about code like isprint(c), where c is of type char.
The isX() and toX() functions/macros (ISO C allows either) all accept an
int, whose value should be either that of an unsigned char, or the
special value EOF (== -1).
So cast to unsigned char each argument to isprint, tolower, etc.
Silences several warnings of the form:
gpsutils.c: In function 'safe_atof':
gpsutils.c:90:5: warning: array subscript has type 'char'
[-Wchar-subscripts]
while (isspace(*p)) {
^
gpsutils.c:188:2: warning: array subscript has type 'char'
[-Wchar-subscripts]
while (isdigit(*p)) {
^
-rw-r--r-- | gpsd.c | 14 | ||||
-rw-r--r-- | gpsmon.c | 10 | ||||
-rw-r--r-- | gpsutils.c | 4 | ||||
-rw-r--r-- | hex.c | 2 | ||||
-rw-r--r-- | json.c | 22 | ||||
-rw-r--r-- | libgpsd_core.c | 2 | ||||
-rw-r--r-- | packet.c | 6 |
7 files changed, 30 insertions, 30 deletions
@@ -605,7 +605,7 @@ static ssize_t throttled_write(struct subscriber_t *sub, char *buf, ssize_t status; if (context.errout.debug >= LOG_CLIENT) { - if (isprint(buf[0])) + if (isprint((unsigned char) buf[0])) gpsd_report(&context.errout, LOG_CLIENT, "=> client(%d): %s\n", sub_index(sub), buf); else { @@ -782,7 +782,7 @@ bool gpsd_add_device(const char *device_name, bool flag_nowait) static char stash[BUFSIZ]; /*@ -temptrans -mayaliasunique @*/ - for (q = p; isprint(*p) && !isspace(*p) && /*@i@*/ (p - q < BUFSIZ - 1); + for (q = p; isprint((unsigned char) *p) && !isspace((unsigned char) *p) && /*@i@*/ (p - q < BUFSIZ - 1); p++) continue; (void)memcpy(stash, q, (size_t) (p - q)); @@ -1002,12 +1002,12 @@ static void set_serial(struct gps_device_t *device, int wordsize = 8; if (strchr("78", *modestring) != NULL) { - while (isspace(*modestring)) + while (isspace((unsigned char) *modestring)) modestring++; wordsize = (int)(*modestring++ - '0'); if (strchr("NOE", *modestring) != NULL) { parity = *modestring++; - while (isspace(*modestring)) + while (isspace((unsigned char) *modestring)) modestring++; if (strchr("12", *modestring) != NULL) stopbits = (unsigned int)(*modestring - '0'); @@ -1077,7 +1077,7 @@ static void rstrip(char *str) { char *strend; strend = str + strlen(str) - 1; - while (isspace(*strend)) { + while (isspace((unsigned char) *strend)) { *strend = '\0'; --strend; } @@ -1360,7 +1360,7 @@ static void handle_request(struct subscriber_t *sub, } else { const char *errend; errend = buf + strlen(buf) - 1; - while (isspace(*errend) && errend > buf) + while (isspace((unsigned char) *errend) && errend > buf) --errend; (void)snprintf(reply, replylen, "{\"class\":\"ERROR\",\"message\":\"Unrecognized request '%.*s'\"}\r\n", @@ -1662,7 +1662,7 @@ static int handle_gpsd_request(struct subscriber_t *sub, const char *buf) if (buf[0] == '?') { const char *end; for (end = buf; *buf != '\0'; buf = end) - if (isspace(*buf)) + if (isspace((unsigned char) *buf)) end = buf + 1; else handle_request(sub, buf, &end, @@ -170,7 +170,7 @@ static void visibilize(/*@out@*/char *buf2, size_t len2, const char *buf) buf2[0] = '\0'; for (sp = buf; *sp != '\0' && strlen(buf2)+4 < len2; sp++) - if (isprint(*sp) || (sp[0] == '\n' && sp[1] == '\0') + if (isprint((unsigned char) *sp) || (sp[0] == '\n' && sp[1] == '\0') || (sp[0] == '\r' && sp[2] == '\0')) (void)snprintf(buf2 + strlen(buf2), 2, "%c", *sp); else @@ -186,12 +186,12 @@ static void cond_hexdump(/*@out@*/char *buf2, size_t len2, size_t i; bool printable = true; for (i = 0; i < len; i++) - if (!isprint(buf[i]) && !isspace(buf[i])) + if (!isprint((unsigned char) buf[i]) && !isspace((unsigned char) buf[i])) printable = false; if (printable) { size_t j; for (i = j = 0; i < len && j < len2 - 1; i++) - if (isprint(buf[i])) { + if (isprint((unsigned char) buf[i])) { buf2[j++] = buf[i]; buf2[j] = '\0'; } @@ -750,8 +750,8 @@ static bool do_command(const char *line) unsigned char buf[BUFLEN]; const char *arg; - if (isspace(line[1])) { - for (arg = line + 2; *arg != '\0' && isspace(*arg); arg++) + if (isspace((unsigned char) line[1])) { + for (arg = line + 2; *arg != '\0' && isspace((unsigned char) *arg); arg++) arg++; arg++; } else @@ -87,7 +87,7 @@ double safe_atof(const char *string) */ p = string; - while (isspace(*p)) { + while (isspace((unsigned char) *p)) { p += 1; } if (*p == '-') { @@ -185,7 +185,7 @@ double safe_atof(const char *string) } expSign = false; } - while (isdigit(*p)) { + while (isdigit((unsigned char) *p)) { exp = exp * 10 + (*p - '0'); p += 1; } @@ -17,7 +17,7 @@ const char /*@ observer @*/ *gpsd_packetdump(char *scbuf, size_t scbuflen, assert(binbuf != NULL); for (cp = binbuf; cp < binbuf + binbuflen; cp++) - if (!isprint(*cp) && !isspace(*cp)) + if (!isprint((unsigned char) *cp) && !isspace((unsigned char) *cp)) printable = false; if (printable) return binbuf; @@ -235,7 +235,7 @@ static int json_internal_read_object(const char *cp, statenames[state], *cp, cp)); switch (state) { case init: - if (isspace(*cp)) + if (isspace((unsigned char) *cp)) continue; else if (*cp == '{') state = await_attr; @@ -246,7 +246,7 @@ static int json_internal_read_object(const char *cp, } break; case await_attr: - if (isspace(*cp)) + if (isspace((unsigned char) *cp)) continue; else if (*cp == '"') { state = in_attr; @@ -294,7 +294,7 @@ static int json_internal_read_object(const char *cp, *pattr++ = *cp; break; case await_value: - if (isspace(*cp) || *cp == ':') + if (isspace((unsigned char) *cp) || *cp == ':') continue; else if (*cp == '[') { if (cursor->type != t_array) { @@ -372,7 +372,7 @@ static int json_internal_read_object(const char *cp, case in_val_token: if (pval == NULL) return JSON_ERR_NULLPTR; - if (isspace(*cp) || *cp == ',' || *cp == '}') { + if (isspace((unsigned char) *cp) || *cp == ',' || *cp == '}') { *pval = '\0'; json_debug_trace((1, "Collected token value %s.\n", valbuf)); state = post_val; @@ -400,7 +400,7 @@ static int json_internal_read_object(const char *cp, if ((strcmp(valbuf, "true")==0 || strcmp(valbuf, "false")==0) && seeking == t_boolean) break; - if (isdigit(valbuf[0])) { + if (isdigit((unsigned char) valbuf[0])) { bool decimal = strchr(valbuf, '.') != NULL; if (decimal && seeking == t_real) break; @@ -501,7 +501,7 @@ static int json_internal_read_object(const char *cp, } /*@fallthrough@*/ case post_array: - if (isspace(*cp)) + if (isspace((unsigned char) *cp)) continue; else if (*cp == ',') state = await_attr; @@ -518,7 +518,7 @@ static int json_internal_read_object(const char *cp, good_parse: /* in case there's another object following, consune trailing WS */ - while (isspace(*cp)) + while (isspace((unsigned char) *cp)) ++cp; if (end != NULL) *end = cp; @@ -539,7 +539,7 @@ int json_read_array(const char *cp, const struct json_array_t *arr, json_debug_trace((1, "Entered json_read_array()\n")); - while (isspace(*cp)) + while (isspace((unsigned char) *cp)) cp++; if (*cp != '[') { json_debug_trace((1, "Didn't find expected array start\n")); @@ -551,7 +551,7 @@ int json_read_array(const char *cp, const struct json_array_t *arr, arrcount = 0; /* Check for empty array */ - while (isspace(*cp)) + while (isspace((unsigned char) *cp)) cp++; if (*cp == ']') goto breakout; @@ -560,7 +560,7 @@ int json_read_array(const char *cp, const struct json_array_t *arr, json_debug_trace((1, "Looking at %s\n", cp)); switch (arr->element_type) { case t_string: - if (isspace(*cp)) + if (isspace((unsigned char) *cp)) cp++; if (*cp != '"') return JSON_ERR_BADSTRING; @@ -605,7 +605,7 @@ int json_read_array(const char *cp, const struct json_array_t *arr, return JSON_ERR_SUBTYPE; } arrcount++; - if (isspace(*cp)) + if (isspace((unsigned char) *cp)) cp++; if (*cp == ']') { json_debug_trace((1, "End of array found.\n")); diff --git a/libgpsd_core.c b/libgpsd_core.c index 3e2a0f25..bec2ddc1 100644 --- a/libgpsd_core.c +++ b/libgpsd_core.c @@ -79,7 +79,7 @@ static void visibilize(/*@out@*/char *buf2, size_t len, const char *buf) buf2[0] = '\0'; for (sp = buf; *sp != '\0' && strlen(buf2)+4 < len; sp++) - if (isprint(*sp) || (sp[0] == '\n' && sp[1] == '\0') + if (isprint((unsigned char) *sp) || (sp[0] == '\n' && sp[1] == '\0') || (sp[0] == '\r' && sp[2] == '\0')) (void)snprintf(buf2 + strlen(buf2), 2, "%c", *sp); else @@ -1500,7 +1500,7 @@ void packet_parse(struct gps_lexer_t *lexer) * Back up past any whitespace. Need to do this because * at least one GPS (the Firefly 1a) emits \r\r\n */ - for (end = (char *)lexer->inbufptr - 1; isspace(*end); end--) + for (end = (char *)lexer->inbufptr - 1; isspace((unsigned char) *end); end--) continue; while (strchr("0123456789ABCDEF", *end)) --end; @@ -1509,8 +1509,8 @@ void packet_parse(struct gps_lexer_t *lexer) for (n = 1; (char *)lexer->inbuffer + n < end; n++) crc ^= lexer->inbuffer[n]; (void)snprintf(csum, sizeof(csum), "%02X", crc); - checksum_ok = (csum[0] == toupper(end[1]) - && csum[1] == toupper(end[2])); + checksum_ok = (csum[0] == toupper((unsigned char) end[1]) + && csum[1] == toupper((unsigned char) end[2])); } if (!checksum_ok) { gpsd_report(&lexer->errout, LOG_WARN, |