From 49f96df2bc5d34becf939375d51fab9ec373b1f5 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sun, 3 Oct 2021 10:30:18 -0700 Subject: [PATCH] =?utf8?q?pango=5Ftextlayout:=20replace=20'agxbput(?= =?utf8?q?=E2=80=A6=20xml=5Fstring0(=E2=80=A6))'=20with=20'xml=5Fescape(?= =?utf8?q?=E2=80=A6)'?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Similar to the prior commit, this avoids dynamic allocating – well, some, `axbput` itself is still dynamically allocating – and improves thread safety. This is intended to be a functional no-op. Related to #1868. --- plugin/pango/gvtextlayout_pango.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/plugin/pango/gvtextlayout_pango.c b/plugin/pango/gvtextlayout_pango.c index 47de23cd3..8abf1e53d 100644 --- a/plugin/pango/gvtextlayout_pango.c +++ b/plugin/pango/gvtextlayout_pango.c @@ -10,6 +10,8 @@ #include "config.h" +#include +#include #include #include #include @@ -65,6 +67,14 @@ static char *xstrdup(const char *str) { return s; } +// wrapper to handle difference in calling conventions between `agxbput` and +// `xml_escape`’s `cb` +static int agxbput_int(void *buffer, const char *s) { + size_t len = agxbput(buffer, s); + assert(len <= INT_MAX); + return (int)len; +} + static boolean pango_textlayout(textspan_t * span, char **fontpath) { static char buf[1024]; /* returned in fontpath, only good until next call */ @@ -210,7 +220,8 @@ static boolean pango_textlayout(textspan_t * span, char **fontpath) if (flags & HTML_SUB) agxbput(&xb,""); - agxbput (&xb,xml_string0(span->str, TRUE)); + const xml_flags_t xml_flags = {.raw = 1, .dash = 1, .nbsp = 1}; + xml_escape(span->str, xml_flags, agxbput_int, &xb); if (flags & HTML_SUB) agxbput(&xb,""); -- 2.49.0