Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dVJma-0003Qs-F5 for pgsql-bugs@arkaria.postgresql.org; Wed, 12 Jul 2017 15:42:32 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dVJmZ-0001yI-T3 for pgsql-bugs@arkaria.postgresql.org; Wed, 12 Jul 2017 15:42:31 +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_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dVJmZ-0001y8-CJ for pgsql-bugs@postgresql.org; Wed, 12 Jul 2017 15:42:31 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dVJmS-0008Ca-Dw for pgsql-bugs@postgresql.org; Wed, 12 Jul 2017 15:42:30 +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 v6CFg4Ox004818; Wed, 12 Jul 2017 11:42:04 -0400 From: Tom Lane To: Heikki Linnakangas cc: Andres Freund , Sergey Koposov , "pg@bowt.ie" , "pgsql-bugs@postgresql.org" Subject: Re: BUG #14722: Segfault in tuplesort_heap_siftup, 32 bit overflow In-reply-to: <3de75af4-a49f-36d1-347f-f170693ce6f5@iki.fi> References: <20170629161637.1478.93109@wrigleys.postgresql.org> <1499281579.8258.32.camel@cmu.edu> <28906.1499292236@sss.pgh.pa.us> <20170705221414.bgnw73z2mwkjwor7@alap3.anarazel.de> <3de75af4-a49f-36d1-347f-f170693ce6f5@iki.fi> Comments: In-reply-to Heikki Linnakangas message dated "Wed, 12 Jul 2017 16:15:10 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <4816.1499874124.1@sss.pgh.pa.us> Date: Wed, 12 Jul 2017 11:42:04 -0400 Message-ID: <4817.1499874124@sss.pgh.pa.us> 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 Heikki Linnakangas writes: > On 07/06/2017 01:14 AM, Andres Freund wrote: >> On 2017-07-05 18:03:56 -0400, Tom Lane wrote: >>> I don't like s/int/int64/g as a fix for this. That loop is probably >>> a hot spot, and this fix is going to be expensive on any machine where >>> int64 isn't the native word width. How about something like this instead: > Another option to use "unsigned int", on the assumption that UINT_MAX >= > INT_MAX * 2 + 1. Ah, that seems like a fine idea. > And to eliminate that assumption, we can use (UINT_MAX > - 1) / 2 as the maximum size of the memtuples array, rather than INT_MAX. Uh ... what assumption? That's certainly true on any twos-complement machine. Besides, if you're worried about hypothetical portability issues, I'm not sure it's any better to assume that (UINT_MAX - 1) / 2 fits in a signed int. 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