# [PATCH 0/2] Patches to let Git build with GCC 6 and DEVELOPER=SureWhyNot

17 messages from 2016-08-04 to 2016-08-06. Participants: Johannes Schindelin, Junio C Hamano, René Scharfe, Johannes Sixt, Jeff King.
Thread: https://gitlist.dev/t/43006

## Johannes Schindelin, 2016-08-04 16:07

Subject: [PATCH 0/2] Patches to let Git build with GCC 6 and DEVELOPER=SureWhyNot
Message-ID: <cover.1470326812.git.johannes.schindelin@gmx.de>
URL: https://gitlist.dev/e/cover.1470326812.git.johannes.schindelin%40gmx.de

```
While working on some local setup to allow my poor little laptop to
build and test the Windows-specific patches of Git for Windows on top of
the upstream branches, my development environment updated to use GCC 6,
and these patches were required.


Johannes Schindelin (2):
  nedmalloc: fix misleading indentation
  nedmalloc: work around overzealous GCC 6 warning

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

Published-As: https://github.com/dscho/git/releases/tag/gcc-6-v1
Fetch-It-Via: git fetch https://github.com/dscho/git gcc-6-v1
-- 
2.9.0.281.g286a8d9

base-commit: 80460f513ebd7851953f5402dd9744236128b240

```

## Johannes Schindelin, 2016-08-04 16:07

Subject: [PATCH 1/2] nedmalloc: fix misleading indentation
Message-ID: <0e17a706c29932e2280a1bc1730f5064bbcfec57.1470326812.git.johannes.schindelin@gmx.de>
URL: https://gitlist.dev/e/0e17a706c29932e2280a1bc1730f5064bbcfec57.1470326812.git.johannes.schindelin%40gmx.de
In-Reply-To: <cover.1470326812.git.johannes.schindelin@gmx.de>

```
Some code in nedmalloc is indented in a funny way that could be
misinterpreted as if a line after a for loop was included in the loop
body, when it is not.

GCC 6 complains about this in DEVELOPER=YepSure mode.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 compat/nedmalloc/nedmalloc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/compat/nedmalloc/nedmalloc.c b/compat/nedmalloc/nedmalloc.c
index a0a16eb..677d1b2 100644
--- a/compat/nedmalloc/nedmalloc.c
+++ b/compat/nedmalloc/nedmalloc.c
@@ -938,10 +938,10 @@ void **nedpindependent_comalloc(nedpool *p, size_t elems, size_t *sizes, void **
 	void **ret;
 	threadcache *tc;
 	int mymspace;
-    size_t i, *adjustedsizes=(size_t *) alloca(elems*sizeof(size_t));
-    if(!adjustedsizes) return 0;
-    for(i=0; i<elems; i++)
-	adjustedsizes[i]=sizes[i]<sizeof(threadcacheblk) ? sizeof(threadcacheblk) : sizes[i];
+	size_t i, *adjustedsizes=(size_t *) alloca(elems*sizeof(size_t));
+	if(!adjustedsizes) return 0;
+	for(i=0; i<elems; i++)
+		adjustedsizes[i]=sizes[i]<sizeof(threadcacheblk) ? sizeof(threadcacheblk) : sizes[i];
 	GetThreadCache(&p, &tc, &mymspace, 0);
 	GETMSPACE(m, p, tc, mymspace, 0,
 	      ret=mspace_independent_comalloc(m, elems, adjustedsizes, chunks));
-- 
2.9.0.281.g286a8d9



```

## Johannes Schindelin, 2016-08-04 16:07

Subject: [PATCH 2/2] nedmalloc: work around overzealous GCC 6 warning
Message-ID: <57360f4885bdd5c36e190bea288f1e1f7f706071.1470326812.git.johannes.schindelin@gmx.de>
URL: https://gitlist.dev/e/57360f4885bdd5c36e190bea288f1e1f7f706071.1470326812.git.johannes.schindelin%40gmx.de
In-Reply-To: <cover.1470326812.git.johannes.schindelin@gmx.de>

