socsvn commit: r289576 - soc2015/clord/head/sys/contrib/ficl

clord at FreeBSD.org clord at FreeBSD.org
Tue Aug 11 06:34:25 UTC 2015


Author: clord
Date: Tue Aug 11 06:34:24 2015
New Revision: 289576
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=289576

Log:
  Properly intialize the ficlDictionary struct in ficlDictionaryCreateHashed
  function. In particular, dictionary->base needed special attention since
  we want to be able to resize our dictionary, and changing it to a pointer
  rather than an array of size 1 requires an extra memory allocation.
  

Modified:
  soc2015/clord/head/sys/contrib/ficl/dictionary.c

Modified: soc2015/clord/head/sys/contrib/ficl/dictionary.c
==============================================================================
--- soc2015/clord/head/sys/contrib/ficl/dictionary.c	Tue Aug 11 06:27:31 2015	(r289575)
+++ soc2015/clord/head/sys/contrib/ficl/dictionary.c	Tue Aug 11 06:34:24 2015	(r289576)
@@ -461,11 +461,14 @@
     ficlDictionary *dictionary;
     size_t nAlloc;
 
-    nAlloc =  sizeof(ficlDictionary) + (size * sizeof (ficlCell))
-            + sizeof(ficlHash) + (bucketCount - 1) * sizeof (ficlWord *);
+    nAlloc = sizeof(ficlHash) + (size * sizeof (ficlCell))
+                              + (bucketCount - 1) * sizeof (ficlWord *);
 
-    dictionary = ficlMalloc(nAlloc);
+    dictionary = ficlMalloc(sizeof(ficlDictionary));
     FICL_SYSTEM_ASSERT(system, dictionary != NULL);
+    memset(dictionary, 0, sizeof(ficlDictionary));
+    dictionary->base = ficlMalloc(nAlloc);
+    FICL_SYSTEM_ASSERT(system, dictionary->base != NULL);
 
     dictionary->size = size;
 	dictionary->system = system;


More information about the svn-soc-all mailing list