Re: [PATCH 2/2] nedmalloc: work around overzealous GCC 6 warning

2 messages, 2 authors, 2016-08-05 · open the first message on its own page

Re: [PATCH 2/2] nedmalloc: work around overzealous GCC 6 warning

From: Junio C Hamano <hidden>
Date: 2016-08-04 17:41:50

Johannes Schindelin [off-list ref] writes:
quoted hunk
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 <redacted>
---
 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.

Re: [PATCH 2/2] nedmalloc: work around overzealous GCC 6 warning

From: Johannes Schindelin <hidden>
Date: 2016-08-05 15:39:14

Hi Junio,

On Thu, 4 Aug 2016, Junio C Hamano wrote:
Johannes Schindelin [off-list ref] writes:
quoted
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 <redacted>
---
 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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help