isspace etc and (int) typecast

From: Henrik Nordstrom <>
Date: Tue, 27 Mar 2007 02:56:08 +0200

Reviewing Squid-2.HEAD changes and sorting/grouping them a bit I
stumbled over your change to add casts in various isspace() calls which
looks a bit odd.

- for (; i < hmsg->req_end && (isspace(hmsg->buf[i])); i++);
+ for (; i < hmsg->req_end && (isspace((int) hmsg->buf[i])); i++);

Generally this is not a safe cast. The ctype family of functions want
the same kind of "C character" as returned by getchar etc. That's an
integer carrying an unsigned char or -1.

As it's a very common coding error most C libraries accept char input to
these functions and might even produce correct results on high octets,
but not all (some may even segfault).

What was the warnings you fixed with these casts? I suspect you only
silenced a valid warning here without fixing the cause..


Received on Mon Mar 26 2007 - 18:56:14 MDT

This archive was generated by hypermail pre-2.1.9 : Sun Apr 01 2007 - 12:00:01 MDT