]> granicus.if.org Git - graphviz/commitdiff
eval: avoid sfprintf in integer-to-string static
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 24 Jul 2021 02:24:48 +0000 (19:24 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 4 Aug 2021 01:37:02 +0000 (18:37 -0700)
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.

lib/expr/exeval.c

index 926567bfc3038713b68fa77244d6f5639a880697..0bc040ff7ca10c041071ec69a270a0e7d59b05aa 100644 (file)
@@ -1779,11 +1779,12 @@ eval(Expr_t* ex, Exnode_t* expr, void* env)
                        tmp.data.constant.value = v;
                        if (expr->data.operand.left->op != DYNAMIC && expr->data.operand.left->op != ID)
                        {
+                               char *str;
                                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;
                        }
                        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)) {
                                if (expr->data.operand.left->type == UNSIGNED)