Re: [PATCH 2/2] nedmalloc: work around overzealous GCC 6 warning
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Aug 5, 2016, 06:24 UTC
- Message-ID
- <xmqq7fbvzqan.fsf@gitster.mtv.corp.google.com>
- In-Reply-To
- <68c24062-7fcc-758f-373f-2f123c5eb78b@kdbg.org>
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