```
With GCC 6, the strdup() function is declared with the "nonnull"
attribute, stating that it is not allowed to pass a NULL value as
parameter.

In nedmalloc()'s reimplementation of strdup(), Postel's Law is heeded
and NULL parameters are handled gracefully. GCC 6 complains about that
now because it thinks that NULL cannot be passed to strdup() anyway.

Let's just shut up GCC >= 6 in that case and go on with our lives.

See https://gcc.gnu.org/gcc-6/porting_to.html for details.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 compat/nedmalloc/nedmalloc.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/compat/nedmalloc/nedmalloc.c b/compat/nedmalloc/nedmalloc.c
index 677d1b2..3f28c0b 100644
--- a/compat/nedmalloc/nedmalloc.c
+++ b/compat/nedmalloc/nedmalloc.c
@@ -956,6 +956,9 @@ void **nedpindependent_comalloc(nedpool *p, size_t elems, size_t *sizes, void **
 char *strdup(const char *s1)
 {
 	char *s2 = 0;
+#if __GNUC__ >= 6
+#pragma GCC diagnostic ignored "-Wnonnull-compare"
+#endif
 	if (s1) {
 		size_t len = strlen(s1) + 1;
 		s2 = malloc(len);
-- 
2.9.0.281.g286a8d9

```

## Junio C Hamano, 2016-08-04 17:41

Subject: Re: [PATCH 2/2] nedmalloc: work around overzealous GCC 6 warning
Message-ID: <xmqqoa584eju.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqoa584eju.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <57360f4885bdd5c36e190bea288f1e1f7f706071.1470326812.git.johannes.schindelin@gmx.de>

```
Johannes Schindelin <johannes.schindelin@gmx.de> writes:

> With GCC 6, the strdup() function is declared with the "nonnull"
> attribute, stating that it is not allowed to pass a NULL value as
> parameter.
>
> In nedmalloc()'s reimplementation of strdup(), Postel's Law is heeded
> and NULL parameters are handled gracefully. GCC 6 complains about that
> now because it thinks that NULL cannot be passed to strdup() anyway.
>
> Let's just shut up GCC >= 6 in that case and go on with our lives.
>
> See https://gcc.gnu.org/gcc-6/porting_to.html for details.
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
>  compat/nedmalloc/nedmalloc.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/compat/nedmalloc/nedmalloc.c b/compat/nedmalloc/nedmalloc.c
> index 677d1b2..3f28c0b 100644
> --- a/compat/nedmalloc/nedmalloc.c
> +++ b/compat/nedmalloc/nedmalloc.c
> @@ -956,6 +956,9 @@ void **nedpindependent_comalloc(nedpool *p, size_t elems, size_t *sizes, void **
>  char *strdup(const char *s1)
>  {
>  	char *s2 = 0;
> +#if __GNUC__ >= 6
> +#pragma GCC diagnostic ignored "-Wnonnull-compare"
> +#endif
>  	if (s1) {
>  		size_t len = strlen(s1) + 1;
>  		s2 = malloc(len);

Is it a common convention to place "#pragma GCC diagnostic"
immediately before the statement you want to affect, and have the
same pragma in effect until the end of the compilation unit?

I know this function is at the end and it is not worth doing
push/ignored/pop dance, and I assumed that it is the reason why we
see a single "ignore from here on", which is much simpler, but it is
somewhat distracting.  It made me wonder if it makes it easier to
read and less distracting to have these three lines in front of and
outside the function definition, while thinking that it would have a
documentation value to have it immediately before the statement you
want to affect.  Help me convince myself that this is the best
place.

Thanks.


```

## René Scharfe, 2016-08-04 21:56

Subject: Re: [PATCH 2/2] nedmalloc: work around overzealous GCC 6 warning
Message-ID: <57A3BA26.5080601@web.de>
URL: https://gitlist.dev/e/57A3BA26.5080601%40web.de
In-Reply-To: <57360f4885bdd5c36e190bea288f1e1f7f706071.1470326812.git.johannes.schindelin@gmx.de>

