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

Usage of isspace and friends

From
MWMorten Welinder <mwelinder@gmail.com>
Date
Oct 12, 2005, 01:40 UTC
Message-ID
<118833cc0510111840k715e1190l54ad65f821c77848@mail.gmail.com>

Someone needs to audit the usage of isspace, tolower, and friends. There are things like this in the code:

static int is_dev_null(const char *str)
{
	return !memcmp("/dev/null", str, 9) && isspace(str[9]);
}

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]);

Admittedly that is ugly. Blame K&R. (Glibc has a partial workaround for this kind of coding bug. On the up side you won't get a crash, but on the down side you can get the wrong result.)

Morten
Next: Junio C Hamano
Message 1 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.