gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet] branch master updated (3c47c0ae9 -> 7011143dc)


From: gnunet
Subject: [gnunet] branch master updated (3c47c0ae9 -> 7011143dc)
Date: Sun, 25 Jun 2023 16:42:06 +0200

This is an automated email from the git hooks/post-receive script.

oec pushed a change to branch master
in repository gnunet.

    from 3c47c0ae9 -fix build issues
     new 4b3ff0e1e proper overflow check
     new 7011143dc [pq] unified/simplified switch-logic

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/pq/pq_query_helper.c  |   6 +-
 src/pq/pq_result_helper.c | 281 +++++++++++++++++++++++++---------------------
 2 files changed, 159 insertions(+), 128 deletions(-)

diff --git a/src/pq/pq_query_helper.c b/src/pq/pq_query_helper.c
index 932f3cb0b..2293c8005 100644
--- a/src/pq/pq_query_helper.c
+++ b/src/pq/pq_query_helper.c
@@ -689,7 +689,7 @@ qconv_array (
     /* num * length-field */
     size_t x = sizeof(uint32_t);
     size_t y = x * num;
-    RETURN_UNLESS (y >= num);
+    RETURN_UNLESS ((0 == num) || (y / num == x));
 
     /* size of header */
     total_size  = x = sizeof(struct pq_array_header);
@@ -700,11 +700,11 @@ qconv_array (
     if (same_sized)
     {
       x = num * meta->same_size;
-      RETURN_UNLESS (x >= num);
+      RETURN_UNLESS ((0 == num) || (x / num == meta->same_size));
 
       y = total_size;
       total_size += x;
-      RETURN_UNLESS ((total_size >= y));
+      RETURN_UNLESS (total_size >= y);
     }
     else  /* sizes are different per element */
     {
diff --git a/src/pq/pq_result_helper.c b/src/pq/pq_result_helper.c
index cdb7fcbc4..624263812 100644
--- a/src/pq/pq_result_helper.c
+++ b/src/pq/pq_result_helper.c
@@ -22,6 +22,7 @@
  * @brief functions to extract result values
  * @author Christian Grothoff
  */
+#include "gnunet_time_lib.h"
 #include "platform.h"
 #include "gnunet_common.h"
 #include "gnunet_util_lib.h"
@@ -1216,151 +1217,181 @@ extract_array_generic (
   if (NULL != info->num)
     *info->num = header.dim;
 
-  switch (info->typ)
-  {
-  case array_of_bool:
-    if (NULL != dst_size)
-      *dst_size = sizeof(bool) * (header.dim);
-    out = GNUNET_new_array (header.dim, bool);
-    break;
-  case array_of_uint16:
-    if (NULL != dst_size)
-      *dst_size = sizeof(uint16_t) * (header.dim);
-    out = GNUNET_new_array (header.dim, uint16_t);
-    break;
-  case array_of_uint32:
-    if (NULL != dst_size)
-      *dst_size = sizeof(uint32_t) * (header.dim);
-    out = GNUNET_new_array (header.dim, uint32_t);
-    break;
-  case array_of_uint64:
-    if (NULL != dst_size)
-      *dst_size = sizeof(uint64_t) * (header.dim);
-    out = GNUNET_new_array (header.dim, uint64_t);
-    break;
-  case array_of_abs_time:
-    if (NULL != dst_size)
-      *dst_size = sizeof(struct GNUNET_TIME_Absolute) * (header.dim);
-    out = GNUNET_new_array (header.dim, struct GNUNET_TIME_Absolute);
-    break;
-  case array_of_rel_time:
-    if (NULL != dst_size)
-      *dst_size = sizeof(struct GNUNET_TIME_Relative) * (header.dim);
-    out = GNUNET_new_array (header.dim, struct GNUNET_TIME_Relative);
-    break;
-  case array_of_timestamp:
-    if (NULL != dst_size)
-      *dst_size = sizeof(struct GNUNET_TIME_Timestamp) * (header.dim);
-    out = GNUNET_new_array (header.dim, struct GNUNET_TIME_Timestamp);
-    break;
-  case array_of_byte:
-    if (0 == info->same_size)
-      *info->sizes = GNUNET_new_array (header.dim, size_t);
-  /* fallthrough */
-  case array_of_string:
-    {
-      size_t total = 0;
-      bool is_string = (array_of_string == info->typ);
-
-      /* first, calculate total size required for allocation */
-      {
-        char *ptr = data + sizeof(header);
-        for (uint32_t i = 0; i < header.dim; i++)
-        {
-          uint32_t sz;
-
-          sz = ntohl (*(uint32_t *) ptr);
-          sz += is_string ? 1 : 0;
-          total += sz;
-          ptr += sizeof(uint32_t);
-          ptr += sz;
-
-          if ((! is_string) &&
-              (0 == info->same_size))
-            (*info->sizes)[i] = sz;
-
-          FAIL_IF ((0 != info->same_size) &&
-                   (sz != info->same_size));
-          FAIL_IF (total < sz);
-        }
-      }
-
-      if (NULL != dst_size)
-        *dst_size = total;
-
-      if (0 < total)
-        out = GNUNET_malloc (total);
-
-      break;
-    }
-  default:
-    FAIL_IF (1 != 0);
-  }
-
-  *((void **) dst) = out;
-  if (NULL == out)
-    return GNUNET_OK; /* array length must be 0 */
-
-  /* copy data */
   {
     char *in = data + sizeof(header);
 
-    for (uint32_t i = 0; i < header.dim; i++)
+    switch (info->typ)
     {
-      size_t sz =  ntohl (*(uint32_t *) in);
-      in += sizeof(uint32_t);
-
-      switch (info->typ)
+    case array_of_bool:
+      if (NULL != dst_size)
+        *dst_size = sizeof(bool) * (header.dim);
+      out = GNUNET_new_array (header.dim, bool);
+      *((void **) dst) = out;
+      for (uint32_t i = 0; i < header.dim; i++)
       {
-      case array_of_bool:
+        size_t sz =  ntohl (*(uint32_t *) in);
         FAIL_IF (sz != sizeof(bool));
+        in += sizeof(uint32_t);
         *(bool *) out = *(bool *) in;
-        break;
-      case array_of_uint16:
+        in += sz;
+        out += sz;
+      }
+      break;
+
+    case array_of_uint16:
+      if (NULL != dst_size)
+        *dst_size = sizeof(uint16_t) * (header.dim);
+      out = GNUNET_new_array (header.dim, uint16_t);
+      *((void **) dst) = out;
+      for (uint32_t i = 0; i < header.dim; i++)
+      {
+        size_t sz =  ntohl (*(uint32_t *) in);
         FAIL_IF (sz != sizeof(uint16_t));
+        in += sizeof(uint32_t);
         *(uint16_t *) out = ntohs (*(uint16_t *) in);
-        break;
-      case array_of_uint32:
+        in += sz;
+        out += sz;
+      }
+      break;
+
+    case array_of_uint32:
+      if (NULL != dst_size)
+        *dst_size = sizeof(uint32_t) * (header.dim);
+      out = GNUNET_new_array (header.dim, uint32_t);
+      *((void **) dst) = out;
+      for (uint32_t i = 0; i < header.dim; i++)
+      {
+        size_t sz =  ntohl (*(uint32_t *) in);
         FAIL_IF (sz != sizeof(uint32_t));
+        in += sizeof(uint32_t);
         *(uint32_t *) out = ntohl (*(uint32_t *) in);
-        break;
-      case array_of_uint64:
+        in += sz;
+        out += sz;
+      }
+      break;
+
+    case array_of_uint64:
+      if (NULL != dst_size)
+        *dst_size = sizeof(uint64_t) * (header.dim);
+      out = GNUNET_new_array (header.dim, uint64_t);
+      *((void **) dst) = out;
+      for (uint32_t i = 0; i < header.dim; i++)
+      {
+        size_t sz =  ntohl (*(uint32_t *) in);
         FAIL_IF (sz != sizeof(uint64_t));
+        in += sizeof(uint32_t);
         *(uint64_t *) out = GNUNET_ntohll (*(uint64_t *) in);
-        break;
-      case array_of_abs_time:
-      case array_of_rel_time:
-      case array_of_timestamp:
+        in += sz;
+        out += sz;
+      }
+      break;
+
+    case array_of_abs_time:
+      if (NULL != dst_size)
+        *dst_size = sizeof(struct GNUNET_TIME_Absolute) * (header.dim);
+      out = GNUNET_new_array (header.dim, struct GNUNET_TIME_Absolute);
+      *((void **) dst) = out;
+      for (uint32_t i = 0; i < header.dim; i++)
+      {
+        size_t sz =  ntohl (*(uint32_t *) in);
+        FAIL_IF (sz != sizeof(uint64_t));
+        in += sizeof(uint32_t);
+        ((struct GNUNET_TIME_Absolute *) out)->abs_value_us =
+          GNUNET_ntohll (*(uint64_t *) in);
+        in += sz;
+        out += sz;
+      }
+      break;
+
+    case array_of_rel_time:
+      if (NULL != dst_size)
+        *dst_size = sizeof(struct GNUNET_TIME_Relative) * (header.dim);
+      out = GNUNET_new_array (header.dim, struct GNUNET_TIME_Relative);
+      *((void **) dst) = out;
+      for (uint32_t i = 0; i < header.dim; i++)
+      {
+        size_t sz =  ntohl (*(uint32_t *) in);
+        FAIL_IF (sz != sizeof(uint64_t));
+        in += sizeof(uint32_t);
+        ((struct GNUNET_TIME_Relative *) out)->rel_value_us =
+          GNUNET_ntohll (*(uint64_t *) in);
+        in += sz;
+        out += sz;
+      }
+      break;
+
+    case array_of_timestamp:
+      if (NULL != dst_size)
+        *dst_size = sizeof(struct GNUNET_TIME_Timestamp) * (header.dim);
+      out = GNUNET_new_array (header.dim, struct GNUNET_TIME_Timestamp);
+      *((void **) dst) = out;
+      for (uint32_t i = 0; i < header.dim; i++)
+      {
+        size_t sz =  ntohl (*(uint32_t *) in);
         FAIL_IF (sz != sizeof(uint64_t));
+        in += sizeof(uint32_t);
+        ((struct GNUNET_TIME_Timestamp *) out)->abs_time.abs_value_us =
+          GNUNET_ntohll (*(uint64_t *) in);
+        in += sz;
+        out += sz;
+      }
+      break;
+
+    case array_of_byte:
+      if (0 == info->same_size)
+        *info->sizes = GNUNET_new_array (header.dim, size_t);
+    /* fallthrough */
+    case array_of_string:
+      {
+        size_t total = 0;
+        bool is_string = (array_of_string == info->typ);
+
+        /* first, calculate total size required for allocation */
         {
-          uint64_t val = GNUNET_ntohll (*(uint64_t *) in);
-          switch (info->typ)
+          char *ptr = data + sizeof(header);
+          for (uint32_t i = 0; i < header.dim; i++)
           {
-          case array_of_abs_time:
-            ((struct GNUNET_TIME_Absolute *) out)->abs_value_us = val;
-            break;
-          case array_of_rel_time:
-            ((struct GNUNET_TIME_Relative *) out)->rel_value_us = val;
-            break;
-          case array_of_timestamp:
-            ((struct GNUNET_TIME_Timestamp *) out)->abs_time.abs_value_us = 
val;
-            break;
-          default:
-            FAIL_IF (1 != 0);
+            uint32_t sz;
+
+            sz = ntohl (*(uint32_t *) ptr);
+            sz += is_string ? 1 : 0;
+            total += sz;
+            ptr += sizeof(uint32_t);
+            ptr += sz;
+
+            if ((! is_string) &&
+                (0 == info->same_size))
+              (*info->sizes)[i] = sz;
+
+            FAIL_IF ((0 != info->same_size) &&
+                     (sz != info->same_size));
+            FAIL_IF (total < sz);
           }
         }
+
+        if (NULL != dst_size)
+          *dst_size = total;
+
+        if (0 < total)
+          out = GNUNET_malloc (total);
+
+        *((void **) dst) = out;
+
+        /* copy data */
+        for (uint32_t i = 0; i < header.dim; i++)
+        {
+          size_t sz =  ntohl (*(uint32_t *) in);
+          in += sizeof(uint32_t);
+          GNUNET_memcpy (out, in, sz);
+
+          in += sz;
+          out += sz;
+          out += (array_of_string == info->typ) ? 1 : 0;
+        }
         break;
-      case array_of_byte:
-      case array_of_string:
-        GNUNET_memcpy (out, in, sz);
-        break;
-      default:
-        FAIL_IF (1 != 0);
       }
-
-      in += sz;
-      out += sz;
-      out += (array_of_string == info->typ) ? 1 : 0;
+    default:
+      FAIL_IF (1 != 0);
     }
   }
 

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]