]> granicus.if.org Git - graphviz/commitdiff
gv2gml emitAttr: replace 'fprintf(… xml_string(…))' with 'xml_escape(…)'
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 3 Oct 2021 18:10:33 +0000 (11:10 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Fri, 8 Oct 2021 14:57:43 +0000 (07:57 -0700)
Similar to the prior commits, this avoids dynamic allocation and improves thread
safety. This is intended to be a functional no-op.

Related to #1868.

cmd/tools/gv2gml.c

index 788db3afaa3e8847e7779449151f5c7a5204fa7f..ad274e65ac1d6f8faa74a17814829b5c728617ec 100644 (file)
@@ -217,14 +217,29 @@ emitSpline (char* s, FILE* outFile, int ix)
 
 }
 
+// `fputs` wrapper to handle the difference in calling convention to what
+// `xml_escape`’s `cb` expects
+static inline int put(void *stream, const char *s) {
+  return fputs(s, stream);
+}
+
+// write a string to the given file, XML-escaping the input
+static inline int xml_puts(FILE *stream, const char *s) {
+  const xml_flags_t flags = {.dash = 1, .nbsp = 1};
+  return xml_escape(s, flags, put, stream);
+}
+
 static void 
 emitAttr (char* name, char* value, FILE* outFile, int ix)
 {
     indent (ix, outFile);
     if (isNumber (value))
        fprintf (outFile, "%s %s\n", name, value);
-    else  
-       fprintf (outFile, "%s \"%s\"\n", name, xml_string(value));
+    else {
+       fprintf(outFile, "%s \"", name);
+       xml_puts(outFile, value);
+       fputs("\"\n", outFile);
+    }
 }
 
 /* node attributes: