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 1j3MD3-00014G-2e for pgsql-committers@arkaria.postgresql.org; Sun, 16 Feb 2020 15:51:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1j3MD1-000864-I7 for pgsql-committers@arkaria.postgresql.org; Sun, 16 Feb 2020 15:51:51 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1j3MD1-00085x-Ai for pgsql-committers@lists.postgresql.org; Sun, 16 Feb 2020 15:51:51 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1j3MCz-0008UN-05; Sun, 16 Feb 2020 15:51:50 +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 01GFpkqU020352; Sun, 16 Feb 2020 10:51:46 -0500 From: Tom Lane To: Jeff Davis cc: pgsql-committers@lists.postgresql.org Subject: Re: pgsql: Logical Tape Set: lazily allocate read buffer. In-reply-to: References: Comments: In-reply-to Jeff Davis message dated "Thu, 13 Feb 2020 18:45:38 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <20350.1581868306.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 16 Feb 2020 10:51:46 -0500 Message-ID: <20351.1581868306@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Jeff Davis writes: > Logical Tape Set: lazily allocate read buffer. Coverity is not very pleased with this patch: it's spewing warnings like 1112 if (lt->buffer =3D=3D NULL) 1113 ltsInitReadBuffer(lts, lt); 1114 = 1115 if (blocknum !=3D lt->curBlockNumber) 1116 { >>> CID 1458440: Null pointer dereferences (FORWARD_NULL) >>> Passing null pointer "lt->buffer" to "ltsReadBlock", which derefer= ences it. 1117 ltsReadBlock(lts, blocknum, (void *) lt->buffer); 1118 lt->curBlockNumber =3D blocknum; Evidently, it doesn't think that ltsInitReadBuffer() is guaranteed to make lt->buffer not null, which is not so surprising considering that that's coded this way: if (lt->firstBlockNumber !=3D -1L) { Assert(lt->buffer_size > 0); lt->buffer =3D palloc(lt->buffer_size); } Is there a reason for that to be coded in such an obscure and fragile fashion, rather than having the test be say "if (lt->buffer =3D=3D NULL)"? If we really need a connection to firstBlockNumber, I'd suggest something like - if (lt->firstBlockNumber !=3D -1L) + if (lt->buffer =3D=3D NULL) { + Assert(lt->firstBlockNumber !=3D -1L); Assert(lt->buffer_size > 0); lt->buffer =3D palloc(lt->buffer_size); } but I'm not sure the extra Assert has any value. regards, tom lane