Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iUYhQ-00038U-1x for pgsql-bugs@arkaria.postgresql.org; Tue, 12 Nov 2019 16:07:24 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iUYhN-0005xh-Q1 for pgsql-bugs@arkaria.postgresql.org; Tue, 12 Nov 2019 16:07:21 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iUYhN-0005wn-E6 for pgsql-bugs@lists.postgresql.org; Tue, 12 Nov 2019 16:07:21 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iUYhK-0005z5-BU for pgsql-bugs@lists.postgresql.org; Tue, 12 Nov 2019 16:07:19 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id xACG7A74006299; Tue, 12 Nov 2019 11:07:10 -0500 From: Tom Lane To: Alvaro Herrera cc: Kyotaro Horiguchi , ranier_gyn@hotmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: [BUG FIX] Uninitialized var fargtypes used. In-reply-to: <20191112140129.GA7283@alvherre.pgsql> References: <20191112140129.GA7283@alvherre.pgsql> Comments: In-reply-to Alvaro Herrera message dated "Tue, 12 Nov 2019 11:01:29 -0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <6297.1573574830.1@sss.pgh.pa.us> Date: Tue, 12 Nov 2019 11:07:10 -0500 Message-ID: <6298.1573574830@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Alvaro Herrera writes: > On 2019-Nov-12, Kyotaro Horiguchi wrote: >> We can change the condition with "nargs <= 0" and it should return the >> only element in clist. If the catalog is broken we may get >> FUNCLOOKUP_AMBIGUOUS but it seems rather the correct behavior. > Yeah, essentially this reverts 0a52d378b03b. Here's another version of > this I wrote last night. I really dislike the s/nargs < 0/nargs <= 0/ aspect of these proposals. That's conflating two fundamentally different corner cases. We have (1) for the nargs<0 case, there must not be more than one match, else it's a user mistake (and not an unlikely one). (2) for the nargs==0 case, if there's more than one match, we either have corrupted catalogs or some kind of software bug. The argument for changing the code like this seems to be "we'll assume the possibility of a bug/corruption is so small that it's okay to treat it as a user mistake". I reject that line of thinking. And I especially reject conflating the two cases without bothering to fix the adjacent comment that describes only case 1. If we're going to revert 0a52d378b03b we should just treat the problem straightforwardly. I was imagining - if (memcmp(argtypes, clist->args, nargs * sizeof(Oid)) == 0) + /* if nargs==0, argtypes can be null; don't pass that to memcmp */ + if (nargs == 0 || + memcmp(argtypes, clist->args, nargs * sizeof(Oid)) == 0) It's really stretching credulity to imagine that one more test-and-branch in this loop costs anything worth noticing, especially compared to the costs of having built the list to begin with. So I'm now feeling that 0a52d378b03b was penny-wise and pound-foolish. Or, in other words: the OP's complaint here is basically that the existing code isn't being straightforward about how it handles this scenario. Changing to a different non-straightforward fix isn't much of an improvement. regards, tom lane