]> granicus.if.org Git - graphviz/commitdiff
eval: avoid sfprintf in float-to-string dynamic
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 24 Jul 2021 02:13:45 +0000 (19:13 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Wed, 4 Aug 2021 01:30:16 +0000 (18:30 -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 602a4f3434060a7669b9d7efa3f63402280dd08a..926567bfc3038713b68fa77244d6f5639a880697 100644 (file)
@@ -1615,8 +1615,7 @@ eval(Expr_t* ex, Exnode_t* expr, void* env)
                                tmp.data.constant.value.string = exprintf(ex->ve, "%g", v.floating);
                        }
                        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)) {
-                               sfprintf(ex->tmp, "%g", v.floating);
-                               tmp.data.constant.value.string = exstash(ex->tmp, ex->ve);
+                               tmp.data.constant.value.string = exprintf(ex->ve, "%g", v.floating);
                        }
                        tmp.type = STRING;
                        return tmp.data.constant.value;