```
Am 04.08.2016 um 18:07 schrieb Johannes Schindelin:
> With GCC 6, the strdup() function is declared with the "nonnull"
> attribute, stating that it is not allowed to pass a NULL value as
> parameter.
>
> In nedmalloc()'s reimplementation of strdup(), Postel's Law is heeded
> and NULL parameters are handled gracefully. GCC 6 complains about that
> now because it thinks that NULL cannot be passed to strdup() anyway.
>
> Let's just shut up GCC >= 6 in that case and go on with our lives.

This version of strdup() is only compiled if nedmalloc is used instead
of the system allocator.  That means we can't rely on strdup() being
able to take NULL -- some (most?) platforms won't like it.  Removing
the NULL check would be a more general and overall easier way out, no?

But it should check the result of malloc() before copying.
---
  compat/nedmalloc/nedmalloc.c | 8 +++-----
  1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/compat/nedmalloc/nedmalloc.c b/compat/nedmalloc/nedmalloc.c
index a0a16eb..cc18f0c 100644
--- a/compat/nedmalloc/nedmalloc.c
+++ b/compat/nedmalloc/nedmalloc.c
@@ -955,12 +955,10 @@ 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
-- 
2.9.2


```

## Junio C Hamano, 2016-08-04 22:33

Subject: Re: [PATCH 2/2] nedmalloc: work around overzealous GCC 6 warning
Message-ID: <xmqqoa58yxin.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqoa58yxin.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <57A3BA26.5080601@web.de>

```
René Scharfe <l.s.r@web.de> writes:

> This version of strdup() is only compiled if nedmalloc is used instead
> of the system allocator.  That means we can't rely on strdup() being
> able to take NULL -- some (most?) platforms won't like it.  Removing
> the NULL check would be a more general and overall easier way out, no?

The callers of this version must be prepared to call a version of
strdup() that does not accept NULL, so in a sense, passing NULL to
this function is already an error in the context of this project.

That sounds like a good rationale to take this more straight-forward
approach.

> But it should check the result of malloc() before copying.
> ---
>  compat/nedmalloc/nedmalloc.c | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/compat/nedmalloc/nedmalloc.c b/compat/nedmalloc/nedmalloc.c
> index a0a16eb..cc18f0c 100644
> --- a/compat/nedmalloc/nedmalloc.c
> +++ b/compat/nedmalloc/nedmalloc.c
> @@ -955,12 +955,10 @@ 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

```

## Junio C Hamano, 2016-08-04 22:39

Subject: Re: [PATCH 2/2] nedmalloc: work around overzealous GCC 6 warning
Message-ID: <xmqqk2fwyx8h.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqk2fwyx8h.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <57A3BA26.5080601@web.de>

```
Let's try it this way.  How about this as a replacement?

-- >8 --
From: Johannes Schindelin <johannes.schindelin@gmx.de>
Date: Thu, 4 Aug 2016 18:07:08 +0200
Subject: [PATCH] nedmalloc: work around overzealous GCC 6 warning

With GCC 6, the strdup() function is declared with the "nonnull"
attribute, stating that it is not allowed to pass a NULL value as
parameter.

In nedmalloc()'s reimplementation of strdup(), Postel's Law is heeded
and NULL parameters are handled gracefully. GCC 6 complains about that
now because it thinks that NULL cannot be passed to strdup() anyway.

Because the callers in this project of strdup() must be prepared to
call any implementation of strdup() supplied by the platform, so it
is pointless to pretend that it is OK to call it with NULL.

Remove the conditional based on NULL-ness of the input; this
squelches the warning.

See https://gcc.gnu.org/gcc-6/porting_to.html for details.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Helped-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 compat/nedmalloc/nedmalloc.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/compat/nedmalloc/nedmalloc.c b/compat/nedmalloc/nedmalloc.c
index 677d1b2..88cd78c 100644
--- a/compat/nedmalloc/nedmalloc.c
+++ b/compat/nedmalloc/nedmalloc.c
@@ -955,12 +955,10 @@ 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;
+	s2 = malloc(len);
+	if (s1)
 		memcpy(s2, s1, len);
-	}
 	return s2;
 }
 #endif
-- 
2.9.2-766-gd7972a8


```

## Johannes Sixt, 2016-08-05 05:36

Subject: Re: [PATCH 2/2] nedmalloc: work around overzealous GCC 6 warning
Message-ID: <5ce2ec67-aa7d-0079-54fe-d73a70a46825@kdbg.org>
URL: https://gitlist.dev/e/5ce2ec67-aa7d-0079-54fe-d73a70a46825%40kdbg.org
In-Reply-To: <xmqqk2fwyx8h.fsf@gitster.mtv.corp.google.com>

