r22564: Move the _strict -> _zeronull functions into lib/util.c
authorJeremy Allison <jra@samba.org>
Sun, 29 Apr 2007 00:09:22 +0000 (00:09 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 17:19:45 +0000 (12:19 -0500)
and out of talloc at tridge's request.
Jeremy.

source/include/smb_macros.h
source/lib/talloc/talloc.c
source/lib/talloc/talloc.h
source/lib/util.c
source/libaddns/dns.h
source/rpc_parse/parse_prs.c

index 08766a1d789769eb5258b5177eb80a6412545afa..afe7c1a4776f4eaafc54a28bbed114a66fa76a52 100644 (file)
@@ -271,19 +271,19 @@ copy an IP address from one buffer to another
 
 /* The new talloc is paranoid malloc checker safe. */
 
-#define TALLOC(ctx, size) talloc_strict(ctx, size, __location__)
-#define TALLOC_P(ctx, type) (type *)talloc_strict(ctx, sizeof(type), #type)
-#define TALLOC_ARRAY(ctx, type, count) (type *)_talloc_array_strict(ctx, sizeof(type), count, #type)
-#define TALLOC_MEMDUP(ctx, ptr, size) _talloc_memdup_strict(ctx, ptr, size, __location__)
-#define TALLOC_ZERO(ctx, size) _talloc_zero_strict(ctx, size, __location__)
-#define TALLOC_ZERO_P(ctx, type) (type *)_talloc_zero_strict(ctx, sizeof(type), #type)
-#define TALLOC_ZERO_ARRAY(ctx, type, count) (type *)_talloc_zero_array_strict(ctx, sizeof(type), count, #type)
+#define TALLOC(ctx, size) talloc_zeronull(ctx, size, __location__)
+#define TALLOC_P(ctx, type) (type *)talloc_zeronull(ctx, sizeof(type), #type)
+#define TALLOC_ARRAY(ctx, type, count) (type *)_talloc_array_zeronull(ctx, sizeof(type), count, #type)
+#define TALLOC_MEMDUP(ctx, ptr, size) _talloc_memdup_zeronull(ctx, ptr, size, __location__)
+#define TALLOC_ZERO(ctx, size) _talloc_zero_zeronull(ctx, size, __location__)
+#define TALLOC_ZERO_P(ctx, type) (type *)_talloc_zero_zeronull(ctx, sizeof(type), #type)
+#define TALLOC_ZERO_ARRAY(ctx, type, count) (type *)_talloc_zero_array_zeronull(ctx, sizeof(type), count, #type)
 #define TALLOC_REALLOC(ctx, ptr, count) _talloc_realloc(ctx, ptr, count, __location__)
 #define TALLOC_REALLOC_ARRAY(ctx, ptr, type, count) (type *)_talloc_realloc_array(ctx, ptr, sizeof(type), count, #type)
 #define talloc_destroy(ctx) talloc_free(ctx)
 #define TALLOC_FREE(ctx) do { if ((ctx) != NULL) {talloc_free(ctx); ctx=NULL;} } while(0)
-#define TALLOC_SIZE(ctx, size) talloc_strict(ctx, size, __location__)
-#define TALLOC_ZERO_SIZE(ctx, size) talloc_zero_size_strict(ctx, size)
+#define TALLOC_SIZE(ctx, size) talloc_zeronull(ctx, size, __location__)
+#define TALLOC_ZERO_SIZE(ctx, size) _talloc_zero_zeronull(ctx, size, __location__)
 
 /* only define PARANOID_MALLOC_CHECKER with --enable-developer and not compiling
    the smbmount utils */
index 8f7906d0d8070c1016821e0b7b821efb4b1f017d..b2b00d8c65ac4635749c02deaaee41b3ef193369 100644 (file)
@@ -1086,29 +1086,6 @@ void *_talloc_zero(const void *ctx, size_t size, const char *name)
        return p;
 }
 
-
-/* 
-   talloc and zero memory. 
-   Strict version - returns NULL if size is zero.
-*/
-void *_talloc_zero_strict(const void *ctx, size_t size, const char *name)
-{
-       void *p;
-
-       if (unlikely(size == 0)) {
-               return NULL;
-       }
-
-       p = _talloc_named_const(ctx, size, name);
-
-       if (p) {
-               memset(p, '\0', size);
-       }
-
-       return p;
-}
-
-
 /*
   memdup with a talloc. 
 */
@@ -1123,26 +1100,6 @@ void *_talloc_memdup(const void *t, const void *p, size_t size, const char *name
        return newp;
 }
 
