]> granicus.if.org Git - graphviz/commitdiff
zero out the result of a vmnewof()
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 11 Jul 2020 22:33:55 +0000 (15:33 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 11 Jul 2020 22:54:54 +0000 (15:54 -0700)
This is the only instance of a call to vmnewof() that appears to rely on the
semantics of the returned memory having been zeroed. We are about to make some
changes that make it impossible for the allocator to zero extra memory in a
vmresize() because it does not know the size of the original allocation. This
change makes it safe for vmresize() to stop providing zeroed out extra memory.

lib/expr/exeval.c

index a9e1dab84a6a3ca8fbd62337c2e28186f8861e73..2069a612ee12754404d8c11819dd059463ea7988 100644 (file)
@@ -482,6 +482,7 @@ scformat(Sfio_t* sp, void* vp, Sffmt_t* dp)
                        node->data.variable.symbol->value->data.constant.value.string = 0;
                fmt->fmt.size = 1024;
                *((void**)vp) = node->data.variable.symbol->value->data.constant.value.string = vmnewof(fmt->expr->vm, node->data.variable.symbol->value->data.constant.value.string, char, fmt->fmt.size, 0);
+               memset(node->data.variable.symbol->value->data.constant.value.string, 0, sizeof(char) * (size_t)fmt->fmt.size);
                break;
        case 'c':
                if (node->type != CHARACTER) {