From 6307b096e2599edfe238816118b3f365a73fd12a Mon Sep 17 00:00:00 2001 From: Michael Paquier Date: Tue, 10 Mar 2026 07:05:32 +0900 Subject: [PATCH] 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 2e947217474c, so no backpatch is required. A similar set of issues has been fixed in 93001888d85c for contrib/xml2/. Author: ChangAo Chen Discussion: https://postgr.es/m/tencent_5BE8DAD985EE140ED62EA728C8D4E1311F0A@qq.com --- src/backend/utils/adt/xml.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/backend/utils/adt/xml.c b/src/backend/utils/adt/xml.c index 2c8d5a81b75..79f6cf7b4fa 100644 --- a/src/backend/utils/adt/xml.c +++ b/src/backend/utils/adt/xml.c @@ -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(); } -- 2.47.3