-/*
-  memdup with a talloc. 
-  Strict version - returns NULL if size is zero.
-*/
-void *_talloc_memdup_strict(const void *t, const void *p, size_t size, const char *name)
-{
-       void *newp;
-
-       if (unlikely(size == 0)) {
-               return NULL;
-       }
-
-       newp = _talloc_named_const(t, size, name);
-       if (likely(newp)) {
-               memcpy(newp, p, size);
-       }
-
-       return newp;
-}
-
 /*
   strdup with a talloc 
 */
@@ -1323,23 +1280,6 @@ void *_talloc_array(const void *ctx, size_t el_size, unsigned count, const char
        return _talloc_named_const(ctx, el_size * count, name);
 }
 
-/*
-  alloc an array, checking for integer overflow in the array size.
-  Strict version - returns NULL if count or el_size are zero.
-*/
-void *_talloc_array_strict(const void *ctx, size_t el_size, unsigned count, const char *name)
-{
-       if (count >= MAX_TALLOC_SIZE/el_size) {
-               return NULL;
-       }
-
-       if (el_size == 0 || count == 0) {
-               return NULL;
-       }
-
-       return _talloc_named_const(ctx, el_size * count, name);
-}
-
 /*
   alloc an zero array, checking for integer overflow in the array size
 */
@@ -1351,24 +1291,6 @@ void *_talloc_zero_array(const void *ctx, size_t el_size, unsigned count, const
        return _talloc_zero(ctx, el_size * count, name);
 }
 
-/*
-  alloc an zero array, checking for integer overflow in the array size
-  Strict version - returns NULL if count or el_size are zero.
-*/
-void *_talloc_zero_array_strict(const void *ctx, size_t el_size, unsigned count, const char *name)
-{
-       if (count >= MAX_TALLOC_SIZE/el_size) {
-               return NULL;
-       }
-
-       if (el_size == 0 || count == 0) {
-               return NULL;
-       }
-
-       return _talloc_zero(ctx, el_size * count, name);
-}
-
-
 /*
   realloc an array, checking for integer overflow in the array size
 */
@@ -1497,14 +1419,3 @@ int talloc_is_parent(const void *context, const void *ptr)
        }
        return 0;
 }
-
-/*
-  Talloc wrapper that returns NULL if size == 0.
-*/
-void *talloc_strict(const void *context, size_t size, const char *name)
-{
-       if (unlikely(size == 0)) {
-               return NULL;
-       }
-       return _talloc_named_const(context, size, name);
-}
index 48bf4303c604be3ea550b34a0fbdcc24c54c742a..d9e7d9433877728c9e714544e11ed5c38940c56f 100644 (file)
@@ -84,33 +84,22 @@ typedef void TALLOC_CTX;
 /* useful macros for creating type checked pointers */
 #define talloc(ctx, type) (type *)talloc_named_const(ctx, sizeof(type), #type)
 #define talloc_size(ctx, size) talloc_named_const(ctx, size, __location__)
-#define talloc_size_strict(ctx, size) talloc_strict(ctx, size, __location__)
 #define talloc_ptrtype(ctx, ptr) (_TALLOC_TYPEOF(ptr))talloc_size(ctx, sizeof(*(ptr)))
 
 #define talloc_new(ctx) talloc_named_const(ctx, 0, "talloc_new: " __location__)
 
 #define talloc_zero(ctx, type) (type *)_talloc_zero(ctx, sizeof(type), #type)
-/* Varient of talloc_zero that returns NULL if size is zero. */
-#define talloc_zero_strict(ctx, type) (type *)_talloc_zero_strict(ctx, sizeof(type), #type)
 #define talloc_zero_size(ctx, size) _talloc_zero(ctx, size, __location__)
-#define talloc_zero_size_strict(ctx, size) _talloc_zero_strict(ctx, size, __location__)
 
 #define talloc_zero_array(ctx, type, count) (type *)_talloc_zero_array(ctx, sizeof(type), count, #type)
-/* Varient of talloc_zero_array that returns NULL if count is zero. */
-#define talloc_zero_array_strict(ctx, type, count) (type *)_talloc_zero_array_strict(ctx, sizeof(type), count, #type)
 #define talloc_array(ctx, type, count) (type *)_talloc_array(ctx, sizeof(type), count, #type)
-/* Varient of talloc_array that returns NULL if count is zero. */
-#define talloc_array_strict(ctx, type, count) (type *)_talloc_array_strict(ctx, sizeof(type), count, #type)
 #define talloc_array_size(ctx, size, count) _talloc_array(ctx, size, count, __location__)
