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 1vQU8i-008l1R-16 for pgsql-bugs@arkaria.postgresql.org; Tue, 02 Dec 2025 17:26:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1vQU8h-009ECx-15 for pgsql-bugs@arkaria.postgresql.org; Tue, 02 Dec 2025 17:26:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vQU8h-009ECp-0J for pgsql-bugs@lists.postgresql.org; Tue, 02 Dec 2025 17:26:11 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1vQU8e-002meo-0r for pgsql-bugs@lists.postgresql.org; Tue, 02 Dec 2025 17:26:10 +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 5B2HPqRn375808; Tue, 2 Dec 2025 12:25:52 -0500 From: Tom Lane To: Laurenz Albe cc: Heikki Linnakangas , adam.warland@infor.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #19341: REPLACE() fails to match final character when using nondeterministic ICU collation In-reply-to: <9f47c6b24d6cf59002603caf19b8b3f4854176be.camel@cybertec.at> References: <19341-1d9a22915edfec58@postgresql.org> <60b467ac47d5c6bbb9c21c3bdfecce8e5de60cda.camel@cybertec.at> <6935ea1e-cfb1-400b-9057-3d43b55d621a@iki.fi> <9f47c6b24d6cf59002603caf19b8b3f4854176be.camel@cybertec.at> Comments: In-reply-to Laurenz Albe message dated "Tue, 02 Dec 2025 18:18:11 +0100" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <375806.1764696352.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Tue, 02 Dec 2025 12:25:52 -0500 Message-ID: <375807.1764696352@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Laurenz Albe writes: >>> for (const char *test_end =3D hptr; test_end <=3D haystack_end; test_e= nd +=3D pg_mblen(test_end)) > During the last iteration of the loop, "test_end" will be equal to "hays= tack_end", > and the loop increment will call "pg_mblen(test_end)". Right, clearly unsafe (and I bet valgrind would complain about it). You need to rearrange the loop logic so that we won't attempt to increment test_end that last time through. Perhaps a for-loop isn't the best way to write it. regards, tom lane