From 7e297ecfa4db2c7ab720a63c7764bc0e20f8058c Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sun, 9 Sep 2007 19:34:30 +0000 Subject: r25047: Fix more warnings. (This used to be commit 69de86d2d2e49439760fbc61901eb87fb7fc5d55) --- source4/lib/util/ms_fnmatch.c | 5 ++--- source4/lib/util/util.h | 13 ++----------- source4/lib/util/util_pw.c | 45 ++++++++++++++++--------------------------- source4/lib/util/util_str.c | 20 ------------------- 4 files changed, 21 insertions(+), 62 deletions(-) (limited to 'source4/lib/util') diff --git a/source4/lib/util/ms_fnmatch.c b/source4/lib/util/ms_fnmatch.c index 8e216b0226..73fb0e0966 100644 --- a/source4/lib/util/ms_fnmatch.c +++ b/source4/lib/util/ms_fnmatch.c @@ -201,11 +201,10 @@ int ms_fnmatch(const char *pattern, const char *string, enum protocol_types prot if (pattern[i] == '*' || pattern[i] == '<') count++; } - max_n = talloc_array(NULL, struct max_n, count); - if (!max_n) { + max_n = talloc_zero_array(NULL, struct max_n, count); + if (max_n == NULL) { return -1; } - memset(max_n, 0, sizeof(struct max_n) * count); ret = ms_fnmatch_core(pattern, string, max_n, strrchr(string, '.')); diff --git a/source4/lib/util/util.h b/source4/lib/util/util.h index a2e0954517..004c453a64 100644 --- a/source4/lib/util/util.h +++ b/source4/lib/util/util.h @@ -28,7 +28,6 @@ * @brief Helpful macros */ -struct substitute_context; struct smbsrv_tcon; extern const char *logfile; @@ -73,7 +72,7 @@ extern const char *panic_action; */ #define SMB_ASSERT(b) do { if (!(b)) { \ DEBUG(0,("PANIC: assert failed at %s(%d)\n", __FILE__, __LINE__)); \ - smb_panic("assert failed"); abort(); }} while (0) + smb_panic("assert failed"); }} while (0) #ifndef SAFE_FREE /* Oh no this is also defined in tdb.h */ /** @@ -370,12 +369,6 @@ _PUBLIC_ void hex_encode(const unsigned char *buff_in, size_t len, char **out_he */ _PUBLIC_ char *hex_encode_talloc(TALLOC_CTX *mem_ctx, const unsigned char *buff_in, size_t len); -/** - Set a string value, deallocating any existing space, and allocing the space - for the string -**/ -_PUBLIC_ bool string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src); - /** Substitute a string for a pattern in another string. Make sure there is enough room! @@ -780,8 +773,6 @@ enum protocol_types { PROTOCOL_SMB2 }; - - int ms_fnmatch(const char *pattern, const char *string, enum protocol_types protocol); /** a generic fnmatch function - uses for non-CIFS pattern matching */ @@ -838,6 +829,6 @@ _PUBLIC_ int idr_remove(struct idr_context *idp, int id); /** Become a daemon, discarding the controlling terminal. **/ -_PUBLIC_ void become_daemon(bool Fork); +_PUBLIC_ void become_daemon(bool fork); #endif /* _SAMBA_UTIL_H_ */ diff --git a/source4/lib/util/util_pw.c b/source4/lib/util/util_pw.c index 0e0675571e..11e46ec4e3 100644 --- a/source4/lib/util/util_pw.c +++ b/source4/lib/util/util_pw.c @@ -21,37 +21,26 @@ #include "includes.h" -static struct passwd *alloc_copy_passwd(const struct passwd *from) +static struct passwd *alloc_copy_passwd(TALLOC_CTX *mem_ctx, + const struct passwd *from) { - struct passwd *ret = smb_xmalloc_p(struct passwd); - ZERO_STRUCTP(ret); - ret->pw_name = smb_xstrdup(from->pw_name); - ret->pw_passwd = smb_xstrdup(from->pw_passwd); - ret->pw_uid = from->pw_uid; - ret->pw_gid = from->pw_gid; - ret->pw_gecos = smb_xstrdup(from->pw_gecos); - ret->pw_dir = smb_xstrdup(from->pw_dir); - ret->pw_shell = smb_xstrdup(from->pw_shell); - return ret; -} + struct passwd *ret = talloc_zero(mem_ctx, struct passwd); -void passwd_free (struct passwd **buf) -{ - if (!*buf) { - DEBUG(0, ("attempted double-free of allocated passwd\n")); - return; - } + if (ret == NULL) + return NULL; - SAFE_FREE((*buf)->pw_name); - SAFE_FREE((*buf)->pw_passwd); - SAFE_FREE((*buf)->pw_gecos); - SAFE_FREE((*buf)->pw_dir); - SAFE_FREE((*buf)->pw_shell); + ret->pw_name = talloc_strdup(ret, from->pw_name); + ret->pw_passwd = talloc_strdup(ret, from->pw_passwd); + ret->pw_uid = from->pw_uid; + ret->pw_gid = from->pw_gid; + ret->pw_gecos = talloc_strdup(ret, from->pw_gecos); + ret->pw_dir = talloc_strdup(ret, from->pw_dir); + ret->pw_shell = talloc_strdup(ret, from->pw_shell); - SAFE_FREE(*buf); + return ret; } -struct passwd *getpwnam_alloc(const char *name) +struct passwd *getpwnam_alloc(TALLOC_CTX *mem_ctx, const char *name) { struct passwd *temp; @@ -66,10 +55,10 @@ struct passwd *getpwnam_alloc(const char *name) return NULL; } - return alloc_copy_passwd(temp); + return alloc_copy_passwd(mem_ctx, temp); } -struct passwd *getpwuid_alloc(uid_t uid) +struct passwd *getpwuid_alloc(TALLOC_CTX *mem_ctx, uid_t uid) { struct passwd *temp; @@ -84,5 +73,5 @@ struct passwd *getpwuid_alloc(uid_t uid) return NULL; } - return alloc_copy_passwd(temp); + return alloc_copy_passwd(mem_ctx, temp); } diff --git a/source4/lib/util/util_str.c b/source4/lib/util/util_str.c index 4bec469f87..0f1f2d5a1c 100644 --- a/source4/lib/util/util_str.c +++ b/source4/lib/util/util_str.c @@ -259,26 +259,6 @@ _PUBLIC_ char *hex_encode_talloc(TALLOC_CTX *mem_ctx, const unsigned char *buff_ return hex_buffer; } -/** - Set a string value, deallocating any existing space, and allocing the space - for the string -**/ -_PUBLIC_ bool string_set(TALLOC_CTX *mem_ctx, char **dest, const char *src) -{ - talloc_free(*dest); - - if (src == NULL) - src = ""; - - *dest = talloc_strdup(mem_ctx, src); - if ((*dest) == NULL) { - DEBUG(0,("Out of memory in string_init\n")); - return false; - } - - return true; -} - /** Substitute a string for a pattern in another string. Make sure there is enough room! -- cgit