-#define talloc_array_size_strict(ctx, size, count) _talloc_array_strict(ctx, size, count, __location__)
 #define talloc_array_ptrtype(ctx, ptr, count) (_TALLOC_TYPEOF(ptr))talloc_array_size(ctx, sizeof(*(ptr)), count)
 
 #define talloc_realloc(ctx, p, type, count) (type *)_talloc_realloc_array(ctx, p, sizeof(type), count, #type)
 #define talloc_realloc_size(ctx, ptr, size) _talloc_realloc(ctx, ptr, size, __location__)
 
 #define talloc_memdup(t, p, size) _talloc_memdup(t, p, size, __location__)
-/* Varient of talloc_memdup that returns NULL if count is zero. */
-#define talloc_memdup_strict(t, p, size) _talloc_memdup_strict(t, p, size, __location__)
 
 #define talloc_set_type(ptr, type) talloc_set_name_const(ptr, #type)
 #define talloc_get_type(ptr, type) (type *)talloc_check_name(ptr, #type)
@@ -163,9 +152,7 @@ void talloc_disable_null_tracking(void);
 void talloc_enable_leak_report(void);
 void talloc_enable_leak_report_full(void);
 void *_talloc_zero(const void *ctx, size_t size, const char *name);
-void *_talloc_zero_strict(const void *ctx, size_t size, const char *name);
 void *_talloc_memdup(const void *t, const void *p, size_t size, const char *name);
-void *_talloc_memdup_strict(const void *t, const void *p, size_t size, const char *name);
 char *talloc_strdup(const void *t, const char *p);
 char *talloc_strndup(const void *t, const char *p, size_t n);
 char *talloc_append_string(const void *t, char *orig, const char *append);
@@ -174,9 +161,7 @@ char *talloc_vasprintf_append(char *s, const char *fmt, va_list ap) PRINTF_ATTRI
 char *talloc_asprintf(const void *t, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
 char *talloc_asprintf_append(char *s, const char *fmt, ...) PRINTF_ATTRIBUTE(2,3);
 void *_talloc_array(const void *ctx, size_t el_size, unsigned count, const char *name);
-void *_talloc_array_strict(const void *ctx, size_t el_size, unsigned count, const char *name);
 void *_talloc_zero_array(const void *ctx, size_t el_size, unsigned count, const char *name);
-void *_talloc_zero_array_strict(const void *ctx, size_t el_size, unsigned count, const char *name);
 void *_talloc_realloc_array(const void *ctx, void *ptr, size_t el_size, unsigned count, const char *name);
 void *talloc_realloc_fn(const void *context, void *ptr, size_t size);
 void *talloc_autofree_context(void);
@@ -184,6 +169,5 @@ size_t talloc_get_size(const void *ctx);
 void *talloc_find_parent_byname(const void *ctx, const char *name);
 void talloc_show_parents(const void *context, FILE *file);
 int talloc_is_parent(const void *context, const void *ptr);
-void *talloc_strict(const void *context, size_t size, const char *name);
 
 #endif
index 1e64db38fc3d6138f1a46ef23c32ff80673984e7..9a22e89fe21af0de44f8c30665a50d38cc03fb9e 100644 (file)
@@ -3227,3 +3227,102 @@ int get_safe_IVAL(const char *buf_base, size_t buf_len, char *ptr, size_t off, i
        }
        return IVAL(ptr,off);
 }
+
+/****************************************************************
+ talloc wrapper functions that guarentee a null pointer return
+ if size == 0.
+****************************************************************/
+
+#ifndef MAX_TALLOC_SIZE
+#define MAX_TALLOC_SIZE 0x10000000
+#endif
+
+/*
+ *    talloc and zero memory.
+ *    - returns NULL if size is zero.
+ */
+
+void *_talloc_zero_zeronull(const void *ctx, size_t size, const char *name)
+{
+       void *p;
+
+       if (size == 0) {
+               return NULL;
+       }
+
+       p = talloc_named_const(ctx, size, name);
+
+       if (p) {
+               memset(p, '\0', size);
+       }
+
+       return p;
+}
+
+/*
+ *   memdup with a talloc.
+ *   - returns NULL if size is zero.
+ */
+
+void *_talloc_memdup_zeronull(const void *t, const void *p, size_t size, const char *name)
+{
+       void *newp;
+
+       if (size == 0) {
+               return NULL;
+       }
+
+       newp = talloc_named_const(t, size, name);
+       if (newp) {
+               memcpy(newp, p, size);
+       }
+
+       return newp;
+}
+
+/*
+ *   alloc an array, checking for integer overflow in the array size.
+ *   - returns NULL if count or el_size are zero.
+ */
+
+void *_talloc_array_zeronull(const void *ctx, size_t el_size, unsigned count, const char *name)
+{
+       if (count >= MAX_TALLOC_SIZE/el_size) {
+               return NULL;
+       }
+
+       if (el_size == 0 || count == 0) {
+               return NULL;
+       }
+
+       return talloc_named_const(ctx, el_size * count, name);
+}
+
+/*
+ *   alloc an zero array, checking for integer overflow in the array size
+ *   - returns NULL if count or el_size are zero.
+ */
+
+void *_talloc_zero_array_zeronull(const void *ctx, size_t el_size, unsigned count, const char *name)
+{
+       if (count >= MAX_TALLOC_SIZE/el_size) {
+               return NULL;
+       }
+
+       if (el_size == 0 || count == 0) {
+               return NULL;
+       }
+
+       return _talloc_zero(ctx, el_size * count, name);
+}
+
+/*
+ *   Talloc wrapper that returns NULL if size == 0.
+ */
+void *talloc_zeronull(const void *context, size_t size, const char *name)
+{
+       if (size == 0) {
+               return NULL;
+       }
+       return talloc_named_const(context, size, name);
+}
index bbc4b68656fb29b6a6bf5ccba22a2b93134f9760..4862a23b3d48dfd86dc5dd5ba2c18393f4697468 100644 (file)
 
 #include <talloc.h>
 
