Fix misuse of "volatile" in xml.c

What should be used is not "volatile foo *ptr" but "foo *volatile ptr",
The incorrect (former) style means that what the pointer variable points
to is volatile.  The correct (latter) style means that the pointer
variable itself needs to be treated as volatile.  The latter style is
required to ensure a consistent treatment of these variables after a
longjmp with the TRY/CATCH blocks.

Some casts can be removed thanks to this change.

Issue introduced by 2e94721747, so no backpatch is required.  A
similar set of issues has been fixed in 93001888d8 for contrib/xml2/.

Author: ChangAo Chen <cca5507@qq.com>
Discussion: https://postgr.es/m/tencent_5BE8DAD985EE140ED62EA728C8D4E1311F0A@qq.com
This commit is contained in:
Michael Paquier 2026-03-10 07:05:32 +09:00
parent 7c8280eeb5
commit 6307b096e2

View file

@ -529,7 +529,7 @@ xmltext(PG_FUNCTION_ARGS)
#ifdef USE_LIBXML
text *arg = PG_GETARG_TEXT_PP(0);
text *result;
volatile xmlChar *xmlbuf = NULL;
xmlChar *volatile xmlbuf = NULL;
PgXmlErrorContext *xmlerrcxt;
/* First we gotta spin up some error handling. */
@ -544,19 +544,19 @@ xmltext(PG_FUNCTION_ARGS)
"could not allocate xmlChar");
result = cstring_to_text_with_len((const char *) xmlbuf,
xmlStrlen((const xmlChar *) xmlbuf));
xmlStrlen(xmlbuf));
}
PG_CATCH();
{
if (xmlbuf)
xmlFree((xmlChar *) xmlbuf);
xmlFree(xmlbuf);
pg_xml_done(xmlerrcxt, true);
PG_RE_THROW();
}
PG_END_TRY();
xmlFree((xmlChar *) xmlbuf);
xmlFree(xmlbuf);
pg_xml_done(xmlerrcxt, false);
PG_RETURN_XML_P(result);
@ -4247,7 +4247,7 @@ xml_xmlnodetoxmltype(xmlNodePtr cur, PgXmlErrorContext *xmlerrcxt)
}
else
{
volatile xmlChar *str = NULL;
xmlChar *volatile str = NULL;
PG_TRY();
{
@ -4267,7 +4267,7 @@ xml_xmlnodetoxmltype(xmlNodePtr cur, PgXmlErrorContext *xmlerrcxt)
PG_FINALLY();
{
if (str)
xmlFree((xmlChar *) str);
xmlFree(str);
}
PG_END_TRY();
}