```
Am 05.08.2016 um 00:39 schrieb Junio C Hamano:
> @@ -955,12 +955,10 @@ 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;
> +	s2 = malloc(len);
> +	if (s1)

It does not make sense to check s1 for NULL when it was passed to 
strlen() earlier; strlen() does not accept NULL, either...

>  		memcpy(s2, s1, len);
> -	}
>  	return s2;
>  }
>  #endif

-- Hannes


```

## Johannes Sixt, 2016-08-05 05:40

Subject: Re: [PATCH 2/2] nedmalloc: work around overzealous GCC 6 warning
Message-ID: <68c24062-7fcc-758f-373f-2f123c5eb78b@kdbg.org>
URL: https://gitlist.dev/e/68c24062-7fcc-758f-373f-2f123c5eb78b%40kdbg.org
In-Reply-To: <5ce2ec67-aa7d-0079-54fe-d73a70a46825@kdbg.org>

```
Am 05.08.2016 um 07:36 schrieb Johannes Sixt:
> Am 05.08.2016 um 00:39 schrieb Junio C Hamano:
>> @@ -955,12 +955,10 @@ 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;
>> +    s2 = malloc(len);
>> +    if (s1)
>
> It does not make sense to check s1 for NULL when it was passed to
> strlen() earlier; strlen() does not accept NULL, either...

Oh! This is a typo. You meant to check s2 for NULL.

And the declaration for s2 should remain, of course.

>
>>          memcpy(s2, s1, len);
>> -    }
>>      return s2;
>>  }
>>  #endif

-- Hannes


```

## Junio C Hamano, 2016-08-05 06:24

Subject: Re: [PATCH 2/2] nedmalloc: work around overzealous GCC 6 warning
Message-ID: <xmqq7fbvzqan.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqq7fbvzqan.fsf%40gitster.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

```

## Jeff King, 2016-08-05 07:42

Subject: Re: [PATCH 2/2] nedmalloc: work around overzealous GCC 6 warning
Message-ID: <20160805074219.3vvgzaqnn6kvsh3s@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20160805074219.3vvgzaqnn6kvsh3s%40sigill.intra.peff.net
In-Reply-To: <xmqq7fbvzqan.fsf@gitster.mtv.corp.google.com>

```
On Thu, Aug 04, 2016 at 11:24:32PM -0700, Junio C Hamano wrote:

> I do not know if we want to worry about st_add(1, strlen(s1))
> overflow around here, though.
> [...]
> +	size_t len = strlen(s1) + 1;

I wondered that, too, but I don't think it's possible.

To overflow the size_t with "+1", strlen() must return the maximum value
that it can hold. But such a string would need one more byte than that,
for its trailing NUL. So assuming you cannot have a string that exceeds
size_t in the first place, I think it is impossible to overflow here.

-Peff

```

## Johannes Schindelin, 2016-08-05 15:34

Subject: Re: [PATCH 2/2] nedmalloc: work around overzealous GCC 6 warning
Message-ID: <alpine.DEB.2.20.1608051728380.5786@virtualbox>
URL: https://gitlist.dev/e/alpine.DEB.2.20.1608051728380.5786%40virtualbox
In-Reply-To: <xmqqk2fwyx8h.fsf@gitster.mtv.corp.google.com>

```
Hi Junio & René,

On Thu, 4 Aug 2016, Junio C Hamano wrote:

> Let's try it this way.  How about this as a replacement?

I like it (with the if (s2) test intead of if (s1), of course). But please
record René as author, maybe mentioning myself with a "Diagnosed-by:"
line.

FWIW today's `pu` does pass the test suite without problems in my CI
setup.

This setup will from now on test next & pu in the Git for Windows SDK, and
rebase Git for Windows' current master to git.git's maint, master, next &
pu, every morning after a weekday (unless I forget to turn on my laptop,
that is).

Once it stabilizes, I will figure out a way how to publish the logs,
because playing Lt Tawney Madison gets old real quick.

Thanks,
Dscho
```

## Johannes Schindelin, 2016-08-05 15:38

Subject: Re: [PATCH 2/2] nedmalloc: work around overzealous GCC 6 warning
Message-ID: <alpine.DEB.2.20.1608051736400.5786@virtualbox>
URL: https://gitlist.dev/e/alpine.DEB.2.20.1608051736400.5786%40virtualbox
In-Reply-To: <xmqqoa584eju.fsf@gitster.mtv.corp.google.com>

```
Hi Junio,

