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

Re: [PATCH] do not depend on undefined signed integer overflow

From
Erik Faye-Lund <kusmabite@gmail.com>
Date
Oct 4, 2010, 19:47 UTC
Message-ID
<AANLkTimx0PbyTPgwq8=VoE2Ldihf44c2UkDGYom4TAcf@mail.gmail.com>
In-Reply-To
<1286221388-4908-1-git-send-email-kusmabite@gmail.com>
On Mon, Oct 4, 2010 at 9:43 PM, Erik Faye-Lund <kusmabite@gmail.com> wrote:
Show 9 quoted lines
> +/*
> + * Signed integer overflow is undefined in C and some compilers take
> + * advantage of this when optimizing, so here's a helper macro to force
> + * wrapping when adding two integers. The size to wrap to is taken from
> + * the first parameter.
> + */
> +#define signed_add_overflows(a, b) \
> +    ((b) > ((INTMAX_MAX >> (bitsizeof(uintmax_t) - bitsizeof(a))) - (a)))
> +

*Sigh*, I already see that this comment is out of date (I did a different approach before this one). Sorry, I will fix up this comment for the next round.

Previous: Erik Faye-LundNext: Jonathan Nieder
Message 2 of 3 in “do not depend on undefined signed integer overflow”
  1. do not depend on undefined signed integer overflowErik Faye-Lund, Oct 4, 2010
  2. Erik Faye-LundOct 4, 2010
  3. Jonathan NiederOct 4, 2010

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.