Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sf1tz-000QRq-P9 for pgsql-hackers@arkaria.postgresql.org; Fri, 16 Aug 2024 18:42:19 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1sf1sy-00030S-Ro for pgsql-hackers@arkaria.postgresql.org; Fri, 16 Aug 2024 18:41:17 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1sf1sy-000308-CH for pgsql-hackers@lists.postgresql.org; Fri, 16 Aug 2024 18:41:17 +0000 Received: from mail-il1-x130.google.com ([2607:f8b0:4864:20::130]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1sf1n0-005DN4-Ex for pgsql-hackers@lists.postgresql.org; Fri, 16 Aug 2024 18:35:08 +0000 Received: by mail-il1-x130.google.com with SMTP id e9e14a558f8ab-39d2e4d73bcso2657745ab.1 for ; Fri, 16 Aug 2024 11:35:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723833304; x=1724438104; darn=lists.postgresql.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=frxnEC2u2X/4U3aeQsPtbA9M/KuyPsAc6a14k2J421Y=; b=X3L3tfbAm0FQDGqI19ElCQSubq+niPmPhnSDHOlrAbTU6J0GhqlNWMk/pKtKhgMG2K i0RPZVFHitVZsuO+fcIKRi4Ie+5Hx11ADfeAyVI8Ps2DaRSz/jAABgUMuyCWhUg/MNcE FZi8O/bEZLc/kavYDwD1Zm+fV/K+d1IQSiA+PvnVGbxL/zw/uggfkICXFi8Lw1zksc4N StUOp1UCEpg0nuGXOkJHcR9vIPQjq4tycAZkrEdZwG7B3Fl9/5KB6dE5pklZRCWq2JQs zwRJr+DfZf+RDyrxFTjdBIPKiWEU84GcdRhglImCZxeZF+qKFSatIRP5+HvGcXPGXn8o SNSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723833304; x=1724438104; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=frxnEC2u2X/4U3aeQsPtbA9M/KuyPsAc6a14k2J421Y=; b=tyUNVjrsO66PmSg+8ImVOmVHmhXGv5pgpNF9b5rwfATp2UfMcR4F2TbDlDkT+BeDqx 6t81Z/xh2j+OBe/iQYcx8vhR0kYuoQePuiqqyaGukhpgBRXW0IZI2ZS+bApLmTd+Lw+q TdYfuP59imfHQYIUgNOYKeDw6VsZTvKSVUToE5Mryy+wAndrkZEmUrb7Jg5REfYO1Dyx phcwyYgjw1opKiOvZuG8dvjDRopB2Lztfp1wdjEcSii1lUo9j4+9HODPJSIsVU1P7acb k2duCw/G1SXI8Fpq86l/DfsnFz6aeEpVnJY9beFfpxEvH8kUek3/r3tym01sbeOVyzB+ ZrLw== X-Forwarded-Encrypted: i=1; AJvYcCXshs9CQ42zKnPDW9HLByQWmvTSiqAEoB6HanaP/1OYLHo6XDL5cJlB1ib2tCkAupHwa1IePUXYHb+a/1h+z237KFOHOqknMVK7CI+ib2drhhzz X-Gm-Message-State: AOJu0Yx3UCHoQNl9Fto5K9+gMpvBE7ajOt/83mqPpXXNmxo35WHitpLM fZwPleEY9mq4mm8QWNMI3WH8f+0HK/z4FEM4WNW4qZMvVNyUoPck X-Google-Smtp-Source: AGHT+IGTdhRSzV8oNaew4ilzxFLmYktnL71KyQzej1uZegQOw+7SC1lHEA8WlMhH4r9Zg38bJRMaVg== X-Received: by 2002:a05:6e02:12e4:b0:376:1299:81e8 with SMTP id e9e14a558f8ab-39d32351172mr4235445ab.28.1723833303751; Fri, 16 Aug 2024 11:35:03 -0700 (PDT) Received: from nathan (162-195-168-172.lightspeed.stlsmo.sbcglobal.net. [162.195.168.172]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-39d1ead53e6sm15143985ab.4.2024.08.16.11.35.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Aug 2024 11:35:03 -0700 (PDT) Date: Fri, 16 Aug 2024 13:35:01 -0500 From: Nathan Bossart To: Alexander Lakhin Cc: Joseph Koshakow , jian he , Heikki Linnakangas , Matthew Kim , Tom Lane , PostgreSQL Hackers , Andres Freund Subject: Re: Remove dependence on integer wrapping Message-ID: References: <875ad3ec-f216-487e-baad-cdbaf32c1fcf@iki.fi> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, Aug 16, 2024 at 09:00:00PM +0300, Alexander Lakhin wrote: > Sp it looks like jsonb_array_element_text() still needs the same > treatment as jsonb_array_element(). D'oh. I added a test for that but didn't actually fix the code. I think we just need something like the following. diff --git a/src/backend/utils/adt/jsonfuncs.c b/src/backend/utils/adt/jsonfuncs.c index 1f8ea51e6a..69cdd84393 100644 --- a/src/backend/utils/adt/jsonfuncs.c +++ b/src/backend/utils/adt/jsonfuncs.c @@ -990,7 +990,7 @@ jsonb_array_element_text(PG_FUNCTION_ARGS) { uint32 nelements = JB_ROOT_COUNT(jb); - if (-element > nelements) + if (pg_abs_s32(element) > nelements) PG_RETURN_NULL(); else element += nelements; > Moreover, I tried to use "-ftrapv" on 32-bit Debian and came across > another failure: > select '9223372036854775807'::int8 * 2147483648::int8; > server closed the connection unexpectedly > ... > #4  0xb722226a in __GI_abort () at ./stdlib/abort.c:79 > #5  0x004cb2e1 in __mulvdi3.cold () > #6  0x00abe7ab in pg_mul_s64_overflow (a=9223372036854775807, b=2147483648, result=0xbff1da68) >     at ../../../../src/include/common/int.h:264 > #7  0x00abfbff in int8mul (fcinfo=0x14d9d04) at int8.c:496 > #8  0x00782675 in ExecInterpExpr (state=0x14d9c4c, econtext=0x14da15c, isnull=0xbff1dc3f) at execExprInterp.c:765 Hm. It looks like that is pointing to __builtin_mul_overflow(), which seems strange. > #6  0x00005576cf627c68 in bms_singleton_member (a=0x5576d09f7fb0) at bitmapset.c:691 > 691                             if (result >= 0 || HAS_MULTIPLE_ONES(w)) At a glance, this appears to be caused by the RIGHTMOST_ONE macro: #define RIGHTMOST_ONE(x) ((signedbitmapword) (x) & -((signedbitmapword) (x))) -- nathan