git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] builtin/mv.c: use correct type to compute size of an array element
Date: Thu, 7 Jul 2022 14:42:21 -0400	[thread overview]
Message-ID: <YscpDTgwxUko/aZM@coredump.intra.peff.net> (raw)
In-Reply-To: <xmqq8rp54r4l.fsf@gitster.g>

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. 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).

>    * Shouldn't we have an array of struct with four members, instead
>      of four parallel arrays, e.g.
> 
> 		struct {
> 			const char *source;
> 			const char *destination;
> 			enum update_mode mode;
> 			const char *submodule_gitfile;
> 		} *mv_file;
> 
>    The latter question is important to answer before we accept
>    Coccinelle-suggested rewrite to use four MOVE_ARRAY() on these
>    four parallel arrays on top of this fix.

I think that would make the code a lot cleaner. But it looks like
"source" and "destination" come from separate calls to
internal_prefix_pathspec().  So you'd have to reconcile that. And
there's some extra trickiness that sometimes "destination" comes from
"dest_path", which _isn't_ always the same size as "source".

So I suspect the code which uses these arrays would be cleaner with a
struct, but the setup may get worse. :)

-Peff

  parent reply	other threads:[~2022-07-07 18:42 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-07  2:02 [PATCH] builtin/mv.c: use correct type to compute size of an array element Junio C Hamano
2022-07-07  5:52 ` [PATCH v2] builtin/mv.c: use the MOVE_ARRAY() macro instead of memmove() Junio C Hamano
2022-07-10  1:33   ` [PATCH v3] " Junio C Hamano
2022-07-18 20:30     ` Derrick Stolee
2022-07-07 12:11 ` [PATCH] builtin/mv.c: use correct type to compute size of an array element Ævar Arnfjörð Bjarmason
2022-07-07 18:10   ` Junio C Hamano
2022-07-07 19:11     ` René Scharfe
2022-07-09  8:16       ` René Scharfe
2022-07-10  5:38         ` Junio C Hamano
2022-07-10 10:05           ` [PATCH] cocci: avoid normalization rules for memcpy René Scharfe
2022-07-10 14:45             ` Ævar Arnfjörð Bjarmason
2022-07-10 16:32               ` Ævar Arnfjörð Bjarmason
2022-07-10 19:30               ` Junio C Hamano
2022-07-11 17:11               ` René Scharfe
2022-07-11 20:05                 ` Ævar Arnfjörð Bjarmason
2022-07-07 18:27   ` [PATCH] builtin/mv.c: use correct type to compute size of an array element René Scharfe
2022-07-07 18:42 ` Jeff King [this message]
2022-07-07 20:25   ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YscpDTgwxUko/aZM@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).