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

Re: [PATCH 1/4] add-patch: Fix type missmatch rom msvc

From
Patrick Steinhardt <ps@pks.im>
Date
Dec 27, 2024, 10:16 UTC
Message-ID
<Z25-aaS7s3baU7ly@pks.im>
In-Reply-To
<xmqq34iaxh7r.fsf@gitster.g>
On Thu, Dec 26, 2024 at 01:33:12PM -0800, Junio C Hamano wrote:
Show 32 quoted lines
> Sören Krecker <soekkle@freenet.de> writes:
> > @@ -1624,10 +1629,11 @@ static int patch_update_file(struct add_p_state *s,
> >  			else if (0 < response && response <= file_diff->hunk_nr)
> >  				hunk_index = response - 1;
> >  			else
> > -				err(s, Q_("Sorry, only %d hunk available.",
> > -					  "Sorry, only %d hunks available.",
> > -					  file_diff->hunk_nr),
> > -				    (int)file_diff->hunk_nr);
> > +				err(s,
> > +				    Q_("Sorry, only %"PRIuMAX" hunk available.",
> > +				       "Sorry, only %"PRIuMAX" hunks available.",
> > +				       (uintmax_t)file_diff->hunk_nr),
> > +				    (uintmax_t)file_diff->hunk_nr);
> 
> Again, this hunk may be needed, as the "hunk_nr" uses size_t, which
> probably is overly wide.
> 
> So, I do not mind too much to adjust the code around hunk_nr,
> hunk_alloc and other things that are already size_t (but before
> doing so, we probably should see if it makes more sense to use ulong
> for these members instead of size_t), hbut I am not sure if it is a
> sensible move to change old_offset, count, etc. that count in number
> of lines and use ulong (not bytes) to use size_t instead.
> 
> size_t _might_ be wider than some other forms of unsigned integers,
> but it is not necessarily the widest, so "because on msvc ulong is
> merely 32-bit and I want wider integer like everybody else!" is not
> a good excuse for such a change (if it were, we'd all coding with
> nothing but uintmax_t).
> 
> So I dunno.

In practice, the number of bytes and number of lines _can_ be the same when the file consists of newlines, only. That is of course unlikely to be the case in any sane input, but may be the case when processing input that was specifically crafted to trigger such an edge case. So using a type that can store the maximum size of a theoretically possible object feels like a sensible safeguard to me and requires us to worry less about such weird edge cases.

I also doubt that widening the type to `size_t` would have a meaningful impact on performance, so I don't see a strong reason not to go there. I tend to think that using `size_t` in such size-like-fields should be our default unless there is a good reason not to pick it.

Patrick
Previous: Junio C HamanoNext: Phillip Wood
Message 6 of 17 in “Fixes typemissmatch warinigs from msvc”
  1. 0/4 Fixes typemissmatch warinigs from msvcSören Krecker, Dec 23, 2024
  2. 4/4 commit.c: Fix type missmatch warings from msvcSören Krecker, Dec 23, 2024
  3. Junio C HamanoDec 26, 2024
  4. 1/4 add-patch: Fix type missmatch rom msvcSören Krecker, Dec 23, 2024
  5. Junio C HamanoDec 26, 2024
  6. Patrick SteinhardtDec 27, 2024
  7. Phillip WoodDec 27, 2024
  8. Junio C HamanoDec 27, 2024
  9. Sören KreckerDec 27, 2024
  10. Junio C HamanoDec 27, 2024
  11. Phillip WoodDec 28, 2024
  12. 2/4 date.c: Fix type missmatch warings from msvcSören Krecker, Dec 23, 2024
  13. Junio C HamanoDec 26, 2024
  14. 3/4 apply.c : Fix type missmatch warings from msvcSören Krecker, Dec 23, 2024
  15. Junio C HamanoDec 23, 2024
  16. Junio C HamanoDec 23, 2024
  17. Sören KreckerDec 26, 2024

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.