From: Matthew Fernandez Date: Sun, 3 Oct 2021 18:10:33 +0000 (-0700) Subject: gv2gml emitAttr: replace 'fprintf(… xml_string(…))' with 'xml_escape(…)' X-Git-Tag: 2.49.2~19^2~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5bd02c9dfea9c23211175a1c844c77fada252da7;p=graphviz gv2gml emitAttr: replace 'fprintf(… xml_string(…))' with 'xml_escape(…)' 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. --- diff --git a/cmd/tools/gv2gml.c b/cmd/tools/gv2gml.c index 788db3afa..ad274e65a 100644 --- a/cmd/tools/gv2gml.c +++ b/cmd/tools/gv2gml.c @@ -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: