svn commit: samba r3052 - in branches/SAMBA_4_0/source: include lib
tridge at samba.org
tridge at samba.org
Tue Oct 19 06:29:41 GMT 2004
Author: tridge
Date: 2004-10-19 06:29:41 +0000 (Tue, 19 Oct 2004)
New Revision: 3052
WebSVN: http://websvn.samba.org/websvn/changeset.php?rep=samba&path=/branches/SAMBA_4_0/source&rev=3052&nolog=1
Log:
added talloc_zero_p() and talloc_zero_array_p() calls, for allocating zeroed memory
Modified:
branches/SAMBA_4_0/source/include/talloc.h
branches/SAMBA_4_0/source/lib/talloc.c
Changeset:
Modified: branches/SAMBA_4_0/source/include/talloc.h
===================================================================
--- branches/SAMBA_4_0/source/include/talloc.h 2004-10-18 22:01:10 UTC (rev 3051)
+++ branches/SAMBA_4_0/source/include/talloc.h 2004-10-19 06:29:41 UTC (rev 3052)
@@ -34,8 +34,11 @@
/* useful macros for creating type checked pointers */
#define talloc(ctx, size) talloc_named_const(ctx, size, __location__)
+#define talloc_zero(ctx, size) _talloc_zero(ctx, size, __location__)
#define talloc_realloc(ctx, ptr, size) _talloc_realloc(ctx, ptr, size, __location__)
#define talloc_p(ctx, type) (type *)talloc_named_const(ctx, sizeof(type), #type)
+#define talloc_zero_p(ctx, type) (type *)_talloc_zero(ctx, sizeof(type), #type)
+#define talloc_zero_array_p(ctx, type, count) (type *)talloc_zero_array(ctx, sizeof(type), count, __location__)
#define talloc_array_p(ctx, type, count) (type *)talloc_array(ctx, sizeof(type), count, __location__)
#define talloc_realloc_p(ctx, p, type, count) (type *)talloc_realloc_array(ctx, p, sizeof(type), count, __location__)
#define talloc_memdup(t, p, size) _talloc_memdup(t, p, size, __location__)
@@ -76,7 +79,7 @@
void talloc_report(const void *ptr, FILE *f);
void talloc_enable_leak_report(void);
void talloc_enable_leak_report_full(void);
-void *talloc_zero(const void *ctx, size_t size);
+void *_talloc_zero(const void *ctx, size_t size, const char *name);
void *_talloc_memdup(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);
@@ -85,6 +88,7 @@
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_zero_array(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_ldb_alloc(void *context, void *ptr, size_t size);
Modified: branches/SAMBA_4_0/source/lib/talloc.c
===================================================================
--- branches/SAMBA_4_0/source/lib/talloc.c 2004-10-18 22:01:10 UTC (rev 3051)
+++ branches/SAMBA_4_0/source/lib/talloc.c 2004-10-19 06:29:41 UTC (rev 3052)
@@ -776,9 +776,9 @@
/*
talloc and zero memory.
*/
-void *talloc_zero(const void *ctx, size_t size)
+void *_talloc_zero(const void *ctx, size_t size, const char *name)
{
- void *p = talloc(ctx, size);
+ void *p = talloc_named_const(ctx, size, name);
if (p) {
memset(p, '\0', size);
@@ -939,7 +939,18 @@
return talloc_named_const(ctx, el_size * count, name);
}
+/*
+ alloc an zero array, checking for integer overflow in the array size
+*/
+void *talloc_zero_array(const void *ctx, size_t el_size, unsigned count, const char *name)
+{
+ if (count >= MAX_TALLOC_SIZE/el_size) {
+ return NULL;
+ }
+ return _talloc_zero(ctx, el_size * count, name);
+}
+
/*
realloc an array, checking for integer overflow in the array size
*/
More information about the samba-cvs
mailing list