Re: NULL passed as an argument to memcmp() in parse_func.c - Mailing list pgsql-hackers

From Tom Lane
Subject Re: NULL passed as an argument to memcmp() in parse_func.c
Date
Msg-id 25140.1435008665@sss.pgh.pa.us
Whole thread Raw
In response to Re: NULL passed as an argument to memcmp() in parse_func.c  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: NULL passed as an argument to memcmp() in parse_func.c  (Glen Knowles <gknowles@ieee.org>)
List pgsql-hackers
Robert Haas <robertmhaas@gmail.com> writes:
> On Mon, Jun 22, 2015 at 2:55 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> If I recall that code correctly, the assumption was that if the third
>> argument is zero then memcmp() must not fetch any bytes (not should not,
>> but MUST not) and therefore it doesn't matter if we pass a NULL.  Are
>> you seeing any observable problem here, and if so what is it?

> I dunno, this seems like playing with fire to me.  A null-test would
> be pretty cheap insurance.

A null test would be a pretty cheap way of masking a bug in that logic,
if we ever introduced one; to wit, that it would cause a call with
argtypes==NULL to match anything.

Possibly saner is
   if (nargs == 0 ||       memcmp(argtypes, best_candidate->args, nargs * sizeof(Oid)) == 0)       break;

I remain unconvinced that this is necessary, though.  It looks a *whole*
lot like the guards we have against old Solaris' bsearch-of-zero-entries
bug.  I maintain that what glibc has done is exactly to introduce a bug
for the zero-entries case, and that Piotr ought to complain to them
about it.  At the very least, if you commit this please annotate it
as working around a memcmp bug.
        regards, tom lane



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: RFC: replace pg_stat_activity.waiting with something more descriptive
Next
From: Jim Nasby
Date:
Subject: Re: RFC: replace pg_stat_activity.waiting with something more descriptive