git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Martin Liška" <mliska@suse.cz>
To: git@vger.kernel.org
Subject: [PATCH 1/2] Fix nonnull errors reported by UBSAN with GCC 7.
Date: Thu, 6 Apr 2017 10:02:22 +0200	[thread overview]
Message-ID: <295981e7-d2e9-d3db-e32d-8dd80ca47136@suse.cz> (raw)

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

Hello.

Following patch fixes issues that can be seen with -fsanitize=undefined on GCC 7.

Patch was tested with make test.

Thanks,
Martin

[-- Attachment #2: 0001-Fix-nonnull-errors-reported-by-UBSAN-with-GCC-7.patch --]
[-- Type: text/x-patch, Size: 1596 bytes --]

From e6d2d5ee5614acdbe67b79aeb0fdc9b53cf3a828 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.

Memory functions like memmove and memcpy should not be called
with an argument equal to NULL.

Signed-off-by: Martin Liska <mliska@suse.cz>
---
 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


             reply	other threads:[~2017-04-06  8:02 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-06  8:02 Martin Liška [this message]
2017-04-06  8:34 ` [PATCH 1/2] Fix nonnull errors reported by UBSAN with GCC 7 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                 ` [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

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=295981e7-d2e9-d3db-e32d-8dd80ca47136@suse.cz \
    --to=mliska@suse.cz \
    --cc=git@vger.kernel.org \
    /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).