fix NPEs, off-by-one, etc
authorChristian Grothoff <christian@grothoff.org>
Tue, 18 Jun 2019 09:00:55 +0000 (11:00 +0200)
committerChristian Grothoff <christian@grothoff.org>
Tue, 18 Jun 2019 09:00:55 +0000 (11:00 +0200)
src/include/gnunet_common.h
src/transport/gnunet-service-tng.c

index 6b48c81d82b22a7818a37f758acf143e2111ec35..66d0b8ac3314e9041a1a12a17862d203eb8686fa 100644 (file)
@@ -507,7 +507,6 @@ GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind,
 #define GNUNET_log_from(kind, comp, ...)                                  \
   do                                                                      \
   {                                                                       \
-    int log_line = __LINE__;                                              \
     static int log_call_enabled = GNUNET_LOG_CALL_STATUS;                 \
     if ((GNUNET_EXTRA_LOGGING > 0) ||                                     \
         ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0))                        \
@@ -518,7 +517,7 @@ GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind,
                                       (comp),                             \
                                       __FILE__,                           \
                                       __FUNCTION__,                       \
-                                      log_line);                          \
+                                      __LINE__);                          \
       if (GN_UNLIKELY (GNUNET_get_log_skip () > 0))                       \
       {                                                                   \
         GNUNET_log_skip (-1, GNUNET_NO);                                  \
@@ -534,7 +533,6 @@ GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind,
 #define GNUNET_log(kind, ...)                                             \
   do                                                                      \
   {                                                                       \
-    int log_line = __LINE__;                                              \
     static int log_call_enabled = GNUNET_LOG_CALL_STATUS;                 \
     if ((GNUNET_EXTRA_LOGGING > 0) ||                                     \
         ((GNUNET_ERROR_TYPE_DEBUG & (kind)) == 0))                        \
@@ -545,7 +543,7 @@ GNUNET_log_from_nocheck (enum GNUNET_ErrorType kind,
                                       NULL,                               \
                                       __FILE__,                           \
                                       __FUNCTION__,                       \
-                                      log_line);                          \
+                                      __LINE__);                          \
       if (GN_UNLIKELY (GNUNET_get_log_skip () > 0))                       \
       {                                                                   \
         GNUNET_log_skip (-1, GNUNET_NO);                                  \
index 803a8e5181bbf8128964feb45464b9f52c2d0751..bae187e7cde634ad416f2902063def11073629d6 100644 (file)
@@ -3872,11 +3872,12 @@ client_send_response (struct PendingMessage *pm)
 {
   struct TransportClient *tc = pm->client;
   struct VirtualLink *vl = pm->vl;
-  struct GNUNET_MQ_Envelope *env;
-  struct SendOkMessage *som;
 
   if (NULL != tc)
   {
+    struct GNUNET_MQ_Envelope *env;
+    struct SendOkMessage *som;
+
     env = GNUNET_MQ_msg (som, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK);
     som->peer = vl->target;
     GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -4593,11 +4594,11 @@ encapsulate_for_dv (struct DistanceVector *dv,
       char *path;
 
       path = GNUNET_strdup (GNUNET_i2s (&GST_my_identity));
-      for (unsigned int i = 0; i <= num_hops; i++)
+      for (unsigned int j = 0; j <= num_hops; j++)
       {
         char *tmp;
 
-        GNUNET_asprintf (&tmp, "%s-%s", path, GNUNET_i2s (&dhops[i]));
+        GNUNET_asprintf (&tmp, "%s-%s", path, GNUNET_i2s (&dhops[j]));
         GNUNET_free (path);
         path = tmp;
       }
@@ -5938,7 +5939,6 @@ handle_reliability_ack (void *cls,
 {
   struct CommunicatorMessageContext *cmc = cls;
   const struct TransportCummulativeAckPayloadP *ack;
-  struct PendingAcknowledgement *pa;
   unsigned int n_acks;
   uint32_t ack_counter;
 
@@ -5947,7 +5947,7 @@ handle_reliability_ack (void *cls,
   ack = (const struct TransportCummulativeAckPayloadP *) &ra[1];
   for (unsigned int i = 0; i < n_acks; i++)
   {
-    pa =
+    struct PendingAcknowledgement *pa =
       GNUNET_CONTAINER_multiuuidmap_get (pending_acks, &ack[i].ack_uuid.value);
     if (NULL == pa)
     {
@@ -6886,7 +6886,7 @@ handle_dv_learn (void *cls, const struct TransportDVLearnMessage *dvl)
 
       if (0 == (bi_history & (1 << i)))
         break; /* i-th hop not bi-directional, stop learning! */
-      if (i == nhops)
+      if (i == nhops - 1)
       {
         path[i + 2] = dvl->initiator;
       }
@@ -8629,7 +8629,6 @@ select_best_pending_from_link (struct PendingMessageScoreContext *sc,
                                     this queue */) )
     {
       frag = GNUNET_YES;
-      relb = GNUNET_NO; /* if we fragment, we never also reliability box */
       if (GNUNET_TRANSPORT_CC_RELIABLE == queue->tc->details.communicator.cc)
       {
         /* FIXME-FRAG-REL-UUID: we could use an optimized, shorter fragmentation
@@ -8829,8 +8828,9 @@ transmit_on_queue (void *cls)
                   "Fragmentation failed queue %s to %s for <%llu>, trying again\n",
                   queue->address,
                   GNUNET_i2s (&n->pid),
-                  pm->logging_uuid);
+                  sc.best->logging_uuid);
       schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
+      return;
     }
   }
   else if (GNUNET_YES == sc.relb)
@@ -8844,7 +8844,7 @@ transmit_on_queue (void *cls)
         "Reliability boxing failed queue %s to %s for <%llu>, trying again\n",
         queue->address,
         GNUNET_i2s (&n->pid),
-        pm->logging_uuid);
+        sc.best->logging_uuid);
       schedule_transmit_on_queue (queue, GNUNET_SCHEDULER_PRIORITY_DEFAULT);
       return;
     }