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

Re: [PATCH] grep: remove tautological check

From
Peter Krefting <peter@softwolves.pp.se>
Date
Oct 22, 2012, 13:20 UTC
Message-ID
<alpine.DEB.2.00.1210221416080.32103@ds9.cixit.se>
In-Reply-To
<1350753964-29346-1-git-send-email-dsp@php.net>
David Soria Parra:
> -		if (p->field < 0 || GREP_HEADER_FIELD_MAX <= p->field)
> +		if (GREP_HEADER_FIELD_MAX <= p->field)

A friend taught me this trick, which will check that it isn't negative for compilers that have the enumeration be signed (notably MSVC), while not complaining for compilers that have it unsigned (GCC, Clang):

   const unsigned int sign = 1u << (sizeof(p->field) * CHAR_BIT - 1);
   if (!(sign & (unsigned int) p->field) || GREP_HEADER_FIELD_MAX <= p->field)
-- 
\\// Peter - http://www.softwolves.pp.se/
Previous: Peter Krefting
Message 3 of 3 in “grep: remove tautological check”
  1. grep: remove tautological checkDavid Soria Parra, Oct 20, 2012
  2. Peter KreftingOct 20, 2012
  3. Peter KreftingOct 22, 2012

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.