git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* mingw: use COPY_ARRAY for copying array
@ 2019-11-12 21:41 René Scharfe
  2019-11-13  8:55 ` Johannes Schindelin
  0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2019-11-12 21:41 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Johannes Schindelin, Junio C Hamano, Johannes Sixt

Use the macro COPY_ARRAY to copy array elements.  The result is shorter
and safer, as it infers the element type automatically and does a (very)
basic type compatibility check for its first two arguments.

Coccinelle and contrib/coccinelle/array.cocci did not generate this
conversion due to the offset of 1 at both source and destination and
because the source is a const pointer; the semantic patch cautiously
handles only pure pointers and array references of the same type.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 compat/mingw.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/compat/mingw.c b/compat/mingw.c
index fe609239dd..2f4654c968 100644
--- a/compat/mingw.c
+++ b/compat/mingw.c
@@ -1566,7 +1566,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
 		while (argv[argc]) argc++;
 		ALLOC_ARRAY(argv2, argc + 1);
 		argv2[0] = (char *)cmd;	/* full path to the script file */
-		memcpy(&argv2[1], &argv[1], sizeof(*argv) * argc);
+		COPY_ARRAY(&argv2[1], &argv[1], argc);
 		exec_id = trace2_exec(prog, argv2);
 		pid = mingw_spawnv(prog, argv2, 1);
 		if (pid >= 0) {
--
2.24.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: mingw: use COPY_ARRAY for copying array
  2019-11-12 21:41 mingw: use COPY_ARRAY for copying array René Scharfe
@ 2019-11-13  8:55 ` Johannes Schindelin
  0 siblings, 0 replies; 2+ messages in thread
From: Johannes Schindelin @ 2019-11-13  8:55 UTC (permalink / raw)
  To: René Scharfe; +Cc: Git Mailing List, Junio C Hamano, Johannes Sixt

[-- Attachment #1: Type: text/plain, Size: 1319 bytes --]

Hi René,

On Tue, 12 Nov 2019, René Scharfe wrote:

> Use the macro COPY_ARRAY to copy array elements.  The result is shorter
> and safer, as it infers the element type automatically and does a (very)
> basic type compatibility check for its first two arguments.
>
> Coccinelle and contrib/coccinelle/array.cocci did not generate this
> conversion due to the offset of 1 at both source and destination and
> because the source is a const pointer; the semantic patch cautiously
> handles only pure pointers and array references of the same type.
>
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---

Looks good to me. Thanks,
Dscho

>  compat/mingw.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/compat/mingw.c b/compat/mingw.c
> index fe609239dd..2f4654c968 100644
> --- a/compat/mingw.c
> +++ b/compat/mingw.c
> @@ -1566,7 +1566,7 @@ static int try_shell_exec(const char *cmd, char *const *argv)
>  		while (argv[argc]) argc++;
>  		ALLOC_ARRAY(argv2, argc + 1);
>  		argv2[0] = (char *)cmd;	/* full path to the script file */
> -		memcpy(&argv2[1], &argv[1], sizeof(*argv) * argc);
> +		COPY_ARRAY(&argv2[1], &argv[1], argc);
>  		exec_id = trace2_exec(prog, argv2);
>  		pid = mingw_spawnv(prog, argv2, 1);
>  		if (pid >= 0) {
> --
> 2.24.0
>
>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-11-13  8:55 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-12 21:41 mingw: use COPY_ARRAY for copying array René Scharfe
2019-11-13  8:55 ` Johannes Schindelin

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).