]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - compat/xalloc.cc
Source Format Enforcement (#763)
[thirdparty/squid.git] / compat / xalloc.cc
index db13493c41a93c6fc87bf14919c67b7e6b41d875..0fa94f9f79915bdd6a92cf08ef82e492ad6dd488 100644 (file)
@@ -1,4 +1,12 @@
-#include "config.h"
+/*
+ * Copyright (C) 1996-2021 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
+#include "squid.h"
 #include "compat/xalloc.h"
 #include "profiler/Profiler.h"
 
@@ -28,7 +36,7 @@ XMS_DBG_INDEX(int sz)
 static void
 stat_init(void)
 {
-    for (int i = 0; i <= XMS_DBG_MAXINDEX; i++)
+    for (int i = 0; i <= XMS_DBG_MAXINDEX; ++i)
         malloc_sizes[i] = malloc_histo[i] = 0;
 
     dbg_stat_init = 1;
@@ -78,7 +86,7 @@ xcalloc(size_t n, size_t sz)
     if (p == NULL) {
         if (failure_notify) {
             static char msg[128];
-            snprintf(msg, 128, "xcalloc: Unable to allocate %lu blocks of %lu bytes!\n", (unsigned long)n, (unsigned long)sz);
+            snprintf(msg, 128, "xcalloc: Unable to allocate %" PRIuSIZE " blocks of %" PRIuSIZE " bytes!\n", n, sz);
             failure_notify(msg);
         } else {
             perror("xcalloc");
@@ -86,19 +94,9 @@ xcalloc(size_t n, size_t sz)
         exit(1);
     }
 
-#if XMALLOC_DEBUG
-    check_malloc(p, sz * n);
-#endif
 #if XMALLOC_STATISTICS
     malloc_stat(sz * n);
 #endif
-#if XMALLOC_TRACE
-    xmalloc_show_trace(p, 1);
-#endif
-#if MEM_GEN_TRACE
-    if (tracefp)
-        fprintf(tracefp, "c:%u:%u:%p\n", (unsigned int) n, (unsigned int) sz, p);
-#endif
 
     PROF_stop(xcalloc);
     return p;
@@ -119,7 +117,7 @@ xmalloc(size_t sz)
     if (p == NULL) {
         if (failure_notify) {
             static char msg[128];
-            snprintf(msg, 128, "xmalloc: Unable to allocate %lu bytes!\n", (unsigned long)sz);
+            snprintf(msg, 128, "xmalloc: Unable to allocate %" PRIuSIZE " bytes!\n", sz);
             failure_notify(msg);
         } else {
             perror("malloc");
@@ -127,19 +125,9 @@ xmalloc(size_t sz)
         exit(1);
     }
 
-#if XMALLOC_DEBUG
-    check_malloc(p, sz);
-#endif
 #if XMALLOC_STATISTICS
     malloc_stat(sz);
 #endif
-#if XMALLOC_TRACE
-    xmalloc_show_trace(p, 1);
-#endif
-#if MEM_GEN_TRACE
-    if (tracefp)
-        fprintf(tracefp, "m:%d:%p\n", sz, p);
-#endif
 
     PROF_stop(xmalloc);
     return (p);
@@ -149,17 +137,10 @@ void *
 xrealloc(void *s, size_t sz)
 {
     PROF_start(xrealloc);
-#if XMALLOC_TRACE
-    xmalloc_show_trace(s, -1);
-#endif
 
     if (sz < 1)
         sz = 1;
 
-#if XMALLOC_DEBUG
-    if (s != NULL)
-        check_free(s);
-#endif
     PROF_start(realloc);
     void *p= realloc(s, sz);
     PROF_stop(realloc);
@@ -167,7 +148,7 @@ xrealloc(void *s, size_t sz)
     if (p == NULL) {
         if (failure_notify) {
             static char msg[128];
-            snprintf(msg, 128, "xrealloc: Unable to reallocate %lu bytes!\n", (unsigned long)sz);
+            snprintf(msg, 128, "xrealloc: Unable to reallocate %" PRIuSIZE " bytes!\n", sz);
             failure_notify(msg);
         } else {
             perror("realloc");
@@ -176,53 +157,23 @@ xrealloc(void *s, size_t sz)
         exit(1);
     }
 
-#if XMALLOC_DEBUG
-    check_malloc(p, sz);
-#endif
 #if XMALLOC_STATISTICS
     malloc_stat(sz);
 #endif
-#if XMALLOC_TRACE
-    xmalloc_show_trace(p, 1);
-#endif
-#if MEM_GEN_TRACE
-    if (tracefp)                /* new ptr, old ptr, new size */
-        fprintf(tracefp, "r:%p:%p:%d\n", p, s, sz);
-#endif
+
     PROF_stop(xrealloc);
     return (p);
 }
 
-void
-xfree(void *s)
-{
-    if (s == NULL)
-        return;
-
-    free_const(s);
-}
-
 void
 free_const(const void *s_const)
 {
     void *s = const_cast<void *>(s_const);
 
     PROF_start(free_const);
-#if XMALLOC_TRACE
-    xmalloc_show_trace(s, -1);
-#endif
-
-#if XMALLOC_DEBUG
-    check_free(s);
-#endif
-
     PROF_start(free);
     free(s);
     PROF_stop(free);
-
-#if MEM_GEN_TRACE
-    if (tracefp)
-        fprintf(tracefp, "f:%p\n", s);
-#endif
     PROF_stop(free_const);
 }
+