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

Re: [PATCH 1/4] git-compat-util.h: xsize_t() - avoid -Wsign-compare warnings

From
Stefan Beller <sbeller@google.com>
Date
Sep 21, 2017, 18:57 UTC
Message-ID
<CAGZ79kYuGpO5Ji9vwqwy_2=ea2Vd9CG2ethzyhXUc709KQSSaQ@mail.gmail.com>
In-Reply-To
<75416139-74c5-8a60-22e8-79c53dd062c1@web.de>
On Thu, Sep 21, 2017 at 11:49 AM, Torsten Bögershausen <tboegi@web.de> wrote:
Show 25 quoted lines
> On 2017-09-21 18:46, Ramsay Jones wrote:
>>
>> Signed-off-by: Ramsay Jones <ramsay@ramsayjones.plus.com>
>> ---
>>  git-compat-util.h | 6 ++++--
>>  1 file changed, 4 insertions(+), 2 deletions(-)
>>
>> diff --git a/git-compat-util.h b/git-compat-util.h
>> index 9bc15b036..cedad4d58 100644
>> --- a/git-compat-util.h
>> +++ b/git-compat-util.h
>> @@ -898,9 +898,11 @@ static inline char *xstrdup_or_null(const char *str)
>>
>>  static inline size_t xsize_t(off_t len)
>>  {
>> -     if (len > (size_t) len)
>> +     size_t size = (size_t) len;
>> +
>> +     if (len != (off_t) size)
>>               die("Cannot handle files this big");
>> -     return (size_t)len;
>> +     return size;
>
> Hm, can someone help me out ?
> Why is the cast not needed ?
Because 'size' is already size_t,
(cast was done in first line of the function:
    size_t size = (size_t) len;
), previously we cast len multiple times,
now we cast it once and use size thereafter.
Show 6 quoted lines
>
>>  }
>>
>>  __attribute__((format (printf, 3, 4)))
>>
>
Previous: Torsten BögershausenNext: Ramsay Jones
Message 3 of 4 in “git-compat-util.h: xsize_t() - avoid -Wsign-compare warnings”
  1. 1/4 git-compat-util.h: xsize_t() - avoid -Wsign-compare warningsRamsay Jones, Sep 21, 2017
  2. Torsten BögershausenSep 21, 2017
  3. Stefan BellerSep 21, 2017
  4. Ramsay JonesSep 21, 2017

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.