From c8db92f409cc05156a294b5973fe2081eb3f8ca7 Mon Sep 17 00:00:00 2001 From: Matthew Fernandez Date: Sat, 2 Jan 2021 17:54:57 -0800 Subject: [PATCH] remove an unnecessary use of sfstropen in GVPR Related to #1873. --- lib/gvpr/compile.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/gvpr/compile.c b/lib/gvpr/compile.c index fbc230367..855260b9c 100644 --- a/lib/gvpr/compile.c +++ b/lib/gvpr/compile.c @@ -191,12 +191,21 @@ static char *symName(Expr_t * ex, int op) if (op >= MINNAME && op <= MAXNAME) return gprnames[op]; else { - Sfio_t *sf = sfstropen(); - char *s; + // calculate how much space we need to construct a name + int bytes = vsnprintf(NULL, 0, "", op); + if (bytes < 0) { + fprintf(stderr, "%s: vsnprintf failure\n", __func__); + exit(EXIT_FAILURE); + } + + // construct a managed buffer to store this name + char *s = vmalloc(ex->ve, (size_t)bytes + 1); + + // make the name + if (s != NULL) { + snprintf(s, (size_t)bytes + 1, "", op); + } - sfprintf(sf, "", op); - s = exstring(ex, sfstruse(sf)); - sfclose(sf); return s; } } -- 2.40.0