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

Re: [PATCH] compat: helper for detecting unsigned overflow

From
JJJoshua Juran <jjuran@gmail.com>
Date
Feb 10, 2011, 13:23 UTC
Message-ID
<E84FF9D8-92D7-4CA0-9CF4-77FF33893977@gmail.com>
In-Reply-To
<AANLkTinqkSxj0C+GyMVR4a7d=yy_mh+oDuar0moZjZ8_@mail.gmail.com>
On Feb 10, 2011, at 4:11 AM, Sverre Rabbelier wrote:
Show 14 quoted lines
> On Thu, Feb 10, 2011 at 10:35, Jonathan Nieder <jrnieder@gmail.com>  
> wrote:
>>       unsigned_add_overflows(a, b)
>
>> Define such a macro, expanding roughly to ((a) < UINT_MAX - (b)).
>> Because the expansion uses each argument only once outside of  
>> sizeof()
>> expressions, it is safe to use with arguments that have side effects.
>
>> +#define unsigned_add_overflows(a, b) \
>> +    ((b) > maximum_unsigned_value_of_type(a) - (a))
>
> I'm confused, you say you won't use it twice, and then you do use it  
> twice?

The author is asserting that maximum_unsigned_value_of_type() is a function of sizeof a, which would have no runtime effect.

Josh
Previous: Sverre Rabbelier
Message 5 of 5 in “do not depend on signed integer overflow”
  1. do not depend on signed integer overflowErik Faye-Lund, Oct 5, 2010
  2. Nicolas PitreOct 5, 2010
  3. compat: helper for detecting unsigned overflowJonathan Nieder, Feb 10, 2011
  4. Sverre RabbelierFeb 10, 2011
  5. Joshua JuranFeb 10, 2011

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.