Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TiFEK-0001wO-IT for pgsql-bugs@arkaria.postgresql.org; Tue, 11 Dec 2012 02:05:56 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1TiFEK-0002M2-1U for pgsql-bugs@arkaria.postgresql.org; Tue, 11 Dec 2012 02:05:56 +0000 Received: from makus.postgresql.org ([98.129.198.125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TiFEJ-0002Lx-CP for pgsql-bugs@postgresql.org; Tue, 11 Dec 2012 02:05:55 +0000 Received: from mail-da0-f46.google.com ([209.85.210.46]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TiFEI-0007An-Ae for pgsql-bugs@postgresql.org; Tue, 11 Dec 2012 02:05:54 +0000 Received: by mail-da0-f46.google.com with SMTP id p5so1478337dak.19 for ; Mon, 10 Dec 2012 18:05:53 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=subject:from:to:cc:in-reply-to:references:content-type:date :message-id:mime-version:x-mailer:content-transfer-encoding :x-gm-message-state; bh=9db7asQcCDzL2OeXKGdVKBsDWHbPndYm4sE1XlCOGoI=; b=fS5/ztpcfFCDlCGRO34ph3oOx+KnNEQbHZ547NanBlXuiXtgPU+w+740sXLv2BRdgK nyK29sPj4N0kO3ib1tyTAcaIWyhk58IiclttJbuOBUGq7j6ZD+DIhLUwghGC+5lIjXy8 drj/IdMwJFMChhIqT495UG/lOGA4QORgMRzVRvgG7pNyGv2fSESx/zvhFEnzbYA3CRmn RA7JrgWkEAh7OC6HHiJGawYEjaZSE/GRfEbEKeVVaEnEaYsDL2VmtSD10ZflTsl9Rc/R F3pj+6A9DIQorY9pyCywiIV2jcd4ioUhiRRC3armHD7qLWhDRdXtbYaFHvf5WfA7xfWD oMNQ== Received: by 10.66.79.72 with SMTP id h8mr40626891pax.49.1355191553305; Mon, 10 Dec 2012 18:05:53 -0800 (PST) Received: from ?IPv6:::1? ([2600:3c01::f03c:91ff:fe93:2ae4]) by mx.google.com with ESMTPS id wg3sm12788970pbc.28.2012.12.10.18.05.51 (version=SSLv3 cipher=OTHER); Mon, 10 Dec 2012 18:05:52 -0800 (PST) Subject: Re: init_htab causes SIGFPE (or worse) due to miscalculation for large nbuckets From: Jeff Davis To: Tom Lane Cc: pgsql-bugs@postgresql.org In-Reply-To: <1036.1355189242@sss.pgh.pa.us> References: <1355079715.3896.14.camel@jdavis> <18018.1355093132@sss.pgh.pa.us> <1355185776.13316.4.camel@sussancws0025> <1036.1355189242@sss.pgh.pa.us> Content-Type: text/plain; charset="ISO-8859-1" Date: Mon, 10 Dec 2012 18:05:49 -0800 Message-ID: <1355191549.15663.10.camel@sussancws0025> Mime-Version: 1.0 X-Mailer: Evolution 2.28.3 Content-Transfer-Encoding: 7bit X-Gm-Message-State: ALoCoQl9qRanDX15s/dsRQVMmtobeM5eBuOSJq5+D2kv9pLQxYrigZQhNLtKJVp1dregGkqq8PJx X-Pg-Spam-Score: -2.6 (--) 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 On Mon, 2012-12-10 at 20:27 -0500, Tom Lane wrote: > Jeff Davis writes: > > 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). > > That does seem like a good idea. We need one for an int-sized result > too, to fix the original problem in init_htab. So I propose these > functions: Looks good to me. One other corner case in the version of the patch I was working on was that nbuckets is compared to num_partitions, which is a long. We can assert that it is less than or equal to INT_MAX in hash_create. Aside from that, I'll drop my version of the patch, which doesn't have any useful differences from yours. Regards, Jeff Davis -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs