]> git.ipfire.org Git - thirdparty/zlib-ng.git/commitdiff
Remove "local" as it was always defined as "static" 33/head
authorMika Lindqvist <postmaster@raasu.org>
Fri, 22 May 2015 14:20:48 +0000 (17:20 +0300)
committerMika Lindqvist <postmaster@raasu.org>
Fri, 22 May 2015 15:01:01 +0000 (18:01 +0300)
* If reallocf() is not available, don't call realloc directly as it might
  cause memory leak.

test/infcover.c

index c1a8d213a17ea6f6799088911d5966e80062fd39..1786f0472bd3b1aa6d7f44a6d143bd0a54d71d46 100644 (file)
@@ -6,7 +6,11 @@
 /* to use, do: ./configure --cover && make cover */
 
 #include <stdio.h>
-#include <stdlib.h>
+#ifdef HAVE_BSD_STDLIB
+#  include <bsd/stdlib.h>
+#else
+#  include <stdlib.h>
+#endif
 #include <string.h>
 #include <assert.h>
 #include "zlib.h"
 #include "inftrees.h"
 #include "inflate.h"
 
-#define local static
-
 /* reallocf is BSD-specific */
 #ifndef reallocf
-#  define reallocf realloc
+static void *reallocf(void *ptr, size_t size)
+{
+    void *ret = realloc(ptr, size);
+    if ((ret == NULL) && (ptr != NULL) && (size != 0))
+        free(ptr);
+    return ret;
+}
 #endif
 
 
@@ -74,7 +82,7 @@ struct mem_zone {
 };
 
 /* memory allocation routine to pass to zlib */
-local void *mem_alloc(void *mem, unsigned count, unsigned size)
+static void *mem_alloc(void *mem, unsigned count, unsigned size)
 {
     void *ptr;
     struct mem_item *item;
@@ -115,7 +123,7 @@ local void *mem_alloc(void *mem, unsigned count, unsigned size)
 }
 
 /* memory free routine to pass to zlib */
-local void mem_free(void *mem, void *ptr)
+static void mem_free(void *mem, void *ptr)
 {
     struct mem_item *item, *next;
     struct mem_zone *zone = mem;
@@ -161,7 +169,7 @@ local void mem_free(void *mem, void *ptr)
 
 /* set up a controlled memory allocation space for monitoring, set the stream
    parameters to the controlled routines, with opaque pointing to the space */
-local void mem_setup(z_stream *strm)
+static void mem_setup(z_stream *strm)
 {
     struct mem_zone *zone;
 
@@ -179,7 +187,7 @@ local void mem_setup(z_stream *strm)
 }
 
 /* set a limit on the total memory allocation, or 0 to remove the limit */
-local void mem_limit(z_stream *strm, size_t limit)
+static void mem_limit(z_stream *strm, size_t limit)
 {
     struct mem_zone *zone = strm->opaque;
 
@@ -187,7 +195,7 @@ local void mem_limit(z_stream *strm, size_t limit)
 }
 
 /* show the current total requested allocations in bytes */
-local void mem_used(z_stream *strm, char *prefix)
+static void mem_used(z_stream *strm, char *prefix)
 {
     struct mem_zone *zone = strm->opaque;
 
@@ -195,7 +203,7 @@ local void mem_used(z_stream *strm, char *prefix)
 }
 
 /* show the high water allocation in bytes */
-local void mem_high(z_stream *strm, char *prefix)
+static void mem_high(z_stream *strm, char *prefix)
 {
     struct mem_zone *zone = strm->opaque;
 
@@ -203,7 +211,7 @@ local void mem_high(z_stream *strm, char *prefix)
 }
 
 /* release the memory allocation zone -- if there are any surprises, notify */
-local void mem_done(z_stream *strm, char *prefix)
+static void mem_done(z_stream *strm, char *prefix)
 {
     int count = 0;
     struct mem_item *item, *next;
@@ -248,7 +256,7 @@ local void mem_done(z_stream *strm, char *prefix)
    delimiter in which case that single digit writes a byte.  The returned
    data is allocated and must eventually be freed.  NULL is returned if out of
    memory.  If the length is not needed, then len can be NULL. */
-local unsigned char *h2b(const char *hex, unsigned *len)
+static unsigned char *h2b(const char *hex, unsigned *len)
 {
     unsigned char *in;
     unsigned next, val;
@@ -287,7 +295,7 @@ local unsigned char *h2b(const char *hex, unsigned *len)
    header information is collected with inflateGetHeader().  If a zlib stream
    is looking for a dictionary, then an empty dictionary is provided.
    inflate() is run until all of the input data is consumed. */
-local void inf(char *hex, char *what, unsigned step, int win, unsigned len, int err)
+static void inf(char *hex, char *what, unsigned step, int win, unsigned len, int err)
 {
     int ret;
     unsigned have;
@@ -352,7 +360,7 @@ local void inf(char *hex, char *what, unsigned step, int win, unsigned len, int
 }
 
 /* cover all of the lines in inflate.c up to inflate() */
-local void cover_support(void)
+static void cover_support(void)
 {
     int ret;
     z_stream strm;
@@ -390,7 +398,7 @@ local void cover_support(void)
 }
 
 /* cover all inflate() header and trailer cases and code after inflate() */
-local void cover_wrap(void)
+static void cover_wrap(void)
 {
     int ret;
     z_stream strm, copy;
@@ -449,7 +457,7 @@ local void cover_wrap(void)
 }
 
 /* input and output functions for inflateBack() */
-local unsigned pull(void *desc, const unsigned char **buf)
+static unsigned pull(void *desc, const unsigned char **buf)
 {
     static unsigned int next = 0;
     static unsigned char dat[] = {0x63, 0, 2, 0};
@@ -465,14 +473,14 @@ local unsigned pull(void *desc, const unsigned char **buf)
     return next < sizeof(dat) ? (*buf = dat + next++, 1) : 0;
 }
 
-local int push(void *desc, unsigned char *buf, unsigned len)
+static int push(void *desc, unsigned char *buf, unsigned len)
 {
     buf += len;
     return desc != Z_NULL;      /* force error if desc not null */
 }
 
 /* cover inflateBack() up to common deflate data cases and after those */
-local void cover_back(void)
+static void cover_back(void)
 {
     int ret;
     z_stream strm;
@@ -509,7 +517,7 @@ local void cover_back(void)
 }
 
 /* do a raw inflate of data in hexadecimal with both inflate and inflateBack */
-local int try(char *hex, char *id, int err)
+static int try(char *hex, char *id, int err)
 {
     int ret;
     unsigned len, size;
@@ -583,7 +591,7 @@ local int try(char *hex, char *id, int err)
 }
 
 /* cover deflate data cases in both inflate() and inflateBack() */
-local void cover_inflate(void)
+static void cover_inflate(void)
 {
     try("0 0 0 0 0", "invalid stored block lengths", 1);
     try("3 0", "fixed", 0);
@@ -619,7 +627,7 @@ local void cover_inflate(void)
 }
 
 /* cover remaining lines in inftrees.c */
-local void cover_trees(void)
+static void cover_trees(void)
 {
     int ret;
     unsigned bits;
@@ -643,7 +651,7 @@ local void cover_trees(void)
 }
 
 /* cover remaining inffast.c decoding and window copying */
-local void cover_fast(void)
+static void cover_fast(void)
 {
     inf("e5 e0 81 ad 6d cb b2 2c c9 01 1e 59 63 ae 7d ee fb 4d fd b5 35 41 68"
         " ff 7f 0f 0 0 0", "fast length extra bits", 0, -8, 258, Z_DATA_ERROR);