| From: | Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com> |
|---|---|
| To: | PostgreSQL Hackers <pgsql-hackers(at)postgresql(dot)org> |
| Cc: | Jeff Davis <pgsql(at)j-davis(dot)com> |
| Subject: | Fixes bug in strlower_libc_sb() |
| Date: | 2025-11-25 03:03:50 |
| Message-ID: | CAEoWx2mW0P8CByavV58zm3=eb2MQHaKOcDEF5B2UJYRyC2c3ig@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi Hackers,
While reviewing Jeff's patch [1], I found this bug in strlower_libc_sb():
```
static size_t
strlower_libc_sb(char *dest, size_t destsize, const char *src, ssize_t
srclen,
pg_locale_t locale)
{
if (srclen < 0)
srclen = strlen(src);
if (srclen + 1 <= destsize)
{
locale_t loc = locale->lt;
char *p;
if (srclen + 1 > destsize) <== This check will never be true
return srclen;
```
So I removed the useless check in the patch.
I also noticed strlower_libc_sb’s behavior is different
from unicode_strlower(), where the function comment says:
```
* Result string is stored in dst, truncating if larger than dstsize. If
* dstsize is greater than the result length, dst will be NUL-terminated;
* otherwise not.
```
And Jeff’s new code in [1] matches the description. The behavior is like
trying the best to copy as many chars as possible, if not enough space in
dest, then NULL-terminator can be omitted. But the current behavior
of strlower_libc_sb that only copies data to dest when dest has enough
space for src and NULL-terminator.
So I updated strlower_libc_sb(), strtitle_libc_sb() and strupper_libc_sb()
to comply with the behavior in this patch as well. “Make check” passed from
my side, so the patch doesn't seem to break anything.
[1]
https://www.postgresql.org/message-id/450ceb6260cad30d7afdf155d991a9caafee7c0d.camel%40j-davis.com
Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Fixes-bug-in-strlower_libc_sb.patch | application/octet-stream | 6.5 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Peter Smith | 2025-11-25 03:33:18 | Re: Proposal: Conflict log history table for Logical Replication |
| Previous Message | jian he | 2025-11-25 02:59:42 | Re: CAST(... ON DEFAULT) - WIP build on top of Error-Safe User Functions |