On Thu, 4 Aug 2016, Junio C Hamano wrote:

> Johannes Schindelin <johannes.schindelin@gmx.de> writes:
> 
> > With GCC 6, the strdup() function is declared with the "nonnull"
> > attribute, stating that it is not allowed to pass a NULL value as
> > parameter.
> >
> > In nedmalloc()'s reimplementation of strdup(), Postel's Law is heeded
> > and NULL parameters are handled gracefully. GCC 6 complains about that
> > now because it thinks that NULL cannot be passed to strdup() anyway.
> >
> > Let's just shut up GCC >= 6 in that case and go on with our lives.
> >
> > See https://gcc.gnu.org/gcc-6/porting_to.html for details.
> >
> > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> > ---
> >  compat/nedmalloc/nedmalloc.c | 3 +++
> >  1 file changed, 3 insertions(+)
> >
> > diff --git a/compat/nedmalloc/nedmalloc.c b/compat/nedmalloc/nedmalloc.c
> > index 677d1b2..3f28c0b 100644
> > --- a/compat/nedmalloc/nedmalloc.c
> > +++ b/compat/nedmalloc/nedmalloc.c
> > @@ -956,6 +956,9 @@ void **nedpindependent_comalloc(nedpool *p, size_t elems, size_t *sizes, void **
> >  char *strdup(const char *s1)
> >  {
> >  	char *s2 = 0;
> > +#if __GNUC__ >= 6
> > +#pragma GCC diagnostic ignored "-Wnonnull-compare"
> > +#endif
> >  	if (s1) {
> >  		size_t len = strlen(s1) + 1;
> >  		s2 = malloc(len);
> 
> Is it a common convention to place "#pragma GCC diagnostic"
> immediately before the statement you want to affect, and have the
> same pragma in effect until the end of the compilation unit?

Uh oh. This was a brain fart. I somehow confused the way pragmas work with
the way __attribute__s work. You are correct, of course, that the pragma
affects the entire remainder of the file, not just this statement.

Luckily, René came up with a much more elegant solution, so that Git's
history does not have to shame me eternally.

Ciao,
Dscho
```

## Junio C Hamano, 2016-08-05 16:13

Subject: Re: [PATCH 2/2] nedmalloc: work around overzealous GCC 6 warning
Message-ID: <xmqqpopnxkfv.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqpopnxkfv.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <alpine.DEB.2.20.1608051728380.5786@virtualbox>

```
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> This setup will from now on test next & pu in the Git for Windows SDK, and
> rebase Git for Windows' current master to git.git's maint, master, next &
> pu, every morning after a weekday (unless I forget to turn on my laptop,
> that is).

Sounds really good.  Thanks.


```

## Junio C Hamano, 2016-08-05 21:57

Subject: Re: [PATCH 2/2] nedmalloc: work around overzealous GCC 6 warning
Message-ID: <xmqqk2fuvpzm.fsf@gitster.mtv.corp.google.com>
URL: https://gitlist.dev/e/xmqqk2fuvpzm.fsf%40gitster.mtv.corp.google.com
In-Reply-To: <alpine.DEB.2.20.1608051728380.5786@virtualbox>

```
Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:

> Hi Junio & René,
>
> On Thu, 4 Aug 2016, Junio C Hamano wrote:
>
>> Let's try it this way.  How about this as a replacement?
>
> I like it (with the if (s2) test intead of if (s1), of course). But please
> record René as author, maybe mentioning myself with a "Diagnosed-by:"
> line.

Hmph.  I cannot do that unilaterally without waiting for René to
respond, though.  In any case, with only header and footer changes,
here is what will appear in 'pu'.

Thanks.

-- >8 --
From: René Scharfe <l.s.r@web.de>
Date: Thu, 4 Aug 2016 23:56:54 +0200
Subject: [PATCH] nedmalloc: work around overzealous GCC 6 warning

With GCC 6, the strdup() function is declared with the "nonnull"
attribute, stating that it is not allowed to pass a NULL value as
parameter.

In nedmalloc()'s reimplementation of strdup(), Postel's Law is heeded
and NULL parameters are handled gracefully. GCC 6 complains about that
now because it thinks that NULL cannot be passed to strdup() anyway.

Because the callers in this project of strdup() must be prepared to
call any implementation of strdup() supplied by the platform, so it
is pointless to pretend that it is OK to call it with NULL.

Remove the conditional based on NULL-ness of the input; this
squelches the warning.

See https://gcc.gnu.org/gcc-6/porting_to.html for details.

Diagnosed-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: René Scharfe <l.s.r@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 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
-- 
2.9.2-766-gd7972a8


```

## René Scharfe, 2016-08-05 22:30

Subject: Re: [PATCH 2/2] nedmalloc: work around overzealous GCC 6 warning
Message-ID: <57A5136E.20802@web.de>
URL: https://gitlist.dev/e/57A5136E.20802%40web.de
In-Reply-To: <xmqqk2fuvpzm.fsf@gitster.mtv.corp.google.com>

```
Am 05.08.2016 um 23:57 schrieb Junio C Hamano:
> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
>
>> Hi Junio & René,
>>
>> On Thu, 4 Aug 2016, Junio C Hamano wrote:
>>
>>> Let's try it this way.  How about this as a replacement?
>>
>> I like it (with the if (s2) test intead of if (s1), of course). But please
>> record René as author, maybe mentioning myself with a "Diagnosed-by:"
>> line.
>
> Hmph.  I cannot do that unilaterally without waiting for René to
> respond, though.  In any case, with only header and footer changes,
> here is what will appear in 'pu'.

It's fine with me, thanks. :)  Minor comments below.

> Thanks.
>
> -- >8 --
> From: René Scharfe <l.s.r@web.de>
> Date: Thu, 4 Aug 2016 23:56:54 +0200
> Subject: [PATCH] nedmalloc: work around overzealous GCC 6 warning
>
> With GCC 6, the strdup() function is declared with the "nonnull"
> attribute, stating that it is not allowed to pass a NULL value as
> parameter.
>
> In nedmalloc()'s reimplementation of strdup(), Postel's Law is heeded
> and NULL parameters are handled gracefully. GCC 6 complains about that
> now because it thinks that NULL cannot be passed to strdup() anyway.
>
> Because the callers in this project of strdup() must be prepared to
> call any implementation of strdup() supplied by the platform, so it
> is pointless to pretend that it is OK to call it with NULL.
>
> Remove the conditional based on NULL-ness of the input; this
> squelches the warning.

My commit message would have been much shorter, probably too short.  But 
perhaps add here: "Check the return value of malloc() instead to make 
sure we actually got memory to write to."

> See https://gcc.gnu.org/gcc-6/porting_to.html for details.
>
> Diagnosed-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> Signed-off-by: René Scharfe <l.s.r@web.de>
> Signed-off-by: Junio C Hamano <gitster@pobox.com>
> ---
>   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);
> +

You added this blank line.  OK.

> +	if (s2)
>   		memcpy(s2, s1, len);
> -	}
>   	return s2;
>   }
>   #endif
>

