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

Re: [PATCH] apply.c: fix -p argument parsing

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 16, 2026, 19:56 UTC
Message-ID
<xmqqikavo8e7.fsf@gitster.g>
In-Reply-To
<20260316005120.7079-1-mroik@delayed.space>
Mirko Faina <mroik@delayed.space> writes:
Show 16 quoted lines
> "git apply" has an option -p that takes an integer as its argument.
> Unfortunately the function apply_option_parse_p() in charge of parsing
> this argument uses atoi() to convert from string to integer, which
> allows a non-digit after the number (e.g. "1q") to be silently ignored.
> As a consequence, an argument that does not begin with a digit silently
> becomes a zero. Despite this command working fine when a non-positive
> argument is passed, it might be useful for the end user to know that
> their input contains non-digits that might've been unintended.
>
> Replace atoi() with strtol_i() to catch malformed inputs.
>
> Signed-off-by: Mirko Faina <mroik@delayed.space>
> ---
> Sending a new version 'cause Tian pointed out that the die message is
> not explicit enough, and a user might not understand which option we're
> referring to if there are multiple.
The updated error message does look more helpful.  Will replace.

Also the post-test clean-up in each test is more thorough, which is a very good thing to see.

Thanks.
Previous: Mirko Faina
Message 19 of 19 in “apply.c: fix -p argument parsing”
  1. apply.c: fix -p argument parsingMirko Faina, Mar 9, 2026
  2. Junio C HamanoMar 9, 2026
  3. apply.c: fix -p argument parsingMirko Faina, Mar 10, 2026
  4. Junio C HamanoMar 10, 2026
  5. Mirko FainaMar 10, 2026
  6. apply.c: fix -p argument parsingMirko Faina, Mar 10, 2026
  7. Junio C HamanoMar 10, 2026
  8. Jeff KingMar 13, 2026
  9. Jeff KingMar 13, 2026
  10. Jeff KingMar 13, 2026
  11. apply.c: fix -p argument parsingMirko Faina, Mar 13, 2026
  12. Junio C HamanoMar 13, 2026
  13. Junio C HamanoMar 13, 2026
  14. Junio C HamanoMar 13, 2026
  15. Tian YuchenMar 15, 2026
  16. Mirko FainaMar 15, 2026
  17. apply.c: fix -p argument parsingMirko Faina, Mar 16, 2026
  18. Mirko FainaMar 16, 2026
  19. Junio C HamanoMar 16, 2026

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.