Skip to content

Commit

Permalink
Return a new string instead of modifying
Browse files Browse the repository at this point in the history
Signed-off-by: Chenxiao Wang <[email protected]>
  • Loading branch information
Chenxiao Wang committed Dec 23, 2024
1 parent 569c4e1 commit 5869be1
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions contrib/babelfishpg_tsql/src/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -5886,7 +5886,7 @@ remove_db_name_in_schema(const char *object_name)
char *schema_name = NULL;
char *mutable_name;
size_t db_name_len;
size_t prefix_len;
size_t prefix_len = 0;
size_t schema_name_len;

mutable_name = pstrdup(object_name);
Expand All @@ -5899,12 +5899,11 @@ remove_db_name_in_schema(const char *object_name)
cur_db_name = get_cur_db_name();
db_name_len = strlen(cur_db_name);
schema_name_len = strlen(schema_name);
prefix_len = db_name_len + 1;

if (schema_name != NULL && schema_name_len > db_name_len && strncmp(schema_name, cur_db_name, db_name_len) == 0 && schema_name[db_name_len] == '_') {
/* Return the part after the prefix */
object_name += prefix_len;
}
prefix_len = db_name_len + 1;
}
pfree(cur_db_name);
}

Expand All @@ -5913,5 +5912,5 @@ remove_db_name_in_schema(const char *object_name)
pfree(splited_object_name[k]);
pfree(splited_object_name);

return object_name;
return (const char *)pstrdup(object_name + prefix_len);
}

0 comments on commit 5869be1

Please sign in to comment.