From: Junio C Hamano <gitster@pobox.com>
To: "Martin Liška" <mliska@suse.cz>
Cc: "Johannes Sixt" <j6t@kdbg.org>, "René Scharfe" <l.s.r@web.de>,
"Jeff King" <peff@peff.net>,
git@vger.kernel.org
Subject: Re: [PATCH v3 1/2] Fix nonnull errors reported by UBSAN with GCC 7.
Date: Sun, 16 Apr 2017 18:49:07 -0700 [thread overview]
Message-ID: <xmqqy3uzkdm4.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <96beb4c6-0569-0c12-8151-462c20be6a2a@suse.cz> ("Martin Liška"'s message of "Fri, 7 Apr 2017 16:23:13 +0200")
Martin Liška <mliska@suse.cz> writes:
> From 0bdf4d717d3d368dd9676d15d20f8592c4d22fde Mon Sep 17 00:00:00 2001
> From: marxin <mliska@suse.cz>
> Date: Wed, 5 Apr 2017 14:31:32 +0200
> Subject: [PATCH 1/2] Fix nonnull errors reported by UBSAN with GCC 7.
>
> Replace call to memmove with newly introduced function memmove_or_null
> and call to memcpy with COPY_ARRAY macro.
I didn't closely follow the discussion, but with these three lines
(which will be the primary thing future readers of this change in
"git log -p" output will rely on), it is unclear why this change was
made. For that matter, it is not clear what "nonnull errors" are,
either.
> Signed-off-by: Martin Liska <mliska@suse.cz>
> ---
> apply.c | 4 +---
> builtin/ls-files.c | 2 +-
> git-compat-util.h | 8 ++++++++
> 3 files changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/apply.c b/apply.c
> index e6dbab26a..121f3f414 100644
> --- a/apply.c
> +++ b/apply.c
> @@ -2802,9 +2802,7 @@ static void update_image(struct apply_state *state,
> img->line + applied_pos + preimage_limit,
> (img->nr - (applied_pos + preimage_limit)) *
> sizeof(*img->line));
> - memcpy(img->line + applied_pos,
> - postimage->line,
> - postimage->nr * sizeof(*img->line));
> + COPY_ARRAY(img->line + applied_pos, postimage->line, postimage->nr);
I am suspecting that postimage->nr can be 0 and newer compliers can
give warning "hey what's the point of copying 0 bytes?" which can be
squelched by moving to COPY_ARRAY()? If that is the case I like the
change (but as I said, it is unclear if that is what is going on
here).
> diff --git a/builtin/ls-files.c b/builtin/ls-files.c
> index d449e46db..0a6cc1e8a 100644
> --- a/builtin/ls-files.c
> +++ b/builtin/ls-files.c
> @@ -391,7 +391,7 @@ static void prune_cache(const char *prefix, size_t prefixlen)
> }
> last = next;
> }
> - memmove(active_cache, active_cache + pos,
> + memmove_or_null(active_cache, active_cache + pos,
> (last - pos) * sizeof(struct cache_entry *));
Does this change come with the same or a similar motivation as the
above (i.e. pos could be the same as last)?
"Something or NULL" is a name we use for a function that returns
something (under normal circumstances) or returns NULL. This
wrapper is not about returning NULL at all, as far as I can see, and
is misnamed. If it is about "avoid moving 0 bytes", similar to how
COPY_ARRAY() is used in the previous hunk, perhaps MOVE_ARRAY() is a
better name?
Thanks.
> active_nr = last - pos;
> }
> diff --git a/git-compat-util.h b/git-compat-util.h
> index 8a4a3f85e..81f6e56ac 100644
> --- a/git-compat-util.h
> +++ b/git-compat-util.h
> @@ -1002,6 +1002,14 @@ int git_qsort_s(void *base, size_t nmemb, size_t size,
> die("BUG: qsort_s() failed"); \
> } while (0)
>
> +static inline void *memmove_or_null(void *dest, const void *src, size_t n)
> +{
> + if (n > 0)
> + return memmove(dest, src, n);
> + else
> + return dest;
> +}
> +
> #ifndef REG_STARTEND
> #error "Git requires REG_STARTEND support. Compile with NO_REGEX=NeedsStartEnd"
> #endif
next prev parent reply other threads:[~2017-04-17 1:49 UTC|newest]
Thread overview: 15+ 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 ` [PATCH 1/2] add MOVE_ARRAY René Scharfe
2017-04-07 15:25 ` [PATCH 2/2] use MOVE_ARRAY René Scharfe
2017-04-17 1:49 ` Junio C Hamano [this message]
2017-04-17 7:59 ` [PATCH v3 1/2] Fix nonnull errors reported by UBSAN with GCC 7 Johannes Sixt
2017-04-06 8:57 ` [PATCH " Johannes Schindelin
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=xmqqy3uzkdm4.fsf@gitster.mtv.corp.google.com \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=j6t@kdbg.org \
--cc=l.s.r@web.de \
--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).