From 28770b6e738b5dc1044f3688e21687996631112c Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sun, 3 Oct 2021 16:53:43 -0700 Subject: [PATCH] common: remove 'xml_string0' All calls of this function have now been refactored to use `xml_escape`. Related to #1868. --- lib/common/utils.h | 1 - lib/common/xml.c | 39 +-------------------------------------- lib/gvc/gvc.def | 1 - 3 files changed, 1 insertion(+), 40 deletions(-) diff --git a/lib/common/utils.h b/lib/common/utils.h index e542a7a52..37cd02397 100644 --- a/lib/common/utils.h +++ b/lib/common/utils.h @@ -61,7 +61,6 @@ extern "C" { int (*cb)(void *state, const char *s), void *state); - UTILS_API char *xml_string0(char *str, boolean raw); UTILS_API void write_plain(GVJ_t * job, graph_t * g, FILE * f, boolean extend); UTILS_API double yDir (double y); UTILS_API char *ps_string(char *s, int); diff --git a/lib/common/xml.c b/lib/common/xml.c index 469643c28..ac13af781 100644 --- a/lib/common/xml.c +++ b/lib/common/xml.c @@ -136,8 +136,7 @@ static int buffer_put(void *dst, const char *src) { size_t length = strlen(src); // do we need to expand this buffer? - assert(buffer->base != NULL && - "buffer not initialized in xml_string0/xml_url_string?"); + assert(buffer->base != NULL && "buffer not initialized in xml_url_string?"); while (length > buffer->capacity || buffer->capacity - length <= buffer->length) { size_t capacity = buffer->capacity == 0 ? 64 : (buffer->capacity * 2); @@ -155,42 +154,6 @@ static int buffer_put(void *dst, const char *src) { return (int)length; } -/* xml_string0: - * Encode input string as an xml string. - * If raw is true, the input is interpreted as having no - * embedded escape sequences, and \n and \r are changed - * into and , respectively. - * Uses a static buffer, so non-re-entrant. - */ -char *xml_string0(char *s, boolean raw) { - static char *buf = NULL; - static size_t bufsize = 0; - char prev = '\0'; - - const xml_flags_t flags = {.raw = raw != FALSE, .dash = 1, .nbsp = 1}; - - if (!buf) { - bufsize = 64; - buf = gmalloc(bufsize); - } - - // generate an escaped version of this string into `buf` - buffer_t buffer = {.base = buf, .capacity = bufsize}; - while (s && *s) { - (void)xml_core(prev, s, flags, buffer_put, &buffer); - prev = *s; - s++; - } - assert(buffer.length < buffer.capacity && "no room for NUL"); - buffer.base[buffer.length] = '\0'; - - // save the static buffer (it may have been realloced) for reuse next time - buf = buffer.base; - bufsize = buffer.capacity; - - return buf; -} - /* a variant of xml_string for urls in hrefs */ char *xml_url_string(char *s) { static char *buf = NULL; diff --git a/lib/gvc/gvc.def b/lib/gvc/gvc.def index ef7638486..5cb297214 100644 --- a/lib/gvc/gvc.def +++ b/lib/gvc/gvc.def @@ -294,7 +294,6 @@ Verbose Version write_plain xml_escape -xml_string0 xml_url_string Y_invert zmalloc -- 2.40.0