Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 94077df

Browse files
committed
Avoid casting away const in sepgsql's quote_object_name.
quote_identifier's API is designed on the assumption that it's not worth worrying about a short-term memory leak when we have to produce a quoted version of the given identifier. Whoever wrote quote_object_name took it on themselves to override that judgment, but the only way to do so is to cast away const someplace. We can avoid that and substantially shorten the function by going along with quote_identifier's opinion. AFAICS quote_object_name is not used in any way where this would be unsustainable. Per discussion of commit 45987aa, which exposed that we had a casting-away-const situation here. Discussion: https://postgr.es/m/20220827112304.GL2342@telsasoft.com
1 parent d1ce745 commit 94077df

File tree

1 file changed

+6
-27
lines changed

1 file changed

+6
-27
lines changed

contrib/sepgsql/label.c

+6-27
Original file line numberDiff line numberDiff line change
@@ -646,45 +646,24 @@ sepgsql_mcstrans_out(PG_FUNCTION_ARGS)
646646
/*
647647
* quote_object_name
648648
*
649-
* It tries to quote the supplied identifiers
649+
* Concatenate as many of the given strings as aren't NULL, with dots between.
650+
* Quote any of the strings that wouldn't be valid identifiers otherwise.
650651
*/
651652
static char *
652653
quote_object_name(const char *src1, const char *src2,
653654
const char *src3, const char *src4)
654655
{
655656
StringInfoData result;
656-
const char *temp;
657657

658658
initStringInfo(&result);
659-
660659
if (src1)
661-
{
662-
temp = quote_identifier(src1);
663-
appendStringInfoString(&result, temp);
664-
if (src1 != temp)
665-
pfree(temp);
666-
}
660+
appendStringInfoString(&result, quote_identifier(src1));
667661
if (src2)
668-
{
669-
temp = quote_identifier(src2);
670-
appendStringInfo(&result, ".%s", temp);
671-
if (src2 != temp)
672-
pfree(temp);
673-
}
662+
appendStringInfo(&result, ".%s", quote_identifier(src2));
674663
if (src3)
675-
{
676-
temp = quote_identifier(src3);
677-
appendStringInfo(&result, ".%s", temp);
678-
if (src3 != temp)
679-
pfree(temp);
680-
}
664+
appendStringInfo(&result, ".%s", quote_identifier(src3));
681665
if (src4)
682-
{
683-
temp = quote_identifier(src4);
684-
appendStringInfo(&result, ".%s", temp);
685-
if (src4 != temp)
686-
pfree(temp);
687-
}
666+
appendStringInfo(&result, ".%s", quote_identifier(src4));
688667
return result.data;
689668
}
690669

0 commit comments

Comments
 (0)