-#define TALLOC(ctx, size) talloc_strict(ctx, size, __location__)
-#define TALLOC_P(ctx, type) (type *)talloc_strict(ctx, sizeof(type), #type)
-#define TALLOC_ARRAY(ctx, type, count) (type *)_talloc_array_strict(ctx, sizeof(type), count, #type)
-#define TALLOC_MEMDUP(ctx, ptr, size) _talloc_memdup_strict(ctx, ptr, size, __location__)
-#define TALLOC_ZERO(ctx, size) _talloc_zero_strict(ctx, size, __location__)
-#define TALLOC_ZERO_P(ctx, type) (type *)_talloc_zero_strict(ctx, sizeof(type), #type)
-#define TALLOC_ZERO_ARRAY(ctx, type, count) (type *)_talloc_zero_array_strict(ctx, sizeof(type), count, #type)
+void *_talloc_zero_zeronull(const void *ctx, size_t size, const char *name);
+void *_talloc_memdup_zeronull(const void *t, const void *p, size_t size, const char *name);
+void *_talloc_array_zeronull(const void *ctx, size_t el_size, unsigned count, const char *name);
+void *_talloc_zero_array_zeronull(const void *ctx, size_t el_size, unsigned count, const char *name);
+void *talloc_zeronull(const void *context, size_t size, const char *name);
+
+#define TALLOC(ctx, size) talloc_zeronull(ctx, size, __location__)
+#define TALLOC_P(ctx, type) (type *)talloc_zeronull(ctx, sizeof(type), #type)
+#define TALLOC_ARRAY(ctx, type, count) (type *)_talloc_array_zeronull(ctx, sizeof(type), count, #type)
+#define TALLOC_MEMDUP(ctx, ptr, size) _talloc_memdup_zeronull(ctx, ptr, size, __location__)
+#define TALLOC_ZERO(ctx, size) _talloc_zero_zeronull(ctx, size, __location__)
+#define TALLOC_ZERO_P(ctx, type) (type *)_talloc_zero_zeronull(ctx, sizeof(type), #type)
+#define TALLOC_ZERO_ARRAY(ctx, type, count) (type *)_talloc_zero_array_zeronull(ctx, sizeof(type), count, #type)
 #define TALLOC_REALLOC(ctx, ptr, count) _talloc_realloc(ctx, ptr, count, __location__)
 #define TALLOC_REALLOC_ARRAY(ctx, ptr, type, count) (type *)_talloc_realloc_array(ctx, ptr, sizeof(type), count, #type)
+#define talloc_destroy(ctx) talloc_free(ctx)
 #define TALLOC_FREE(ctx) do { if ((ctx) != NULL) {talloc_free(ctx); ctx=NULL;} } while(0)
+#define TALLOC_SIZE(ctx, size) talloc_zeronull(ctx, size, __location__)
+#define TALLOC_ZERO_SIZE(ctx, size) _talloc_zero_zeronull(ctx, size, __location__)
 
 /*******************************************************************
    Type definitions for int16, int32, uint16 and uint32.  Needed
index bf79c443953c6b6fe652387ef5a90fc5a8bb2a86..56fffcc26ee0556bb03936afd8d0605c8ba8d6df 100644 (file)
@@ -158,7 +158,7 @@ char *prs_alloc_mem(prs_struct *ps, size_t size, unsigned int count)
 
        if (size && count) {
                /* We can't call the type-safe version here. */
-               ret = (char *)_talloc_zero_array_strict(ps->mem_ctx, size, count,
+               ret = (char *)_talloc_zero_array_zeronull(ps->mem_ctx, size, count,
                                                 "parse_prs");
        }
        return ret;