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

Re: [PATCH] zlib.c: use size_t for size

From
Johannes Sixt <j6t@kdbg.org>
Date
Oct 13, 2018, 08:43 UTC
Message-ID
<2e7b2f4b-92c3-a583-5985-38090cc78c64@kdbg.org>
In-Reply-To
<20181013024624.GB15595@sigill.intra.peff.net>
Am 13.10.18 um 04:46 schrieb Jeff King:
Show 24 quoted lines
> But no, right before that we have this line:
> 
>            offset -= win->offset;
> 
> So offset is in fact no longer its original meaning of "offset into the
> packfile", but is now an offset of the specific request into the window
> we found.
> 
> So I think it's correct, but it sure confused me. I wonder if another
> variable might help, like:
> 
>    size_t offset_in_window;
>    ...
> 
>    /*
>     * We know this difference will fit in a size_t, because our mmap
>     * window by * definition can be no larger than a size_t.
>     */
>    offset_in_window = xsize_t(offset - win->offset);
>    if (left)
> 	*left = win->len - offset_in_window;
>    return win->base + offset_in_window;
> 
> I dunno. Maybe it is overkill.

Thank you for your analysis. No, I don't think that such a new variable would be overkill. It is important to make such knowledge of value magnitudes explicit precisely because it reduces confusion and helps reviewers of the code verify correctness.

-- Hannes
Previous: Jeff King
Message 19 of 19 in “zlib.c: use size_t for size”
  1. zlib.c: use size_t for sizeJunio C Hamano, Oct 12, 2018
  2. Johannes SchindelinOct 12, 2018
  3. Junio C HamanoOct 12, 2018
  4. Johannes SchindelinOct 12, 2018
  5. Ramsay JonesOct 12, 2018
  6. 1/1 zlib.c: use size_t for sizetboegi@web.de, Oct 12, 2018
  7. SZEDER GáborOct 12, 2018
  8. Torsten BögershausenOct 13, 2018
  9. Ramsay JonesOct 14, 2018
  10. Ramsay JonesOct 14, 2018
  11. Jeff KingOct 14, 2018
  12. Ramsay JonesOct 14, 2018
  13. Jeff KingOct 15, 2018
  14. Ramsay JonesOct 15, 2018
  15. Junio C HamanoOct 15, 2018
  16. Torsten BögershausenOct 15, 2018
  17. Jeff KingOct 13, 2018
  18. Jeff KingOct 13, 2018
  19. Johannes SixtOct 13, 2018

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.