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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
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:25:52
Message-ID: 375807.1764696352@sss.pgh.pa.us
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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.

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Heikki Linnakangas 2025-12-02 17:29:06 Re: BUG #19341: REPLACE() fails to match final character when using nondeterministic ICU collation
Previous Message Laurenz Albe 2025-12-02 17:22:28 Re: BUG #19340: Wrong result from CORR() function