Skip to content

Commit cb1b0df

Browse files
committed
Use local helper for identifier case rewrite in varlena
The previous revision used two in-place copy patterns after identifier_case_transform(): strncpy() in one path and memcpy()+NUL termination in another. Keeping both patterns makes behavior easier to drift and harder to review. Introduce a varlena-local helper for this rewrite path, keep identifier_case_transform() unchanged for other callers, and centralize the post-transform copy and cleanup in one place.
1 parent be7f6e4 commit cb1b0df

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

src/backend/utils/adt/varlena.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ static char *text_position_next_internal(char *start_ptr, TextPositionState *sta
143143
static char *text_position_get_match_ptr(TextPositionState *state);
144144
static int text_position_get_match_pos(TextPositionState *state);
145145
static void text_position_cleanup(TextPositionState *state);
146+
static void identifier_case_transform_cstring(char *ident);
146147
static void check_collation_set(Oid collid);
147148
static int text_cmp(text *arg1, text *arg2, Oid collid);
148149
static void appendStringInfoText(StringInfo str, const text *t);
@@ -2753,6 +2754,18 @@ textToQualifiedNameList(text *textval)
27532754
return result;
27542755
}
27552756

2757+
static void
2758+
identifier_case_transform_cstring(char *ident)
2759+
{
2760+
size_t len = strlen(ident);
2761+
char *new_name;
2762+
2763+
new_name = identifier_case_transform(ident, len);
2764+
Assert(strlen(new_name) == len);
2765+
strcpy(ident, new_name);
2766+
pfree(new_name);
2767+
}
2768+
27562769
/*
27572770
* SplitIdentifierString --- parse a string containing identifiers
27582771
*
@@ -2871,11 +2884,7 @@ SplitIdentifierString(char *rawstring, char separator,
28712884
if (compatible_db == ORA_PARSER && enable_case_switch
28722885
&& identifier_case_switch == INTERCHANGE && need_case_switch)
28732886
{
2874-
char *new_name;
2875-
2876-
new_name = identifier_case_transform(curname, strlen(curname));
2877-
strncpy(curname, new_name, strlen(curname));
2878-
pfree(new_name);
2887+
identifier_case_transform_cstring(curname);
28792888
}
28802889

28812890
/* Truncate name if it's overlength */
@@ -3218,12 +3227,7 @@ SplitGUCList(char *rawstring, char separator,
32183227
if (compatible_db == ORA_PARSER && enable_case_switch
32193228
&& identifier_case_switch == INTERCHANGE && need_case_switch)
32203229
{
3221-
char *new_name;
3222-
3223-
new_name = identifier_case_transform(curname, strlen(curname));
3224-
memcpy(curname, new_name, strlen(new_name));
3225-
curname[strlen(new_name)] = '\0';
3226-
pfree(new_name);
3230+
identifier_case_transform_cstring(curname);
32273231
}
32283232

32293233
/*

0 commit comments

Comments
 (0)