From e6d2d5ee5614acdbe67b79aeb0fdc9b53cf3a828 Mon Sep 17 00:00:00 2001 From: marxin Date: Wed, 5 Apr 2017 14:31:32 +0200 Subject: [PATCH 1/2] Fix nonnull errors reported by UBSAN with GCC 7. Memory functions like memmove and memcpy should not be called with an argument equal to NULL. Signed-off-by: Martin Liska --- apply.c | 7 ++++--- builtin/ls-files.c | 5 +++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/apply.c b/apply.c index e6dbab26a..78a83f66b 100644 --- a/apply.c +++ b/apply.c @@ -2802,9 +2802,10 @@ 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)); + if (postimage->nr) + memcpy(img->line + applied_pos, + postimage->line, + postimage->nr * sizeof(*img->line)); if (!state->allow_overlap) for (i = 0; i < postimage->nr; i++) img->line[applied_pos + i].flag |= LINE_PATCHED; diff --git a/builtin/ls-files.c b/builtin/ls-files.c index d449e46db..01d24314d 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -391,8 +391,9 @@ static void prune_cache(const char *prefix, size_t prefixlen) } last = next; } - memmove(active_cache, active_cache + pos, - (last - pos) * sizeof(struct cache_entry *)); + if (last - pos > 0) + memmove(active_cache, active_cache + pos, + (last - pos) * sizeof(struct cache_entry *)); active_nr = last - pos; } -- 2.12.2