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

Re: [PATCH] builtin/mv.c: use correct type to compute size of an array element

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 7, 2022, 20:25 UTC
Message-ID
<xmqqfsjczn42.fsf@gitster.g>
In-Reply-To
<YscpDTgwxUko/aZM@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 13 quoted lines
> On Wed, Jul 06, 2022 at 07:02:18PM -0700, Junio C Hamano wrote:
>
>>    * Should we in general use sizeof(TYPE) in these cases, instead
>>      of the size of the zeroth element, e.g.
>> 
>>  		memmove(source + i, source + i + 1,
>> 			n * sizeof(source[i]));
>>     
>>      It would have been caught by the above Coccinelle rule (we are
>>      taking the size of *dst).
>
> I'm not sure I understand this. As you noted in a later email, using
> sizeof(TYPE) is less maintainable if the type of "source" changes.
Sorry for a typo or thinko, whichever one you like ;-)
Show 5 quoted lines
> But
> later you mention using "*source" instead of "source[i]". I don't think
> there is a particular reason to prefer one over the other from the
> compiler perspective. I find "*source" more idiomatic (but better still
> of course is MOVE_ARRAY, which removes the choice entirely).

Yes, I wrote source[i] there only because I found it somewhat awkward to write source[0] or *source there, when the moved (sub)array is from the index 'i' to the end. *(source + i) would have matched the intention better but it still is awkward.

Previous: Jeff King
Message 18 of 18 in “builtin/mv.c: use correct type to compute size of an array element”
  1. builtin/mv.c: use correct type to compute size of an array elementJunio C Hamano, Jul 7, 2022
  2. builtin/mv.c: use the MOVE_ARRAY() macro instead of memmove()Junio C Hamano, Jul 7, 2022
  3. builtin/mv.c: use the MOVE_ARRAY() macro instead of memmove()Junio C Hamano, Jul 10, 2022
  4. Derrick StoleeJul 18, 2022
  5. Ævar Arnfjörð BjarmasonJul 7, 2022
  6. Junio C HamanoJul 7, 2022
  7. René ScharfeJul 7, 2022
  8. René ScharfeJul 9, 2022
  9. Junio C HamanoJul 10, 2022
  10. cocci: avoid normalization rules for memcpyRené Scharfe, Jul 10, 2022
  11. Ævar Arnfjörð BjarmasonJul 10, 2022
  12. Ævar Arnfjörð BjarmasonJul 10, 2022
  13. Junio C HamanoJul 10, 2022
  14. René ScharfeJul 11, 2022
  15. Ævar Arnfjörð BjarmasonJul 11, 2022
  16. René ScharfeJul 7, 2022
  17. Jeff KingJul 7, 2022
  18. Junio C HamanoJul 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.