Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TiE5V-0000qq-Qx for pgsql-bugs@arkaria.postgresql.org; Tue, 11 Dec 2012 00:52:45 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TiE5U-0000mL-KW for pgsql-bugs@arkaria.postgresql.org; Tue, 11 Dec 2012 00:52:44 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TiE5U-0000mG-4U for pgsql-bugs@postgresql.org; Tue, 11 Dec 2012 00:52:44 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TiE5O-0004Lb-GA for pgsql-bugs@postgresql.org; Tue, 11 Dec 2012 00:52:43 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.5/8.14.5) with ESMTP id qBB0qaMM000334; Mon, 10 Dec 2012 19:52:36 -0500 (EST) From: Tom Lane To: Jeff Davis cc: pgsql-bugs@postgresql.org Subject: Re: init_htab causes SIGFPE (or worse) due to miscalculation for large nbuckets In-reply-to: <1355185776.13316.4.camel@sussancws0025> References: <1355079715.3896.14.camel@jdavis> <18018.1355093132@sss.pgh.pa.us> <1355185776.13316.4.camel@sussancws0025> Comments: In-reply-to Jeff Davis message dated "Mon, 10 Dec 2012 16:29:36 -0800" Date: Mon, 10 Dec 2012 19:52:36 -0500 Message-ID: <333.1355187156@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org Jeff Davis writes: > On Sun, 2012-12-09 at 17:45 -0500, Tom Lane wrote: >> Alternatively, maybe we should hack my_log2 to do that bounding. >> As-is, it seems like trouble waiting to happen. This won't protect >> init_htab, which needs the shift result to fit in int not long. >> But my_log2 is just plain broken for inputs larger than LONG_MAX/2, >> anyway. > It looks like all of the callers, except two, immediately shift the > result. So perhaps it would be better to make a new function (something > like "ceil_pow2") that returns the lowest power of two greater than or > equal to the input, and it can return a long (bounded to +LONG_MAX). > Then, the caller can bound the result further if needed, which should be > less error-prone, because the caller would see that it returns a long > (and compiler, but I don't seem to get a warning for implicit long->int > conversions). > Both of the callers that actually want a log2 already assume that the > input is a power of two, so we can redefine my_log2 to require it. It seems reasonably possible that add-on code is using my_log2, so I'm hesitant to change the function's signature, or to change its behavior more than minimally necessary --- especially in the back branches. regards, tom lane -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs