From 0845cdf9443a6b304c1bcec304a462ae4995c744 Mon Sep 17 00:00:00 2001 From: Tuomas Tynkkynen Date: Tue, 13 Feb 2018 05:00:17 +0200 Subject: libexpr: Rely on Boehm returning zeroed memory in EvalState::allocEnv() Boehm guarantees that memory returned by GC_malloc() is zeroed, so take advantage of that. --- src/libexpr/eval.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/libexpr/eval.cc') diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index b94bc597b013..48542d8e5006 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -43,13 +43,14 @@ static char * dupString(const char * s) } +/* Note: Various places expect the allocated memory to be zeroed. */ static void * allocBytes(size_t n) { void * p; #if HAVE_BOEHMGC p = GC_malloc(n); #else - p = malloc(n); + p = calloc(n, 1); #endif if (!p) throw std::bad_alloc(); return p; @@ -582,9 +583,7 @@ Env & EvalState::allocEnv(unsigned int size) Env * env = (Env *) allocBytes(sizeof(Env) + size * sizeof(Value *)); env->size = size; - /* Clear the values because maybeThunk() and lookupVar fromWith expect this. */ - for (unsigned i = 0; i < size; ++i) - env->values[i] = 0; + /* We assume that env->values has been cleared by the allocator; maybeThunk() and lookupVar fromWith expect this. */ return *env; } -- cgit 1.4.1