From: "René Scharfe" <l.s.r@web.de>
To: "Martin Liška" <mliska@suse.cz>, git@vger.kernel.org
Cc: Johannes Sixt <j6t@kdbg.org>, Jeff King <peff@peff.net>,
Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 1/2] add MOVE_ARRAY
Date: Fri, 7 Apr 2017 17:25:15 +0200 [thread overview]
Message-ID: <c4c60ec9-641d-fb2e-046a-91e08615c8f7@web.de> (raw)
In-Reply-To: <96beb4c6-0569-0c12-8151-462c20be6a2a@suse.cz>
Add MOVE_ARRAY to complement COPY_ARRAY, which was added in 60566cbb.
It provides the same convenience, safety and support for NULL pointers
as representations of empty arrays, just as a wrapper for memmove(3)
instead of memcpy(3).
Inspired-by: Martin Liska <mliska@suse.cz>
Signed-off-by: Rene Scharfe <l.s.r@web.de>
---
git-compat-util.h | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/git-compat-util.h b/git-compat-util.h
index 8a4a3f85e7..3266a71fb4 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -812,6 +812,14 @@ static inline void copy_array(void *dst, const void *src, size_t n, size_t size)
memcpy(dst, src, st_mult(size, n));
}
+#define MOVE_ARRAY(dst, src, n) move_array((dst), (src), (n), sizeof(*(dst)) + \
+ BUILD_ASSERT_OR_ZERO(sizeof(*(dst)) == sizeof(*(src))))
+static inline void move_array(void *dst, const void *src, size_t n, size_t size)
+{
+ if (n)
+ memmove(dst, src, st_mult(size, n));
+}
+
/*
* These functions help you allocate structs with flex arrays, and copy
* the data directly into the array. For example, if you had:
--
2.12.2
next prev parent reply other threads:[~2017-04-07 15:25 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-04-06 8:02 [PATCH 1/2] Fix nonnull errors reported by UBSAN with GCC 7 Martin Liška
2017-04-06 8:34 ` Jeff King
2017-04-06 9:52 ` [PATCH v2 " Martin Liška
2017-04-06 12:26 ` René Scharfe
2017-04-06 15:42 ` [PATCH v3 " Martin Liška
2017-04-06 16:33 ` Johannes Sixt
2017-04-06 17:31 ` René Scharfe
2017-04-06 20:49 ` Johannes Sixt
2017-04-07 14:23 ` Martin Liška
2017-04-07 15:25 ` René Scharfe
2017-04-07 15:25 ` René Scharfe [this message]
2017-04-07 15:25 ` [PATCH 2/2] use MOVE_ARRAY René Scharfe
2017-04-17 1:49 ` [PATCH v3 1/2] Fix nonnull errors reported by UBSAN with GCC 7 Junio C Hamano
2017-04-17 7:59 ` Johannes Sixt
2017-04-06 8:57 ` [PATCH " Johannes Schindelin
-- strict thread matches above, loose matches on Subject: below --
2017-07-15 19:36 [PATCH 1/2] add MOVE_ARRAY René Scharfe
2017-07-16 10:31 ` Jeff King
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
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=c4c60ec9-641d-fb2e-046a-91e08615c8f7@web.de \
--to=l.s.r@web.de \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=j6t@kdbg.org \
--cc=mliska@suse.cz \
--cc=peff@peff.net \
/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.
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).