tolerate additional IPv4 address now available for gnunet.org
[oweals/gnunet.git] / src / util / common_allocation.c
index 71a2221eec46757b44590a9362836cdad77bda11..20333ce560e61ece8b85881b924eb4fb25e38d84 100644 (file)
@@ -2,20 +2,20 @@
      This file is part of GNUnet.
      Copyright (C) 2001, 2002, 2003, 2005, 2006 GNUnet e.V.
 
-     GNUnet is free software; you can redistribute it and/or modify
-     it under the terms of the GNU General Public License as published
-     by the Free Software Foundation; either version 3, or (at your
-     option) any later version.
+     GNUnet is free software: you can redistribute it and/or modify it
+     under the terms of the GNU Affero General Public License as published
+     by the Free Software Foundation, either version 3 of the License,
+     or (at your option) any later version.
 
      GNUnet is distributed in the hope that it will be useful, but
      WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-     General Public License for more details.
+     Affero General Public License for more details.
+    
+     You should have received a copy of the GNU Affero General Public License
+     along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-     You should have received a copy of the GNU General Public License
-     along with GNUnet; see the file COPYING.  If not, write to the
-     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-     Boston, MA 02110-1301, USA.
+     SPDX-License-Identifier: AGPL3.0-or-later
 */
 
 /**
@@ -32,9 +32,9 @@
 #include <malloc/malloc.h>
 #endif
 
-#define LOG(kind,...) GNUNET_log_from (kind, "util",__VA_ARGS__)
+#define LOG(kind,...) GNUNET_log_from (kind, "util-common-allocation",__VA_ARGS__)
 
-#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util", syscall)
+#define LOG_STRERROR(kind,syscall) GNUNET_log_from_strerror (kind, "util-common-allocation", syscall)
 
 #ifndef INT_MAX
 #define INT_MAX 0x7FFFFFFF
@@ -100,8 +100,11 @@ GNUNET_xmalloc_ (size_t size,
  * @return allocated memory, never NULL
  */
 void **
-GNUNET_xnew_array_2d_ (size_t n, size_t m, size_t elementSize,
-                       const char *filename, int linenumber)
+GNUNET_xnew_array_2d_ (size_t n,
+                      size_t m,
+                      size_t elementSize,
+                       const char *filename,
+                      int linenumber)
 {
        /* use char pointer internally to avoid void pointer arithmetic warnings */
        char **ret = GNUNET_xmalloc_ (n * sizeof (void *) +  /* 1. dim header */
@@ -218,6 +221,8 @@ GNUNET_xmalloc_unchecked_ (size_t size,
 {
   void *result;
 
+  (void) filename;
+  (void) linenumber;
 #ifdef W32_MEM_LIMIT
   size += sizeof (size_t);
   if (mem_used + size > W32_MEM_LIMIT)
@@ -256,6 +261,9 @@ GNUNET_xrealloc_ (void *ptr,
                   const char *filename,
                   int linenumber)
 {
+  (void) filename;
+  (void) linenumber;
+
 #ifdef W32_MEM_LIMIT
   n += sizeof (size_t);
   ptr = &((size_t *) ptr)[-1];
@@ -264,7 +272,8 @@ GNUNET_xrealloc_ (void *ptr,
   ptr = realloc (ptr, n);
   if ((NULL == ptr) && (n > 0))
   {
-    LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR, "realloc");
+    LOG_STRERROR (GNUNET_ERROR_TYPE_ERROR,
+                 "realloc");
     GNUNET_assert (0);
   }
 #ifdef W32_MEM_LIMIT
@@ -466,8 +475,8 @@ GNUNET_xgrow_ (void **old,
  */
 int
 GNUNET_asprintf (char **buf,
-                const char *format,
-                ...)
+                 const char *format,
+                 ...)
 {
   int ret;
   va_list args;
@@ -475,6 +484,7 @@ GNUNET_asprintf (char **buf,
   va_start (args, format);
   ret = VSNPRINTF (NULL, 0, format, args);
   va_end (args);
+  GNUNET_assert (ret >= 0);
   *buf = GNUNET_malloc (ret + 1);
   va_start (args, format);
   ret = VSPRINTF (*buf, format, args);
@@ -501,9 +511,13 @@ GNUNET_snprintf (char *buf,
   va_list args;
 
   va_start (args, format);
-  ret = VSNPRINTF (buf, size, format, args);
+  ret = VSNPRINTF (buf,
+                  size,
+                  format,
+                  args);
   va_end (args);
-  GNUNET_assert (ret < size);
+  GNUNET_assert ( (ret >= 0) &&
+                 (((size_t) ret) < size) );
   return ret;
 }
 
@@ -523,7 +537,9 @@ GNUNET_copy_message (const struct GNUNET_MessageHeader *msg)
   msize = ntohs (msg->size);
   GNUNET_assert (msize >= sizeof (struct GNUNET_MessageHeader));
   ret = GNUNET_malloc (msize);
-  GNUNET_memcpy (ret, msg, msize);
+  GNUNET_memcpy (ret,
+                msg,
+                msize);
   return ret;
 }