made the service more resilient against out of order and simply incorrect messages
[oweals/gnunet.git] / src / scalarproduct / gnunet-scalarproduct.c
index 7fe6cf75cbdff0efee1dab3b8087232afd017244..32ed952685c92b84c2d0a28e0d33056be36e6417 100644 (file)
@@ -77,9 +77,9 @@ static int ret = -1;
 
 /**
  * Callback called if we are initiating a new computation session
- * 
+ *
  * @param cls unused
- * @param status if our job was successfully processed 
+ * @param status if our job was successfully processed
  */
 static void
 responder_callback (void *cls,
@@ -110,14 +110,14 @@ responder_callback (void *cls,
 
 /**
  * Callback called if we are initiating a new computation session
- * 
+ *
  * @param cls unused
  * @param key unused
  * @param peer unused
- * @param status if our job was successfully processed 
+ * @param status if our job was successfully processed
  * @param size size of the msg returned
  * @param msg the response we got.
- * @param type of the message received 
+ * @param type of the message received
  */
 static void
 requester_callback (void *cls,
@@ -225,13 +225,13 @@ run (void *cls,
     // get the length of the current element and replace , with null
     for (end = begin; *end && *end != ','; end++);
 
-    if (1 == sscanf (begin, "%" SCNd32",", &element))
+    if (1 == sscanf (begin, "%" SCNd32 ",", &element))
     {
       //element in the middle
       element_count++;
       begin = end + 1;
     }
-    else if (*begin == 0)
+    else if (0 == *begin)
     {
       break;
     }
@@ -244,25 +244,26 @@ run (void *cls,
   while (1);
   if (0 == element_count)
   {
-
+    LOG (GNUNET_ERROR_TYPE_ERROR, _ ("Need elements to compute the vectorproduct, got none.\n"));
     return;
   }
 
   begin = input_elements;
   elements = GNUNET_malloc (sizeof (int32_t) * element_count);
+  element_count = 0;
   /* Read input_elements_peer1, and put in elements_peer1 array */
   do
   {
     // get the length of the current element and replace , with null
     for (end = begin; *end && *end != ','; end++);
 
-    if (1 == sscanf (begin, "%" SCNd32",", &elements[element_count]))
+    if (1 == sscanf (begin, "%" SCNd32 ",", &elements[element_count]))
     {
       //element in the middle
       element_count++;
       begin = end + 1;
     }
-    else if (*begin == 0)
+    else if (0 == *begin)
     {
       break;
     }
@@ -270,7 +271,7 @@ run (void *cls,
   while (1);
 
   mask_bytes = element_count / 8 + (element_count % 8 ? 1 : 0);
-  mask = GNUNET_malloc ((element_count / 8) + 2);
+  mask = GNUNET_malloc ((element_count / 8) + 1);
 
   /* Read input_mask_peer1 and read in mask_peer1 array */
   if ((NULL != input_peer_id) && (NULL != input_mask))
@@ -327,7 +328,7 @@ run (void *cls,
   GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
                                 &shutdown_task,
                                 NULL);
-  
+
   ret = 0;
 }