Re: new compiler warnings

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Peter Eisentraut <peter_e(at)gmx(dot)net>, Jeff Davis <pgsql(at)j-davis(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: new compiler warnings
Date: 2011-10-18 21:52:30
Message-ID: 25087.1318974750@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

I wrote:
> I think a large fraction of the -Waddress warnings are coming from
> this line in the heap_getattr macro:
> AssertMacro((tup) != NULL), \
> Seems to me we could just lose that test and be no worse off, since
> the macro is surely gonna dump core anyway on a null pointer.

Actually, all the ones in the backend are coming from that, so I went
ahead and removed that.

> But some of the remaining -Waddress warnings are not so painless to
> get rid of. Ultimately we might have to add -Wno-address to the
> default CFLAGS.

The remaining -Waddress warnings are all from applying PQExpBufferBroken
to the address of a local variable. We could silence them along these
lines:

*** src/interfaces/libpq/pqexpbuffer.h.orig Thu Apr 28 16:07:00 2011
--- src/interfaces/libpq/pqexpbuffer.h Tue Oct 18 17:46:18 2011
***************
*** 60,65 ****
--- 60,73 ----
((str) == NULL || (str)->maxlen == 0)

/*------------------------
+ * Same, but for use when using a static or local PQExpBufferData struct.
+ * For that, a null-pointer test is useless and may draw compiler warnings.
+ *------------------------
+ */
+ #define PQExpBufferDataBroken(buf) \
+ ((buf).maxlen == 0)
+
+ /*------------------------
* Initial size of the data buffer in a PQExpBuffer.
* NB: this must be large enough to hold error messages that might
* be returned by PQrequestCancel().
*** src/interfaces/libpq/fe-connect.c.orig Sun Sep 25 18:43:15 2011
--- src/interfaces/libpq/fe-connect.c Tue Oct 18 17:46:58 2011
***************
*** 829,835 ****
PQconninfoOption *connOptions;

initPQExpBuffer(&errorBuf);
! if (PQExpBufferBroken(&errorBuf))
return NULL; /* out of memory already :-( */
connOptions = conninfo_parse("", &errorBuf, true);
termPQExpBuffer(&errorBuf);
--- 829,835 ----
PQconninfoOption *connOptions;

initPQExpBuffer(&errorBuf);
! if (PQExpBufferDataBroken(errorBuf))
return NULL; /* out of memory already :-( */
connOptions = conninfo_parse("", &errorBuf, true);
termPQExpBuffer(&errorBuf);
***************
*** 3967,3973 ****
if (errmsg)
*errmsg = NULL; /* default */
initPQExpBuffer(&errorBuf);
! if (PQExpBufferBroken(&errorBuf))
return NULL; /* out of memory already :-( */
connOptions = conninfo_parse(conninfo, &errorBuf, false);
if (connOptions == NULL && errmsg)
--- 3967,3973 ----
if (errmsg)
*errmsg = NULL; /* default */
initPQExpBuffer(&errorBuf);
! if (PQExpBufferDataBroken(errorBuf))
return NULL; /* out of memory already :-( */
connOptions = conninfo_parse(conninfo, &errorBuf, false);
if (connOptions == NULL && errmsg)

(and one similar place in psql, which I did not bother to test).

Any objections or better ideas?

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2011-10-18 22:15:02 Re: new compiler warnings
Previous Message Kevin Grittner 2011-10-18 21:44:47 Re: new compiler warnings