Re: BUG #19341: REPLACE() fails to match final character when using nondeterministic ICU collation

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Heikki Linnakangas <hlinnaka(at)iki(dot)fi>, adam(dot)warland(at)infor(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19341: REPLACE() fails to match final character when using nondeterministic ICU collation
Date: 2025-12-02 17:51:14
Message-ID: 464a14fcbee9567ace136716714b8c18f9bd87fb.camel@cybertec.at
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

On Tue, 2025-12-02 at 12:25 -0500, Tom Lane wrote:
> Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)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 Content-Type Size
v3-0001-Fix-greedy-substring-search-for-non-deterministic.patch text/x-patch 3.5 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Dean Rasheed 2025-12-02 18:54:20 Re: BUG #19340: Wrong result from CORR() function
Previous Message Laurenz Albe 2025-12-02 17:45:47 Re: BUG #19341: REPLACE() fails to match final character when using nondeterministic ICU collation