Re: Usage of isspace and friends

From: Antti-Juhani Kaijanaho <antti-juhani@kaijanaho.info>
Date: 2005-10-13 18:29:28
Junio C Hamano wrote:
> Morten Welinder <mwelinder@gmail.com> writes:
>>Since str[9] is of type char it should not be used as a argument to
>>isspace directly,
>>but rather be cast to unsigned char:
>>
>>    ... isspace((unsigned char)str[9]);
> 
> 
> Huh?  isspace is "int isspace(int)".  Presumably standard
> integral promotion rules applies here whether char is signed or
> unsigned, doesn't it?

Of course, but that's not the issue.  isspace treats its parameter as if
it had been converted from unsigned char to int.  If char is signed,
ïsspace will mistreat those characters that have a negative value.
Then again, I don't think a space character, one that the C locale
regards as such, anyway, wiill ever have a negative value, so the issue
is rather academic.

> The snippet you quoted is from apply.c, and I would say what is
> more problematic is that we do not force C locale while parsing
> the diff

Quite true.  One reason I tend to avoid the standard is* functions in my
own code.

-- 
Antti-Juhani
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Received on Thu Oct 13 18:30:19 2005

This archive was generated by hypermail 2.1.8 : 2005-10-13 18:30:53 EST