From 7b685c95e6095ccd46cbdb96909c6ca5576a9de9 Mon Sep 17 00:00:00 2001 From: Dvir Volk Date: Mon, 2 May 2016 16:06:01 +0300 Subject: [PATCH] better zeroing of realloced space --- rmutil/Makefile | 4 ++-- rmutil/vector.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/rmutil/Makefile b/rmutil/Makefile index b203ed4..f29834d 100644 --- a/rmutil/Makefile +++ b/rmutil/Makefile @@ -3,7 +3,7 @@ ifndef RM_INCLUDE_DIR RM_INCLUDE_DIR=../ endif -CFLAGS = -g -fPIC -lc -lm -O3 -std=gnu99 -I$(RM_INCLUDE_DIR) +CFLAGS = -g -fPIC -lc -lm -O3 -std=gnu99 -I$(RM_INCLUDE_DIR) -Wall CC=gcc OBJS=util.o strings.o sds.o vector.o @@ -17,7 +17,7 @@ librmutil.a: $(OBJS) ar rcs $@ $^ test_vector: test_vector.o vector.o - $(CC) -o test_vector vector.o test_vector.o -lc -O0 + $(CC) -Wall -o test_vector vector.o test_vector.o -lc -O0 @(sh -c ./test_vector) diff --git a/rmutil/vector.c b/rmutil/vector.c index f255844..ebd4668 100644 --- a/rmutil/vector.c +++ b/rmutil/vector.c @@ -45,7 +45,7 @@ int Vector_Resize(Vector *v, int newcap) { v->cap = newcap; v->data = realloc(v->data, v->cap*v->elemSize); - int offset = v->top*v->elemSize; + int offset = oldcap*v->elemSize; // put all zeros at the newly realloc'd part of the vector memset(v->data + offset, 0, v->cap*v->elemSize - offset); return v->cap;