Commit 649d8543 authored by Tom Lane's avatar Tom Lane

Fix lpad() and rpad() to produce correct results in variable-length

multibyte encodings.
parent f8728467
......@@ -9,7 +9,7 @@
*
*
* IDENTIFICATION
* $Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.36 2001/10/25 05:49:45 momjian Exp $
* $Header: /cvsroot/pgsql/src/backend/utils/adt/oracle_compat.c,v 1.37 2002/01/08 17:03:41 tgl Exp $
*
*-------------------------------------------------------------------------
*/
......@@ -200,10 +200,8 @@ lpad(PG_FUNCTION_ARGS)
#ifdef MULTIBYTE
bytelen = pg_database_encoding_max_length() * len;
ret = (text *) palloc(VARHDRSZ + bytelen);
VARATT_SIZEP(ret) = VARHDRSZ + bytelen;
#else
ret = (text *) palloc(VARHDRSZ + len);
VARATT_SIZEP(ret) = VARHDRSZ + len;
#endif
m = len - s1len;
......@@ -247,6 +245,8 @@ lpad(PG_FUNCTION_ARGS)
*ptr_ret++ = *ptr1++;
#endif
VARATT_SIZEP(ret) = ptr_ret - (char *) ret;
PG_RETURN_TEXT_P(ret);
}
......@@ -311,10 +311,8 @@ rpad(PG_FUNCTION_ARGS)
#ifdef MULTIBYTE
bytelen = pg_database_encoding_max_length() * len;
ret = (text *) palloc(VARHDRSZ + bytelen);
VARATT_SIZEP(ret) = VARHDRSZ + bytelen;
#else
ret = (text *) palloc(VARHDRSZ + len);
VARATT_SIZEP(ret) = VARHDRSZ + len;
#endif
m = len - s1len;
......@@ -358,6 +356,8 @@ rpad(PG_FUNCTION_ARGS)
}
#endif
VARATT_SIZEP(ret) = ptr_ret - (char *) ret;
PG_RETURN_TEXT_P(ret);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment