git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Roland Illig <roland.illig@gmx.de>
To: Jeff King <peff@peff.net>
Cc: git@vger.kernel.org
Subject: Re: undefined behavior in builtin/am.c
Date: Fri, 1 Jul 2022 20:58:25 +0200	[thread overview]
Message-ID: <647f50a7-4350-fe04-fb84-b79417d98455@gmx.de> (raw)
In-Reply-To: <Yr80s8VP8ECCXKd+@coredump.intra.peff.net>

Am 01.07.2022 um 19:53 schrieb Jeff King:
> 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

  reply	other threads:[~2022-07-01 19:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-01 17:03 undefined behavior in builtin/am.c Roland Illig
2022-07-01 17:53 ` Jeff King
2022-07-01 18:58   ` Roland Illig [this message]
2022-07-01 17:54 ` Phillip Wood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=647f50a7-4350-fe04-fb84-b79417d98455@gmx.de \
    --to=roland.illig@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).