fix uninit issue: bad use of hash map
authorChristian Grothoff <christian@grothoff.org>
Thu, 21 Feb 2019 10:58:05 +0000 (11:58 +0100)
committerChristian Grothoff <christian@grothoff.org>
Thu, 21 Feb 2019 10:58:05 +0000 (11:58 +0100)
src/rps/gnunet-service-rps.c
src/rps/rps-test_util.c

index e3e25342ed289c9697dc6d2c34fd3586f0d31c99..ccf54d1e235ed0092244107b12e94c2becdab92b 100644 (file)
@@ -2948,7 +2948,11 @@ destroy_sub (struct Sub *sub)
   for (uint32_t i = 0; i < 256; i++)
   {
     char push_recv_str_tmp[8];
-    (void) snprintf (push_recv_str_tmp, 8, "%" PRIu32 "\n", sub->push_recv[i]);
+    
+    GNUNET_snprintf (push_recv_str_tmp,
+                    sizeof (push_recv_str_tmp),
+                    "%" PRIu32 "\n",
+                    sub->push_recv[i]);
     (void) strncat (push_recv_str,
                     push_recv_str_tmp,
                     1535 - strnlen (push_recv_str, 1536));
@@ -2956,7 +2960,8 @@ destroy_sub (struct Sub *sub)
   (void) strncat (push_recv_str,
                   "\n",
                   1535 - strnlen (push_recv_str, 1536));
-  LOG (GNUNET_ERROR_TYPE_DEBUG, "Writing push stats to disk\n");
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Writing push stats to disk\n");
   to_file_w_len (sub->file_name_push_recv, 1535, push_recv_str);
   GNUNET_free (sub->file_name_push_recv);
   sub->file_name_push_recv = NULL;
@@ -2965,7 +2970,11 @@ destroy_sub (struct Sub *sub)
   for (uint32_t i = 0; i < 256; i++)
   {
     char pull_delays_str_tmp[8];
-    (void) snprintf (pull_delays_str_tmp, 8, "%" PRIu32 "\n", sub->pull_delays[i]);
+
+    GNUNET_snprintf (pull_delays_str_tmp,
+                    sizeof (pull_delays_str_tmp),
+                    "%" PRIu32 "\n",
+                    sub->pull_delays[i]);
     (void) strncat (pull_delays_str,
                     pull_delays_str_tmp,
                     1535 - strnlen (pull_delays_str, 1536));
@@ -3028,8 +3037,11 @@ core_connects (void *cls,
   (void) cls;
   (void) mq;
 
-  GNUNET_CONTAINER_multipeermap_put (map_single_hop, peer, NULL,
-      GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+  GNUNET_assert (GNUNET_YES ==
+                GNUNET_CONTAINER_multipeermap_put (map_single_hop,
+                                                   peer,
+                                                   NULL,
+                                                   GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
   return NULL;
 }
 
index 3a482c1e6bb6affaf488df09a6468ad66063e305..85829f2470a25f3dcd157db75da9c432f544e3a5 100644 (file)
@@ -74,49 +74,42 @@ static struct GNUNET_CONTAINER_MultiHashMap *open_files;
 struct GNUNET_DISK_FileHandle *
 get_file_handle (const char *name)
 {
-  struct GNUNET_HashCode hash = {0};
+  struct GNUNET_HashCode hash;
   struct GNUNET_DISK_FileHandle *fh;
 
   if (NULL == open_files)
   {
     open_files = GNUNET_CONTAINER_multihashmap_create (16,
-        GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+                                                      GNUNET_NO);
     LOG (GNUNET_ERROR_TYPE_DEBUG,
          "Created map of open files.\n");
   }
   GNUNET_CRYPTO_hash (name,
-                      strnlen (name,
-                               512),
+                      strlen (name),
                       &hash);
-  if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (open_files,
-                                                           &hash))
-  {
-    fh = GNUNET_DISK_file_open (name,
-                                GNUNET_DISK_OPEN_WRITE |
-                                GNUNET_DISK_OPEN_CREATE |
-                                GNUNET_DISK_OPEN_APPEND,
-                                GNUNET_DISK_PERM_USER_READ |
-                                GNUNET_DISK_PERM_USER_WRITE |
-                                GNUNET_DISK_PERM_GROUP_READ);
-    if (NULL == fh)
-    {
-      LOG (GNUNET_ERROR_TYPE_ERROR,
-           "Opening file `%s' failed.\n",
-           name);
-      GNUNET_assert (0);
-    }
-    GNUNET_CONTAINER_multihashmap_put (open_files,
-                                       &hash,
-                                       fh,
-                                       GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY);
+  if (NULL != (fh = GNUNET_CONTAINER_multihashmap_get (open_files,
+                                                      &hash)))
     return fh;
-  }
-  else
+  fh = GNUNET_DISK_file_open (name,
+                             GNUNET_DISK_OPEN_WRITE |
+                             GNUNET_DISK_OPEN_CREATE |
+                             GNUNET_DISK_OPEN_APPEND,
+                             GNUNET_DISK_PERM_USER_READ |
+                             GNUNET_DISK_PERM_USER_WRITE |
+                             GNUNET_DISK_PERM_GROUP_READ);
+  if (NULL == fh)
   {
-    fh = GNUNET_CONTAINER_multihashmap_get (open_files,
-                                            &hash);
-    return fh;
+    LOG (GNUNET_ERROR_TYPE_ERROR,
+        "Opening file `%s' failed.\n",
+        name);
+    GNUNET_assert (0);
   }
+  GNUNET_assert (GNUNET_YES ==
+                GNUNET_CONTAINER_multihashmap_put (open_files,
+                                                   &hash,
+                                                   fh,
+                                                   GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
+  return fh;
 }