]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix misuse of "volatile" in xml.c
authorMichael Paquier <michael@paquier.xyz>
Mon, 9 Mar 2026 22:05:32 +0000 (07:05 +0900)
committerMichael Paquier <michael@paquier.xyz>
Mon, 9 Mar 2026 22:05:32 +0000 (07:05 +0900)
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 <cca5507@qq.com>
Discussion: https://postgr.es/m/tencent_5BE8DAD985EE140ED62EA728C8D4E1311F0A@qq.com

src/backend/utils/adt/xml.c

index 2c8d5a81b751d1795d67490a6da728f9a1d9109e..79f6cf7b4fa76619c97fd7e55880f338d6087c1b 100644 (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();
        }