All of lore.kernel.org
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Johannes Sixt <j6t@kdbg.org>
Cc: "Johannes Schindelin" <johannes.schindelin@gmx.de>,
	"René Scharfe" <l.s.r@web.de>,
	git@vger.kernel.org
Subject: Re: [PATCH 2/2] nedmalloc: work around overzealous GCC 6 warning
Date: Thu, 04 Aug 2016 23:24:32 -0700	[thread overview]
Message-ID: <xmqq7fbvzqan.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <68c24062-7fcc-758f-373f-2f123c5eb78b@kdbg.org> (Johannes Sixt's message of "Fri, 5 Aug 2016 07:40:48 +0200")

Johannes Sixt <j6t@kdbg.org> writes:

> Oh! This is a typo. You meant to check s2 for NULL.
>
> And the declaration for s2 should remain, of course.

Yeah, the moral of the story is don't try to do something you do not
usually do X-<.

The second try (the log message is the same).

I do not know if we want to worry about st_add(1, strlen(s1))
overflow around here, though.

 compat/nedmalloc/nedmalloc.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/compat/nedmalloc/nedmalloc.c b/compat/nedmalloc/nedmalloc.c
index 677d1b2..2d4ef59 100644
--- a/compat/nedmalloc/nedmalloc.c
+++ b/compat/nedmalloc/nedmalloc.c
@@ -955,12 +955,11 @@ void **nedpindependent_comalloc(nedpool *p, size_t elems, size_t *sizes, void **
  */
 char *strdup(const char *s1)
 {
-	char *s2 = 0;
-	if (s1) {
-		size_t len = strlen(s1) + 1;
-		s2 = malloc(len);
+	size_t len = strlen(s1) + 1;
+	char *s2 = malloc(len);
+
+	if (s2)
 		memcpy(s2, s1, len);
-	}
 	return s2;
 }
 #endif

  reply	other threads:[~2016-08-05  6:24 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-04 16:07 [PATCH 0/2] Patches to let Git build with GCC 6 and DEVELOPER=SureWhyNot Johannes Schindelin
2016-08-04 16:07 ` [PATCH 1/2] nedmalloc: fix misleading indentation Johannes Schindelin
2016-08-04 16:07 ` [PATCH 2/2] nedmalloc: work around overzealous GCC 6 warning Johannes Schindelin
2016-08-04 17:41   ` Junio C Hamano
2016-08-05 15:38     ` Johannes Schindelin
2016-08-04 21:56   ` René Scharfe
2016-08-04 22:33     ` Junio C Hamano
2016-08-04 22:39     ` Junio C Hamano
2016-08-05  5:36       ` Johannes Sixt
2016-08-05  5:40         ` Johannes Sixt
2016-08-05  6:24           ` Junio C Hamano [this message]
2016-08-05  7:42             ` Jeff King
2016-08-05 15:34       ` Johannes Schindelin
2016-08-05 16:13         ` Junio C Hamano
2016-08-06  8:19           ` Johannes Schindelin
2016-08-05 21:57         ` Junio C Hamano
2016-08-05 22:30           ` René Scharfe

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq7fbvzqan.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=j6t@kdbg.org \
    --cc=johannes.schindelin@gmx.de \
    --cc=l.s.r@web.de \
    /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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.