shithub: neatroff

Download patch

ref: fad7630769d6732aaae116114a17084e8f4d6d52
parent: 8f4d430fa2cfb6c56feb0eacec4cbc9590961d78
author: Ali Gholami Rudi <ali@rudi.ir>
date: Wed Jul 2 05:19:02 EDT 2014

dict: reset dict->head in dict_init()

Reported by peters@schwertfisch.de.

--- a/dict.c
+++ b/dict.c
@@ -14,6 +14,7 @@
  */
 void dict_init(struct dict *d, int size, long notfound, int dupkeys, int level2)
 {
+	int headsize = (level2 ? 256 * 256 : 256) * sizeof(d->head[0]);
 	memset(d, 0, sizeof(*d));
 	d->size = size;
 	d->n = 1;
@@ -22,7 +23,8 @@
 	d->key = xmalloc(size * sizeof(d->key[0]));
 	d->val = xmalloc(size * sizeof(d->val[0]));
 	d->next = xmalloc(size * sizeof(d->next[0]));
-	d->head = xmalloc((level2 ? 256 * 256 : 256) * sizeof(d->next[0]));
+	d->head = xmalloc(headsize);
+	memset(d->head, 0, headsize);
 	if (dupkeys)
 		d->buf = xmalloc(size * NMLEN);
 }