Skip to content

Commit 7f88bbe

Browse files
alarixniacorecode
authored andcommitted
ctype: Cast arguments to unsigned char
Eliminates a warning about char subscripts on NetBSD. The argument of these functions is of type int, but only a very restricted subset of values are actually valid. The argument must either be the value of the macro EOF (which has a negative value), or must be a non-negative value within the range representable as unsigned char. Passing invalid values leads to undefined behavior. Signed-off-by: Nia Alarie <nia@NetBSD.org>
1 parent f52ebb4 commit 7f88bbe

3 files changed

Lines changed: 6 additions & 4 deletions

File tree

net.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ read_remote(int fd, int extbufsize, char *extbuf)
201201
switch (parsestate) {
202202
case parse_status:
203203
for (; pos < len; pos++) {
204-
if (isdigit(buff[pos])) {
204+
if (isdigit((unsigned char)buff[pos])) {
205205
status_running = status_running * 10 + (buff[pos] - '0');
206206
} else {
207207
status = status_running;

spool.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ readqueuef(struct queue *queue, char *queuefn)
181181
*s = 0;
182182

183183
s++;
184-
while (isspace(*s))
184+
while (isspace((unsigned char)*s))
185185
s++;
186186

187187
s = strdup(s);

util.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,8 @@ hostname(void)
8383
if (s == NULL)
8484
goto local;
8585

86-
for (s = name; *s != 0 && (isalnum(*s) || strchr("_.-", *s)); ++s)
86+
for (s = name; *s != 0
87+
&& (isalnum((unsigned char)*s) || strchr("_.-", *s)); ++s)
8788
/* NOTHING */;
8889
*s = 0;
8990

@@ -126,7 +127,8 @@ systemhostname(void)
126127
*/
127128
name[sizeof(name) - 1] = 0;
128129

129-
for (s = name; *s != 0 && (isalnum(*s) || strchr("_.-", *s)); ++s)
130+
for (s = name; *s != 0 &&
131+
(isalnum((unsigned char)*s) || strchr("_.-", *s)); ++s)
130132
/* NOTHING */;
131133
*s = 0;
132134

0 commit comments

Comments
 (0)