Re: [PATCH 2/2] string-list API: change "nr" and "alloc" to "size_t"
- From
Derrick Stolee <derrickstolee@github.com>
- Date
- Mar 7, 2022, 13:43 UTC
- Message-ID
- <34eb7b5a-180c-0e4a-0929-8eaf52f80090@github.com>
- In-Reply-To
- <patch-2.2-398682c07aa-20220307T113707Z-avarab@gmail.com>
On 3/7/2022 6:38 AM, Ævar Arnfjörð Bjarmason wrote:
Show 6 quoted lines
> Change the "nr" and "alloc" members of "struct string_list" to use > "size_t" instead of "nr". On some platforms the size of an "unsigned > int" will be smaller than a "size_t", e.g. a 32 bit unsigned v.s. 64 > bit unsigned. As "struct string_list" is a generic API we use in a lot > of places this might cause overflows. >
Show 7 quoted lines
> printf_ln(Q_("The bundle requires this ref:",
> - "The bundle requires these %d refs:",
> - r->nr),
> - r->nr);
> + "The bundle requires these %"PRIuMAX" refs:",
> + (unsigned long)r->nr),
> + (uintmax_t)r->nr);There are more additions of unsigned long here, which will possibly truncate the size_t of r->nr. I must be missing something here that explains why you are making this choice.
Thanks, -Stolee