git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Aug 5, 2016, 15:38 UTC
Message-ID
<alpine.DEB.2.20.1608051736400.5786@virtualbox>
In-Reply-To
<xmqqoa584eju.fsf@gitster.mtv.corp.google.com>
Hi Junio,
On Thu, 4 Aug 2016, Junio C Hamano wrote:
Show 37 quoted lines
> 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

Previous: Junio C HamanoNext: René Scharfe
Message 5 of 17 in “Patches to let Git build with GCC 6 and DEVELOPER=SureWhyNot”
  1. 0/2 Patches to let Git build with GCC 6 and DEVELOPER=SureWhyNotJohannes Schindelin, Aug 4, 2016
  2. 1/2 nedmalloc: fix misleading indentationJohannes Schindelin, Aug 4, 2016
  3. 2/2 nedmalloc: work around overzealous GCC 6 warningJohannes Schindelin, Aug 4, 2016
  4. Junio C HamanoAug 4, 2016
  5. Johannes SchindelinAug 5, 2016
  6. René ScharfeAug 4, 2016
  7. Junio C HamanoAug 4, 2016
  8. Junio C HamanoAug 4, 2016
  9. Johannes SixtAug 5, 2016
  10. Johannes SixtAug 5, 2016
  11. Junio C HamanoAug 5, 2016
  12. Jeff KingAug 5, 2016
  13. Johannes SchindelinAug 5, 2016
  14. Junio C HamanoAug 5, 2016
  15. Johannes SchindelinAug 6, 2016
  16. Junio C HamanoAug 5, 2016
  17. René ScharfeAug 5, 2016

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.