git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: Usage of isspace and friends

From
Antti-Juhani Kaijanaho <antti-juhani@kaijanaho.info>
Date
Oct 13, 2005, 08:29 UTC
Message-ID
<434E1AE8.9010509@kaijanaho.info>
In-Reply-To
<7vachd6hdx.fsf@assigned-by-dhcp.cox.net>
Junio C Hamano wrote:
Show 11 quoted lines
> 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
Previous: Junio C HamanoNext: H. Peter Anvin
Message 3 of 10 in “Usage of isspace and friends”
  1. Morten WelinderOct 12, 2005
  2. Junio C HamanoOct 13, 2005
  3. Antti-Juhani KaijanahoOct 13, 2005
  4. H. Peter AnvinOct 13, 2005
  5. Junio C HamanoOct 13, 2005
  6. Linus TorvaldsOct 13, 2005
  7. H. Peter AnvinOct 13, 2005
  8. Linus TorvaldsOct 13, 2005
  9. H. Peter AnvinOct 13, 2005
  10. Linus TorvaldsOct 13, 2005

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.