From: Matthew Fernandez Date: Sat, 24 Jul 2021 02:26:37 +0000 (-0700) Subject: eval: avoid sfprintf in integer-to-string dynamic X-Git-Tag: 2.49.0~31^2~4 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f11e2b51f4bb09a3e5059aea93f3a253e808cc88;p=graphviz eval: avoid sfprintf in integer-to-string dynamic Instead of constructing a string in the `tmp` buffer and then eventually allocating vmalloc space to copy this into, we can simply compute the number of bytes in advance, allocate vmalloc space, and then directly emit the output into the vmalloc buffer. Related to #1873, #1998. --- diff --git a/lib/expr/exeval.c b/lib/expr/exeval.c index 0bc040ff7..ea7fc9e33 100644 --- a/lib/expr/exeval.c +++ b/lib/expr/exeval.c @@ -1787,11 +1787,12 @@ eval(Expr_t* ex, Exnode_t* expr, void* env) tmp.data.constant.value.string = str; } else if ((*ex->disc->convertf)(ex, &tmp, STRING, expr->data.operand.right ? expr->data.operand.right->data.variable.symbol : (Exid_t*)0, 0, ex->disc)) { + char *str = NULL; if (expr->data.operand.left->type == UNSIGNED) - sfprintf(ex->tmp, "%I*u", sizeof(v.integer), v.integer); + str = exprintf(ex->ve, "%llu", (unsigned long long)v.integer); else - sfprintf(ex->tmp, "%I*d", sizeof(v.integer), v.integer); - tmp.data.constant.value.string = exstash(ex->tmp, ex->ve); + str = exprintf(ex->ve, "%lld", (long long)v.integer); + tmp.data.constant.value.string = str; } tmp.type = STRING; return tmp.data.constant.value;