From d4493fe9d75378245d6ef0262e5a31525e88f7f2 Mon Sep 17 00:00:00 2001 From: Tatsuo Ishii Date: Mon, 15 Apr 2002 07:54:37 +0000 Subject: [PATCH] Fix text_substr bug intrduced in 7.3 development using Joe Conway's patches (submitted at pgsql-patches on 2002/04/08) + small fix. --- src/backend/utils/adt/varlena.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c index 20f6c72c49..b4e5d336f9 100644 --- a/src/backend/utils/adt/varlena.c +++ b/src/backend/utils/adt/varlena.c @@ -373,7 +373,10 @@ text_substr(PG_FUNCTION_ARGS) if (eml > 1) { sm = 0; - sn = (m + n) * eml + 3; /* +3 to avoid mb characters overhanging slice end */ + if (n > -1) + sn = (m + n) * eml + 3; /* +3 to avoid mb characters overhanging slice end */ + else + sn = n; /* n < 0 is special-cased by heap_tuple_untoast_attr_slice */ } #endif @@ -387,7 +390,10 @@ text_substr(PG_FUNCTION_ARGS) PG_RETURN_NULL(); /* notreached: suppress compiler warning */ #endif #ifdef MULTIBYTE - len = pg_mbstrlen_with_len (VARDATA (string), sn - 3); + if (n > -1) + len = pg_mbstrlen_with_len (VARDATA (string), sn - 3); + else /* n < 0 is special-cased; need full string length */ + len = pg_mbstrlen_with_len (VARDATA (string), VARSIZE(string)-VARHDRSZ); if (m > len) { -- 2.39.5