```

## Johannes Schindelin, 2016-08-06 08:19

Subject: Re: [PATCH 2/2] nedmalloc: work around overzealous GCC 6 warning
Message-ID: <alpine.DEB.2.20.1608061014170.5786@virtualbox>
URL: https://gitlist.dev/e/alpine.DEB.2.20.1608061014170.5786%40virtualbox
In-Reply-To: <xmqqpopnxkfv.fsf@gitster.mtv.corp.google.com>

```
Hi Junio,

On Fri, 5 Aug 2016, Junio C Hamano wrote:

> Johannes Schindelin <Johannes.Schindelin@gmx.de> writes:
> 
> > This setup will from now on test next & pu in the Git for Windows SDK, and
> > rebase Git for Windows' current master to git.git's maint, master, next &
> > pu, every morning after a weekday (unless I forget to turn on my laptop,
> > that is).
> 
> Sounds really good.  Thanks.

Report for today:

- `pu` and `next` pass

- rebasing the Windows-specific patches failed because of the merge
  conflicts when trying to apply the GCC-6 pragma, which I have on Git for
  Windows' `master` already.

Note: I fixed said merge conflicts locally, and the way I set this up, the
CI job learns the conflict resolution and will apply it automatically next
time it runs.

So: all greeeeen today.

Ciao,
Dscho

```
