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

Re: [PATCH] grep: add --max-count command line option

From
Paul Eggert <eggert@cs.ucla.edu>
Date
Jun 20, 2022, 16:32 UTC
Message-ID
<7b7a2876-f6fe-1234-813b-71ba94a00422@cs.ucla.edu>
In-Reply-To
<xy0kCdbtIjKb_GkXpHs7eeE8eWLbbct69_tVczBGS3CMnnnKTlTheaeNlH-RB1mMAfWThSTN6bMThsQ4lLtr0Ji6RwG3Nd52L1muiEqdtCU=@protonmail.com>
On 6/20/22 11:25, Carlos L. wrote:
> This does not work well with OPTION_INTEGER, since it assumes the value to be int-sized:
>
> parse-options.c:
>   219             *(int *)opt->value = strtol(arg, (char **)&s, 10);

OK, so parse-options messes up if the user specifies a count that does not fit in 'int'? Although that's a separate bug, let's not make things worse here; let's make the new count an 'int'.

In the long run parse-options should be changed to use strtoimax instead of strtol, and the corresponding integers should be changed to intmax_t, and the proper thing should be done if the string value does not fit into intmax_t. But this longer-run fix affects all integer-valued options, not just this one.

> I also wanted to avoid using signed int so both sides of the comparison with `count` in grep_source_1() have the same sign.

Such comparisons cannot misfire if both values are nonnegative, and that can easily be arranged here.

Previous: Carlos L.Next: Carlos L. via GitGitGadget
Message 4 of 14 in “grep: add --max-count command line option”
  1. grep: add --max-count command line optionCarlos L. via GitGitGadget, Jun 20, 2022
  2. Paul EggertJun 20, 2022
  3. Carlos L.Jun 20, 2022
  4. Paul EggertJun 20, 2022
  5. grep: add --max-count command line optionCarlos L. via GitGitGadget, Jun 21, 2022
  6. Junio C HamanoJun 21, 2022
  7. Carlos L.Jun 22, 2022
  8. Junio C HamanoJun 22, 2022
  9. 0/2 grep: add --max-count command line optionCarlos L. via GitGitGadget, Jun 22, 2022
  10. 2/2 tests: add tests for grep --max-countCarlos López via GitGitGadget, Jun 22, 2022
  11. Junio C HamanoJun 22, 2022
  12. 1/2 grep: add --max-count command line optionCarlos López via GitGitGadget, Jun 22, 2022
  13. grep: add --max-count command line optionCarlos L. via GitGitGadget, Jun 22, 2022
  14. Carlos L.Jun 22, 2022

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.