summaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/varlena.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/backend/utils/adt/varlena.c')
-rw-r--r--src/backend/utils/adt/varlena.c77
1 files changed, 46 insertions, 31 deletions
diff --git a/src/backend/utils/adt/varlena.c b/src/backend/utils/adt/varlena.c
index 30f44e8c4d..9707c0f3fd 100644
--- a/src/backend/utils/adt/varlena.c
+++ b/src/backend/utils/adt/varlena.c
@@ -221,7 +221,7 @@ text_to_cstring_buffer(const text *src, char *dst, size_t dst_len)
dst_len--;
if (dst_len >= src_len)
dst_len = src_len;
- else /* ensure truncation is encoding-safe */
+ else /* ensure truncation is encoding-safe */
dst_len = pg_mbcliplen(VARDATA_ANY(srcunpacked), src_len, dst_len);
memcpy(dst, VARDATA_ANY(srcunpacked), dst_len);
dst[dst_len] = '\0';
@@ -268,7 +268,7 @@ byteain(PG_FUNCTION_ARGS)
bc = (len - 2) / 2 + VARHDRSZ; /* maximum possible length */
result = palloc(bc);
bc = hex_decode(inputText + 2, len - 2, VARDATA(result));
- SET_VARSIZE(result, bc + VARHDRSZ); /* actual length */
+ SET_VARSIZE(result, bc + VARHDRSZ); /* actual length */
PG_RETURN_BYTEA_P(result);
}
@@ -828,8 +828,8 @@ text_substring(Datum str, int32 start, int32 length, bool length_not_specified)
{
S1 = Max(S, 1);
- if (length_not_specified) /* special case - get length to end of
- * string */
+ if (length_not_specified) /* special case - get length to end of
+ * string */
L1 = -1;
else
{
@@ -893,8 +893,8 @@ text_substring(Datum str, int32 start, int32 length, bool length_not_specified)
*/
slice_start = 0;
- if (length_not_specified) /* special case - get length to end of
- * string */
+ if (length_not_specified) /* special case - get length to end of
+ * string */
slice_size = L1 = -1;
else
{
@@ -1017,8 +1017,8 @@ textoverlay(PG_FUNCTION_ARGS)
{
text *t1 = PG_GETARG_TEXT_PP(0);
text *t2 = PG_GETARG_TEXT_PP(1);
- int sp = PG_GETARG_INT32(2); /* substring start position */
- int sl = PG_GETARG_INT32(3); /* substring length */
+ int sp = PG_GETARG_INT32(2); /* substring start position */
+ int sl = PG_GETARG_INT32(3); /* substring length */
PG_RETURN_TEXT_P(text_overlay(t1, t2, sp, sl));
}
@@ -1028,10 +1028,10 @@ textoverlay_no_len(PG_FUNCTION_ARGS)
{
text *t1 = PG_GETARG_TEXT_PP(0);
text *t2 = PG_GETARG_TEXT_PP(1);
- int sp = PG_GETARG_INT32(2); /* substring start position */
+ int sp = PG_GETARG_INT32(2); /* substring start position */
int sl;
- sl = text_length(PointerGetDatum(t2)); /* defaults to length(t2) */
+ sl = text_length(PointerGetDatum(t2)); /* defaults to length(t2) */
PG_RETURN_TEXT_P(text_overlay(t1, t2, sp, sl));
}
@@ -1438,7 +1438,8 @@ varstr_cmp(char *arg1, int len1, char *arg2, int len2, Oid collid)
#ifdef WIN32
/* Win32 does not have UTF-8, so we need to map to UTF-16 */
- if (GetDatabaseEncoding() == PG_UTF8)
+ if (GetDatabaseEncoding() == PG_UTF8
+ && (!mylocale || mylocale->provider == COLLPROVIDER_LIBC))
{
int a1len;
int a2len;
@@ -1524,7 +1525,7 @@ varstr_cmp(char *arg1, int len1, char *arg2, int len2, Oid collid)
return result;
}
-#endif /* WIN32 */
+#endif /* WIN32 */
if (len1 >= TEXTBUFLEN)
a1p = (char *) palloc(len1 + 1);
@@ -1573,11 +1574,14 @@ varstr_cmp(char *arg1, int len1, char *arg2, int len2, Oid collid)
result = ucol_strcoll(mylocale->info.icu.ucol,
uchar1, ulen1,
uchar2, ulen2);
+
+ pfree(uchar1);
+ pfree(uchar2);
}
#else /* not USE_ICU */
/* shouldn't happen */
elog(ERROR, "unsupported collprovider: %c", mylocale->provider);
-#endif /* not USE_ICU */
+#endif /* not USE_ICU */
}
else
{
@@ -2143,7 +2147,7 @@ varstrfastcmp_locale(Datum x, Datum y, SortSupport ssup)
&status);
if (U_FAILURE(status))
ereport(ERROR,
- (errmsg("collation failed: %s", u_errorName(status))));
+ (errmsg("collation failed: %s", u_errorName(status))));
}
else
#endif
@@ -2159,11 +2163,14 @@ varstrfastcmp_locale(Datum x, Datum y, SortSupport ssup)
result = ucol_strcoll(sss->locale->info.icu.ucol,
uchar1, ulen1,
uchar2, ulen2);
+
+ pfree(uchar1);
+ pfree(uchar2);
}
#else /* not USE_ICU */
/* shouldn't happen */
elog(ERROR, "unsupported collprovider: %c", sss->locale->provider);
-#endif /* not USE_ICU */
+#endif /* not USE_ICU */
}
else
{
@@ -2283,7 +2290,7 @@ varstr_abbrev_convert(Datum original, SortSupport ssup)
Size bsize;
#ifdef USE_ICU
int32_t ulen = -1;
- UChar *uchar;
+ UChar *uchar = NULL;
#endif
/*
@@ -2354,16 +2361,17 @@ varstr_abbrev_convert(Datum original, SortSupport ssup)
&iter,
state,
(uint8_t *) sss->buf2,
- Min(sizeof(Datum), sss->buflen2),
+ Min(sizeof(Datum), sss->buflen2),
&status);
if (U_FAILURE(status))
ereport(ERROR,
- (errmsg("sort key generation failed: %s", u_errorName(status))));
+ (errmsg("sort key generation failed: %s",
+ u_errorName(status))));
}
else
bsize = ucol_getSortKey(sss->locale->info.icu.ucol,
uchar, ulen,
- (uint8_t *) sss->buf2, sss->buflen2);
+ (uint8_t *) sss->buf2, sss->buflen2);
}
else
#endif
@@ -2398,6 +2406,11 @@ varstr_abbrev_convert(Datum original, SortSupport ssup)
* okay. See remarks on bytea case above.)
*/
memcpy(pres, sss->buf2, Min(sizeof(Datum), bsize));
+
+#ifdef USE_ICU
+ if (uchar)
+ pfree(uchar);
+#endif
}
/*
@@ -2903,8 +2916,8 @@ byteaoverlay(PG_FUNCTION_ARGS)
{
bytea *t1 = PG_GETARG_BYTEA_PP(0);
bytea *t2 = PG_GETARG_BYTEA_PP(1);
- int sp = PG_GETARG_INT32(2); /* substring start position */
- int sl = PG_GETARG_INT32(3); /* substring length */
+ int sp = PG_GETARG_INT32(2); /* substring start position */
+ int sl = PG_GETARG_INT32(3); /* substring length */
PG_RETURN_BYTEA_P(bytea_overlay(t1, t2, sp, sl));
}
@@ -2914,7 +2927,7 @@ byteaoverlay_no_len(PG_FUNCTION_ARGS)
{
bytea *t1 = PG_GETARG_BYTEA_PP(0);
bytea *t2 = PG_GETARG_BYTEA_PP(1);
- int sp = PG_GETARG_INT32(2); /* substring start position */
+ int sp = PG_GETARG_INT32(2); /* substring start position */
int sl;
sl = VARSIZE_ANY_EXHDR(t2); /* defaults to length(t2) */
@@ -3277,7 +3290,7 @@ SplitIdentifierString(char *rawstring, char separator,
{
endp = strchr(nextp + 1, '"');
if (endp == NULL)
- return false; /* mismatched quotes */
+ return false; /* mismatched quotes */
if (endp[1] != '"')
break; /* found end of quoted name */
/* Collapse adjacent quotes into one quote, and look again */
@@ -3351,7 +3364,9 @@ SplitIdentifierString(char *rawstring, char separator,
/*
- * SplitDirectoriesString --- parse a string containing directory names
+ * SplitDirectoriesString --- parse a string containing file/directory names
+ *
+ * This works fine on file names too; the function name is historical.
*
* This is similar to SplitIdentifierString, except that the parsing
* rules are meant to handle pathnames instead of identifiers: there is
@@ -3402,7 +3417,7 @@ SplitDirectoriesString(char *rawstring, char separator,
{
endp = strchr(nextp + 1, '"');
if (endp == NULL)
- return false; /* mismatched quotes */
+ return false; /* mismatched quotes */
if (endp[1] != '"')
break; /* found end of quoted name */
/* Collapse adjacent quotes into one quote, and look again */
@@ -3934,7 +3949,7 @@ replace_text_regexp(text *src_text, void *regexp,
data,
data_len,
search_start,
- NULL, /* no details */
+ NULL, /* no details */
REGEXP_REPLACE_BACKREF_CNT,
pmatch,
0);
@@ -4246,14 +4261,14 @@ text_to_array_internal(PG_FUNCTION_ARGS)
/* XXX: this hardcodes assumptions about the text type */
PG_RETURN_ARRAYTYPE_P(construct_md_array(elems, nulls,
1, dims, lbs,
- TEXTOID, -1, false, 'i'));
+ TEXTOID, -1, false, 'i'));
}
start_posn = 1;
/* start_ptr points to the start_posn'th character of inputstring */
start_ptr = VARDATA_ANY(inputstring);
- for (fldnum = 1;; fldnum++) /* field number is 1 based */
+ for (fldnum = 1;; fldnum++) /* field number is 1 based */
{
CHECK_FOR_INTERRUPTS();
@@ -4697,7 +4712,7 @@ string_agg_transfn(PG_FUNCTION_ARGS)
else if (!PG_ARGISNULL(2))
appendStringInfoText(state, PG_GETARG_TEXT_PP(2)); /* delimiter */
- appendStringInfoText(state, PG_GETARG_TEXT_PP(1)); /* value */
+ appendStringInfoText(state, PG_GETARG_TEXT_PP(1)); /* value */
}
/*
@@ -5323,7 +5338,7 @@ text_format_parse_format(const char *start_ptr, const char *end_ptr,
if (*cp != '$')
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
- errmsg("width argument position must be ended by \"$\"")));
+ errmsg("width argument position must be ended by \"$\"")));
/* The number was width argument position */
*widthpos = n;
/* Explicit 0 for argument index is immediately refused */
@@ -5368,7 +5383,7 @@ text_format_string_conversion(StringInfo buf, char conversion,
else if (conversion == 'I')
ereport(ERROR,
(errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
- errmsg("null values cannot be formatted as an SQL identifier")));
+ errmsg("null values cannot be formatted as an SQL identifier")));
return;
}