Re: [PATCH] grep: add --max-count command line option
- From
Paul Eggert <eggert@cs.ucla.edu>
- Date
- Jun 20, 2022, 15:57 UTC
- Message-ID
- <449bede6-82b0-72ef-300d-bc0c49a1858b@cs.ucla.edu>
- In-Reply-To
- <pull.1278.git.git.1655740174420.gitgitgadget@gmail.com>
On 6/20/22 10:49, Carlos L. via GitGitGadget wrote:
> + unsigned max_count;
Why not make this intmax_t? That way, you don't have to worry about casting -1 to unsigned. Also on typical 64-bit machines you no longer have to worry about mishandling counts greater than 2**32 (the limit becomes 2**63 - 1 which is plenty).
These days it's typically better to avoid unsigned types in C when you can, as standard tools like 'gcc -fsanitize=undefined' can catch signed int overflow whereas unsigned int overflow always wraps around which is typically bad news.