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.96) (envelope-from ) id 1w8QHC-000W6E-0S for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Apr 2026 22:12:34 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w8QHA-008L3r-1d for pgsql-hackers@arkaria.postgresql.org; Thu, 02 Apr 2026 22:12:32 +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.96) (envelope-from ) id 1w8QHA-008L3j-0f for pgsql-hackers@lists.postgresql.org; Thu, 02 Apr 2026 22:12:32 +0000 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w8QH8-00000000Gw6-03MU for pgsql-hackers@lists.postgresql.org; Thu, 02 Apr 2026 22:12:32 +0000 Received: by mail-wr1-x431.google.com with SMTP id ffacd0b85a97d-43b95e5b3afso828838f8f.3 for ; Thu, 02 Apr 2026 15:12:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1775167948; cv=none; d=google.com; s=arc-20240605; b=V/UmPb5HVPqiKRqmcKryhQpPgrewSz8onTnvyxQ/Pzh/7l4BSQY6vvZa3C7dw3cGxE JJEXEJRzsH4eqUZxy9agO23oj9WZOgolu81JtkZIAuO+dxktIOl0k7mkMVXOFjypLTO7 hwrwnnX90J3n56m8dgoxSxsYkvDtywxz/OLAJ49SPX72nq1taju9i88ROQY78FaT/5OE P5rvXdB8eq1mQRGp+OXdiZBQmgL8gl3IPfpNVaUIpbNmVXq5FdboslwE41wpcpj5FX2N sF8Mf77GzG/T7E2zkXASvaKHY7Zovli7yQsw2jGD3/BhX2ax4UG+88DPFs9huAwAmfM0 q1uA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=lsrV0TQq6DLYh4Ynv+RuZE+LwBidOUBwJmnvapKPmwg=; fh=lK8Ey75qlt4w4S087HA2sQsiHJBeqk3Wvx6fjumIn6g=; b=DoJNzUvbST9pEpZLcH12oCFj8mW7CSjBm77D8fVYhvf2ys39sKcL/uu5wDZHRaoD6b SvSnMpm4MGmN2W/ksih/JXVI7ks3nZSR7S886vNAMiirDdJuoidVTJh/xhZJoLra+9Dr HyP/oFFQdaX+Ts0lqQa2BG4OzyVtCreUVhUFFGyOGTYO6eV0fIWbHGZLTNeXTCdMEGPj nxTGWpVaR9aCg0JNoVoJnUbnEAvncL9VPuI3xs7Fy0RFSQHD3FnlnBThwBiuj3kqa8+2 kx+ZDRu5XJxsGJNDE8tYTnLpIF0hKEWhE/QunHC31E4EteqL223LR4j5C33rOXkKDqBq Vq6w==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775167948; x=1775772748; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=lsrV0TQq6DLYh4Ynv+RuZE+LwBidOUBwJmnvapKPmwg=; b=JvTM2rXQ+tAQ+9lq2OlZkf9frzQj787UIKEviruuwCSsp25whAU3ubbXyLl4FNjbC7 YSidQ7aSVymt/zMSMVZvhWNSSIZHw783+CmaxSdtmo69fyLiPs/473mhSJqbEY3Ph5da CztSCSl7dIzNnvTcY5WZqt01asCnvjyGMweWVdgYR+89bzsO6bh5nyEZs9lFMsPxbu1R b0eZDdMlCf8X1PnsrZQl3LyZQMQp+YVMV3NHnfjikT3eROlpEgmjgX5GqxslSjq+Ur4U p27pfa0sjmSF3y8q/Z59c812gV49JEBIe/4lQ2vtMOUKzY54pavXcBU+faHgIfTNFnl8 474w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775167948; x=1775772748; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=lsrV0TQq6DLYh4Ynv+RuZE+LwBidOUBwJmnvapKPmwg=; b=cUHFZD62Bnu9UzlFc/hhHLYHCf5CgKFeqJgVHZoegNEyQSWkhlILp103W0/QPy0A1l aoAotry+QgCicoGaPnLb3rgIVaxSHFcuY9AMBVL5lfeMGN5ftND2SZDKkbB7V9LX/7tE MlSdT5meNEUc5Sgobv3acmeMvt/jmmZf04dZG4dxNQiReq7vYoordEh3ijgSU6t9IsZI /eW4FJifUfFT9UNQbTv2zu0otJVznFXBUgefcM5TKzgyWSr84oMmqGbYyuigdB4LIN1U Zh6960ltO3Wqwkglt6l64vq7t0dff5WhUSWwjFvDbJS5zWOnGQigjaW2cBJQTVPKSmFP WsEg== X-Gm-Message-State: AOJu0Ywk7A8SEWlKhsGA0qvRCWlWiNpyJRbt2jq/fJ2WsjnGIWH+kzRn RheKeNYnhd1+RwETfT7aCk446tRYbkU0ZElfdSG3k1Pkg4crbSJ0ocljk1m/8bUwPBfS0ZJz951 IO6HhECe/JQMXbR4CJRhtGueH+Cc8Yc69d75i X-Gm-Gg: AeBDietfOxh02y1ZSJqotk8PUP9XINZDQ/YM7QzIhqrBJQWPYUnCvJq/uCTa2x/EWr9 siBQozHh2DnzQHLKex5g+W/uriJmPexsoU4fEgVqwTETrocddMV69p+2NL972cMoiSNEgU/nT3D 3ZM5ftpqiwHWO1fLu5S4HdS8Nc+8PAPMtN3U5XrY5uBEjn9oY11YZ9VpX0+DzmR8JdM66wi8eZR oBwjDA3kofkjwVbF1rbd5E7YGfHugenhbhHezybAPNy7zJUDyJbACH1HY06zjKmOII+dDwcdDmT CA81Az42c4mCnyhjCEi9UrNdNLEkf/GV+FO/NmUBFRltWNnm+upZmB1Oc79Ol9pU0zSG63FejQ= = X-Received: by 2002:a05:6000:40dd:b0:43b:8858:1146 with SMTP id ffacd0b85a97d-43d292e7fd9mr1166946f8f.41.1775167947415; Thu, 02 Apr 2026 15:12:27 -0700 (PDT) MIME-Version: 1.0 References: <3190647.1775103768@sss.pgh.pa.us> In-Reply-To: <3190647.1775103768@sss.pgh.pa.us> From: David Rowley Date: Fri, 3 Apr 2026 11:12:15 +1300 X-Gm-Features: AQROBzCnYIDU0cNs74Nljg_gKOGTlAb4vwPZgKrNMFWFJmBm-UcBhjjJ3Q-LUEk Message-ID: Subject: Re: Small and unlikely overflow hazard in bms_next_member() To: Tom Lane Cc: PostgreSQL Developers Content-Type: text/plain; charset="UTF-8" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, 2 Apr 2026 at 17:22, Tom Lane wrote: > Assert(prevbit <= a->nwords * BITS_PER_BITMAPWORD); > but if the bitmapset were large enough to accommodate INT_MAX > as a member then a->nwords * BITS_PER_BITMAPWORD must overflow. I missed that one. That's annoying. Even "prevbit = a->nwords * BITS_PER_BITMAPWORD - 1;" is undefined if it wraps due to the signed maths. > I don't think we should add cycles here for this purpose. I'm not keen on slowing things down for this either. I did do some experiments in [1] that sees fewer instructions from using 64-bit maths. I might go off and see if there are any wins there that also give us the INT_MAX fix. It's not great effort to reward ratio though... David [1] https://godbolt.org/z/Eh1vzssq7