xmlGetUTF8Char()'s second argument is both input and output. Fix
authorTom Lane <[email protected]>
Sat, 10 Nov 2007 18:51:20 +0000 (18:51 +0000)
committerTom Lane <[email protected]>
Sat, 10 Nov 2007 18:51:20 +0000 (18:51 +0000)
uninitialized value, and avoid invoking the function nine separate
times in the pg_xmlIsNameChar macro.  Should resolve buildfarm failures.
Per report from Ben Leslie.

src/backend/utils/adt/xml.c

index 5a59bafe1cb20059f09155544d9f297dd8144946..c6245084fba24fa5c643d7891fdf3f6c1f8b5508 100644 (file)
@@ -998,7 +998,8 @@ xml_init(void)
        while (xmlIsBlank_ch(*(p))) (p)++
 
 /* Letter | Digit | '.' | '-' | '_' | ':' | CombiningChar | Extender */
-#define pg_xmlIsNameChar(c) \
+/* Beware of multiple evaluations of argument! */
+#define PG_XMLISNAMECHAR(c) \
        (xmlIsBaseChar_ch(c) || xmlIsIdeographicQ(c) \
                        || xmlIsDigit_ch(c) \
                        || c == '.' || c == '-' || c == '_' || c == ':' \
@@ -1006,12 +1007,13 @@ xml_init(void)
                        || xmlIsExtender_ch(c))
 
 static int
-parse_xml_decl(const xmlChar *str,size_t *lenp,
+parse_xml_decl(const xmlChar *str, size_t *lenp,
                           xmlChar **version, xmlChar **encoding, int *standalone)
 {
        const xmlChar *p;
        const xmlChar *save_p;
        size_t          len;
+       int                     utf8char;
        int                     utf8len;
 
        xml_init();
@@ -1028,8 +1030,10 @@ parse_xml_decl(const xmlChar *str,size_t *lenp,
        if (xmlStrncmp(p, (xmlChar *)"<?xml", 5) != 0)
                goto finished;
 
-       /* This means it's a PI like <?xml-stylesheet ...?>. */
-       if (pg_xmlIsNameChar(xmlGetUTF8Char(&p[5], &utf8len)))
+       /* if next char is name char, it's a PI like <?xml-stylesheet ...?> */
+       utf8len = strlen((const char *) (p+5));
+       utf8char = xmlGetUTF8Char(p+5, &utf8len);
+       if (PG_XMLISNAMECHAR(utf8char))
                goto finished;
 
        p += 5;