Re: BUG #19341: REPLACE() fails to match final character when using nondeterministic ICU collation - Mailing list pgsql-bugs

From Laurenz Albe
Subject Re: BUG #19341: REPLACE() fails to match final character when using nondeterministic ICU collation
Date
Msg-id 464a14fcbee9567ace136716714b8c18f9bd87fb.camel@cybertec.at
Whole thread Raw
In response to Re: BUG #19341: REPLACE() fails to match final character when using nondeterministic ICU collation  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: BUG #19341: REPLACE() fails to match final character when using nondeterministic ICU collation
List pgsql-bugs
On Tue, 2025-12-02 at 12:25 -0500, Tom Lane wrote:
> Laurenz Albe <laurenz.albe@cybertec.at> writes:
> > > > for (const char *test_end = hptr; test_end <= haystack_end; test_end += pg_mblen(test_end))
>
> > During the last iteration of the loop, "test_end" will be equal to "haystack_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.

Right.  The attached patch v3 turns it into a while loop to avoid
the problem.

Yours,
Laurenz Albe

Attachment

pgsql-bugs by date:

Previous
From: Laurenz Albe
Date:
Subject: Re: BUG #19341: REPLACE() fails to match final character when using nondeterministic ICU collation
Next
From: Dean Rasheed
Date:
Subject: Re: BUG #19340: Wrong result from CORR() function