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 1hG9q3-0002yW-CL for pgsql-hackers@arkaria.postgresql.org; Mon, 15 Apr 2019 22:12:31 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hG9q1-0002eV-QE for pgsql-hackers@arkaria.postgresql.org; Mon, 15 Apr 2019 22:12:29 +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 1hG9q1-0002eO-EB for pgsql-hackers@lists.postgresql.org; Mon, 15 Apr 2019 22:12:29 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hG9pz-0000eS-3t for pgsql-hackers@lists.postgresql.org; Mon, 15 Apr 2019 22:12:28 +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 x3FMCOhZ030401; Mon, 15 Apr 2019 18:12:24 -0400 From: Tom Lane To: Tomas Vondra cc: pgsql-hackers@lists.postgresql.org Subject: Re: Strange coding in mvdistinct.c In-reply-to: <29785.1555365602@sss.pgh.pa.us> References: <29785.1555365602@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Mon, 15 Apr 2019 18:00:02 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <30399.1555366344.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 15 Apr 2019 18:12:24 -0400 Message-ID: <30400.1555366344@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Oh, and as I continue to grep, I found this in dependencies.c: dependencies =3D (MVDependencies *) repalloc(dependencies, offsetof(MVDependen= cies, deps) + dependencies->nde= ps * sizeof(MVDependency)); I'm pretty sure this is an actual bug: the calculation should be offsetof(MVDependencies, deps) + dependencies->ndeps * sizeof(MVDependency *)); because deps is an array of MVDependency* not MVDependency. This would lead to an overallocation not underallocation, and it's probably pretty harmless because ndeps can't get too large (I hope; if it could, this would have O(N^2) performance problems). Still, you oughta fix it. (There's a similar calculation later in the file that gets it right.) regards, tom lane