Skip to content

Commit 649d854

Browse files
committed
Fix lpad() and rpad() to produce correct results in variable-length
multibyte encodings.
1 parent f872846 commit 649d854

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/backend/utils/adt/oracle_compat.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
*
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.36 2001/10/25 05:49:45 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.37 2002/01/08 17:03:41 tgl Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -200,10 +200,8 @@ lpad(PG_FUNCTION_ARGS)
200200
#ifdef MULTIBYTE
201201
bytelen = pg_database_encoding_max_length() * len;
202202
ret = (text *) palloc(VARHDRSZ + bytelen);
203-
VARATT_SIZEP(ret) = VARHDRSZ + bytelen;
204203
#else
205204
ret = (text *) palloc(VARHDRSZ + len);
206-
VARATT_SIZEP(ret) = VARHDRSZ + len;
207205
#endif
208206
m = len - s1len;
209207

@@ -247,6 +245,8 @@ lpad(PG_FUNCTION_ARGS)
247245
*ptr_ret++ = *ptr1++;
248246
#endif
249247

248+
VARATT_SIZEP(ret) = ptr_ret - (char *) ret;
249+
250250
PG_RETURN_TEXT_P(ret);
251251
}
252252

@@ -311,10 +311,8 @@ rpad(PG_FUNCTION_ARGS)
311311
#ifdef MULTIBYTE
312312
bytelen = pg_database_encoding_max_length() * len;
313313
ret = (text *) palloc(VARHDRSZ + bytelen);
314-
VARATT_SIZEP(ret) = VARHDRSZ + bytelen;
315314
#else
316315
ret = (text *) palloc(VARHDRSZ + len);
317-
VARATT_SIZEP(ret) = VARHDRSZ + len;
318316
#endif
319317
m = len - s1len;
320318

@@ -358,6 +356,8 @@ rpad(PG_FUNCTION_ARGS)
358356
}
359357
#endif
360358

359+
VARATT_SIZEP(ret) = ptr_ret - (char *) ret;
360+
361361
PG_RETURN_TEXT_P(ret);
362362
}
363363

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy