do not allow NULL for fn
authorChristian Grothoff <christian@grothoff.org>
Thu, 16 Jun 2011 13:08:48 +0000 (13:08 +0000)
committerChristian Grothoff <christian@grothoff.org>
Thu, 16 Jun 2011 13:08:48 +0000 (13:08 +0000)
src/datacache/datacache.c
src/datastore/gnunet-service-datastore.c
src/topology/gnunet-daemon-topology.c
src/util/container_bloomfilter.c

index 10b2721ee53287d79bb1c7ca2583853b66b57f38..b937c63bb65931fd42efbcbc32f08bb84ec3edfa 100644 (file)
@@ -163,7 +163,7 @@ GNUNET_DATACACHE_create (const struct GNUNET_CONFIGURATION_Handle *cfg,
     }
   else
     {
-      ret->filter = GNUNET_CONTAINER_bloomfilter_load (NULL, bf_size, 5);  /* approx. 3% false positives at max use */  
+      ret->filter = GNUNET_CONTAINER_bloomfilter_init (NULL, bf_size, 5);  /* approx. 3% false positives at max use */  
     }
   ret->stats = GNUNET_STATISTICS_create ("datacache",
                                         cfg);
index 9ae4002925b55012d80e30ca73eef5a6ab7e9445..fab403a86eabb0fc8a8866faa8c271c4f63f4760 100644 (file)
@@ -1664,7 +1664,10 @@ run (void *cls,
       GNUNET_free_non_null (fn);
       fn = NULL;
     }
-  filter = GNUNET_CONTAINER_bloomfilter_load (fn, bf_size, 5);  /* approx. 3% false positives at max use */  
+  if (fn != NULL)
+    filter = GNUNET_CONTAINER_bloomfilter_load (fn, bf_size, 5);  /* approx. 3% false positives at max use */  
+  else
+    filter = GNUNET_CONTAINER_bloomfilter_init (NULL, bf_size, 5);  /* approx. 3% false positives at max use */  
   GNUNET_free_non_null (fn);
   if (filter == NULL)
     {
index ebe19a58d706e1177bae5b3fea066317928cba77..f7118a058a4cefd4a1a4c6bbd275f8aad72be67f 100644 (file)
@@ -511,7 +511,7 @@ setup_filter (struct Peer *peer)
      "useless" once a HELLO has been passed on to ~100
      other peers, which is likely more than enough in
      any case; hence 64, 5 as bloomfilter parameters. */
-  peer->filter = GNUNET_CONTAINER_bloomfilter_load (NULL, 64, 5);
+  peer->filter = GNUNET_CONTAINER_bloomfilter_init (NULL, 64, 5);
   peer->filter_expiration = GNUNET_TIME_relative_to_absolute (HELLO_ADVERTISEMENT_MIN_REPEAT_FREQUENCY);
   /* never send a peer its own HELLO */
   GNUNET_CONTAINER_bloomfilter_add (peer->filter, &peer->pid.hashPubKey);
index 53eaf31d1b0c6196f5c84f164cb48ff33e096f33..b4c3ad08da0b20a8751ea94877d94338e1264fc5 100644 (file)
@@ -437,6 +437,7 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename,
   int i;
   size_t ui;
 
+  GNUNET_assert (NULL != filename);
   if ((k == 0) || (size == 0))
     return NULL;
   if (size < BUFFSIZE)
@@ -448,31 +449,23 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename,
 
   bf = GNUNET_malloc (sizeof (struct GNUNET_CONTAINER_BloomFilter));
   /* Try to open a bloomfilter file */
-  if (filename != NULL)
+  bf->fh = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READWRITE
+                                 | GNUNET_DISK_OPEN_CREATE,
+                                 GNUNET_DISK_PERM_USER_READ |
+                                 GNUNET_DISK_PERM_USER_WRITE);
+  if (NULL == bf->fh)
     {
-      bf->fh = GNUNET_DISK_file_open (filename, GNUNET_DISK_OPEN_READWRITE
-                                      | GNUNET_DISK_OPEN_CREATE,
-                                      GNUNET_DISK_PERM_USER_READ |
-                                      GNUNET_DISK_PERM_USER_WRITE);
-      if (NULL == bf->fh)
-        {
-          GNUNET_free (bf);
-          return NULL;
-        }
-      bf->filename = GNUNET_strdup (filename);
-    }
-  else
-    {
-      bf->filename = NULL;
-      bf->fh = NULL;
+      GNUNET_free (bf);
+      return NULL;
     }
+  bf->filename = GNUNET_strdup (filename);
   /* Alloc block */
   bf->bitArray = GNUNET_malloc_large (size);
   if (bf->bitArray == NULL)
     {
       if (bf->fh != NULL)
        GNUNET_DISK_file_close (bf->fh);
-      GNUNET_free_non_null (bf->filename);
+      GNUNET_free (bf->filename);
       GNUNET_free (bf);
       return NULL;
     }
@@ -480,36 +473,33 @@ GNUNET_CONTAINER_bloomfilter_load (const char *filename,
   bf->addressesPerElement = k;
   memset (bf->bitArray, 0, bf->bitArraySize);
 
-  if (bf->filename != NULL)
+  /* Read from the file what bits we can */
+  rbuff = GNUNET_malloc (BUFFSIZE);
+  pos = 0;
+  while (pos < size * 8)
     {
-      /* Read from the file what bits we can */
-      rbuff = GNUNET_malloc (BUFFSIZE);
-      pos = 0;
-      while (pos < size * 8)
-        {
-          int res;
-
-          res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE);
-          if (res == -1)
-            {
-              GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
-                                        "read", bf->filename);
-            }
-          if (res == 0)
-            break;              /* is ok! we just did not use that many bits yet */
-          for (i = 0; i < res; i++)
-            {
-              if ((rbuff[i] & 0x0F) != 0)
-                setBit (bf->bitArray, pos + i * 2);
-              if ((rbuff[i] & 0xF0) != 0)
-                setBit (bf->bitArray, pos + i * 2 + 1);
-            }
-          if (res < BUFFSIZE)
-            break;
-          pos += BUFFSIZE * 2;  /* 2 bits per byte in the buffer */
-        }
-      GNUNET_free (rbuff);
+      int res;
+      
+      res = GNUNET_DISK_file_read (bf->fh, rbuff, BUFFSIZE);
+      if (res == -1)
+       {
+         GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+                                   "read", bf->filename);
+       }
+      if (res == 0)
+       break;              /* is ok! we just did not use that many bits yet */
+      for (i = 0; i < res; i++)
+       {
+         if ((rbuff[i] & 0x0F) != 0)
+           setBit (bf->bitArray, pos + i * 2);
+         if ((rbuff[i] & 0xF0) != 0)
+           setBit (bf->bitArray, pos + i * 2 + 1);
+       }
+      if (res < BUFFSIZE)
+       break;
+      pos += BUFFSIZE * 2;  /* 2 bits per byte in the buffer */
     }
+  GNUNET_free (rbuff);
   return bf;
 }