Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit403cbd2

Browse files
committed
Relax check for return value from second call of pg_strnxfrm().
strxfrm() is not guaranteed to return the exact number of bytes neededto store the result; it may return a higher value.Discussion:https://postgr.es/m/32f85d88d1f64395abfe5a10dd97a62a4d3474ce.camel@j-davis.comReviewed-by: Heikki LinnakangasBackpatch-through: 16
1 parent9d198f4 commit403cbd2

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

‎src/backend/access/hash/hashfunc.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,9 @@ hashtext(PG_FUNCTION_ARGS)
300300
buf=palloc(bsize+1);
301301

302302
rsize=pg_strnxfrm(buf,bsize+1,keydata,keylen,mylocale);
303-
if (rsize!=bsize)
303+
304+
/* the second call may return a smaller value than the first */
305+
if (rsize>bsize)
304306
elog(ERROR,"pg_strnxfrm() returned unexpected result");
305307

306308
/*
@@ -354,7 +356,9 @@ hashtextextended(PG_FUNCTION_ARGS)
354356
buf=palloc(bsize+1);
355357

356358
rsize=pg_strnxfrm(buf,bsize+1,keydata,keylen,mylocale);
357-
if (rsize!=bsize)
359+
360+
/* the second call may return a smaller value than the first */
361+
if (rsize>bsize)
358362
elog(ERROR,"pg_strnxfrm() returned unexpected result");
359363

360364
/*

‎src/backend/utils/adt/pg_locale.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2288,9 +2288,9 @@ pg_strxfrm_enabled(pg_locale_t locale)
22882288
* The provided 'src' must be nul-terminated. If 'destsize' is zero, 'dest'
22892289
* may be NULL.
22902290
*
2291-
* Returns the number of bytes needed to store the transformed string,
2292-
* excluding the terminating nul byte. If the value returned is 'destsize' or
2293-
* greater, the resulting contents of 'dest' are undefined.
2291+
* Returns the number of bytes needed(or more)to store the transformed
2292+
*string,excluding the terminating nul byte. If the value returned is
2293+
*'destsize' orgreater, the resulting contents of 'dest' are undefined.
22942294
*/
22952295
size_t
22962296
pg_strxfrm(char*dest,constchar*src,size_tdestsize,pg_locale_tlocale)
@@ -2320,9 +2320,9 @@ pg_strxfrm(char *dest, const char *src, size_t destsize, pg_locale_t locale)
23202320
* 'src' does not need to be nul-terminated. If 'destsize' is zero, 'dest' may
23212321
* be NULL.
23222322
*
2323-
* Returns the number of bytes needed to store the transformed string,
2324-
* excluding the terminating nul byte. If the value returned is 'destsize' or
2325-
* greater, the resulting contents of 'dest' are undefined.
2323+
* Returns the number of bytes needed(or more)to store the transformed
2324+
*string,excluding the terminating nul byte. If the value returned is
2325+
*'destsize' orgreater, the resulting contents of 'dest' are undefined.
23262326
*
23272327
* This function may need to nul-terminate the argument for libc functions;
23282328
* so if the caller already has a nul-terminated string, it should call

‎src/backend/utils/adt/varchar.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,9 @@ hashbpchar(PG_FUNCTION_ARGS)
10291029
buf=palloc(bsize+1);
10301030

10311031
rsize=pg_strnxfrm(buf,bsize+1,keydata,keylen,mylocale);
1032-
if (rsize!=bsize)
1032+
1033+
/* the second call may return a smaller value than the first */
1034+
if (rsize>bsize)
10331035
elog(ERROR,"pg_strnxfrm() returned unexpected result");
10341036

10351037
/*
@@ -1085,7 +1087,9 @@ hashbpcharextended(PG_FUNCTION_ARGS)
10851087
buf=palloc(bsize+1);
10861088

10871089
rsize=pg_strnxfrm(buf,bsize+1,keydata,keylen,mylocale);
1088-
if (rsize!=bsize)
1090+
1091+
/* the second call may return a smaller value than the first */
1092+
if (rsize>bsize)
10891093
elog(ERROR,"pg_strnxfrm() returned unexpected result");
10901094

10911095
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp