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

Re: [PATCH v2 2/2] string-list API: change "nr" and "alloc" to "size_t"

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 7, 2022, 20:43 UTC
Message-ID
<xmqqy21lqyrk.fsf@gitster.g>
In-Reply-To
<9c9ca557-122e-3bcb-db4b-3b5ba7bf9369@iee.email>
Philip Oakley <philipoakley@iee.email> writes:
Show 14 quoted lines
>> @@ -448,10 +448,10 @@ void shortlog_output(struct shortlog *log)
>>  				(int)UTIL_TO_INT(item), item->string);
>>  		} else {
>>  			struct string_list *onelines = item->util;
>> -			fprintf(log->file, "%s (%d):\n",
>> -				item->string, onelines->nr);
>> -			for (j = onelines->nr - 1; j >= 0; j--) {
>> -				const char *msg = onelines->items[j].string;
>> +			fprintf(log->file, "%s (%"PRIuMAX"):\n",
>> +				item->string, (uintmax_t)onelines->nr);
>> +			for (j = onelines->nr; j >= 1; j--) {
>> +				const char *msg = onelines->items[j - 1].string;
> Does this change of iteration limits and j's offset need a commit
> message comment?

Good eyes. I also tried to made sure this is the only loop that counts toward zero that use a variable whose type has become size_t with this patch, which is unsigned and cannot use "var >= 0" as the loop termination condition, but what is not in the patch is hard to know. If there were loops that used to count down with the .nr or the .alloc members of string_list structure, they would need to be updated, but if such a code exists, it is likely a bug already.

I think many internal index string-list.c uses are still "int" (cf. get_entry_index() and functions on the call graph that leads to it, like add_entry() and string_list_remove()) that wants to be updated to "ssize_t"; if the string_list has very many elements, add_entry() may not find an existing string and add a duplicate at the end, because the bisection search get_entry_index() uses cannot move the upper-bound pointer beyond "int".

It would have been better if you culled the parts of the patch you are not referring to, by the way.

Thanks.
Previous: Philip OakleyNext: Philip Oakley
Message 13 of 15 in “string-list.h: make "nr" and "alloc" a "size_t"”
  1. 0/2 string-list.h: make "nr" and "alloc" a "size_t"Ævar Arnfjörð Bjarmason, Mar 7, 2022
  2. 1/2 gettext API users: correct use of casts for Q_()Ævar Arnfjörð Bjarmason, Mar 7, 2022
  3. Derrick StoleeMar 7, 2022
  4. Ævar Arnfjörð BjarmasonMar 7, 2022
  5. Derrick StoleeMar 7, 2022
  6. 2/2 string-list API: change "nr" and "alloc" to "size_t"Ævar Arnfjörð Bjarmason, Mar 7, 2022
  7. Derrick StoleeMar 7, 2022
  8. Ævar Arnfjörð BjarmasonMar 7, 2022
  9. 0/2 string-list.h: make "nr" and "alloc" a "size_t"Ævar Arnfjörð Bjarmason, Mar 7, 2022
  10. 1/2 gettext API users: don't explicitly cast ngettext()'s "n"Ævar Arnfjörð Bjarmason, Mar 7, 2022
  11. 2/2 string-list API: change "nr" and "alloc" to "size_t"Ævar Arnfjörð Bjarmason, Mar 7, 2022
  12. Philip OakleyMar 7, 2022
  13. Junio C HamanoMar 7, 2022
  14. Philip OakleyMar 7, 2022
  15. Derrick StoleeMar 7, 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.