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 1viGpq-0021te-0q for pgsql-hackers@arkaria.postgresql.org; Tue, 20 Jan 2026 18:52:14 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1viGpo-002SxN-3B for pgsql-hackers@arkaria.postgresql.org; Tue, 20 Jan 2026 18:52:13 +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 1viGpo-002SxF-2G for pgsql-hackers@lists.postgresql.org; Tue, 20 Jan 2026 18:52:13 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1viGpm-001ZaG-2I for pgsql-hackers@postgresql.org; Tue, 20 Jan 2026 18:52:12 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 60KIq8LU1710698; Tue, 20 Jan 2026 13:52:08 -0500 From: Tom Lane To: John Naylor cc: Alexander Lakhin , pgsql-hackers Subject: Re: Undefined behavior detected by new clang's ubsan In-reply-to: References: <777bd201-6e3a-4da0-a922-4ea9de46a3ee@gmail.com> <7ea15f17-f001-4b5c-979d-b9cff4db46bb@gmail.com> Comments: In-reply-to John Naylor message dated "Tue, 20 Jan 2026 14:48:03 +0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1710696.1768935128.1@sss.pgh.pa.us> Date: Tue, 20 Jan 2026 13:52:08 -0500 Message-ID: <1710697.1768935128@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk John Naylor writes: > I don't think it's great to pass a NULL pointer to a sort, but the > length could conceivably be zero for future degenerate cases, so we > could silence the warning by adding "if (n < 2) return;" before the > for-loop. The advantage of doing that anyway is it allows us to remove > all four of the "if (d_ > ST_POINTER_STEP)" branches in the recursion > part. That's better for readability. +1 regards, tom lane