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

Re: undefined behavior in builtin/am.c

From
RIRoland Illig <roland.illig@gmx.de>
Date
Jul 1, 2022, 18:58 UTC
Message-ID
<647f50a7-4350-fe04-fb84-b79417d98455@gmx.de>
In-Reply-To
<Yr80s8VP8ECCXKd+@coredump.intra.peff.net>
Am 01.07.2022 um 19:53 schrieb Jeff King:
Show 18 quoted lines
> On Fri, Jul 01, 2022 at 07:03:18PM +0200, Roland Illig wrote:
>
>> The macro 'isspace' must only be called with an integer representable as
>> an 'unsigned char', or with the value of the macro EOF.
>>
>> On platforms where plain 'char' is a signed integer type, any character
>> whose value is negative invokes undefined behavior (except for the one
>> character that by coincidence has the same value as the macro EOF).
>>
>> To fix this, write '!isspace((unsigned char)*str)' instead.
>>
>> I have no idea how to trigger this part of the code but for someone who
>> knows this part of Git, it should be easy. Depending on the platform,
>> this kind of error may be silently ignored or crash the program, as
>> always with undefined behavior.
>
> We don't use the system isspace(), but instead our own macro wrappers in
> git-compat-util.h. They do the cast to unsigned char themselves.
Thanks for the explanation, good to know that there's no problem. :)
Roland
Previous: Jeff KingNext: Phillip Wood
Message 3 of 4 in “undefined behavior in builtin/am.c”
  1. Roland IlligJul 1, 2022
  2. Jeff KingJul 1, 2022
  3. Roland IlligJul 1, 2022
  4. Phillip WoodJul 1, 2022

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.