From eec698254f67365f27b4b7569fa982e22472aca1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 3 Dec 2004 07:20:30 +0000 Subject: [PATCH] r4055: fixed more places to use type safe allocation macros --- source/auth/pampass.c | 10 +++++----- source/client/client.c | 4 ++-- source/include/smb_interfaces.h | 2 +- source/lib/gencache.c | 5 ++--- source/lib/netif/interface.c | 2 +- source/lib/registry/common/reg_interface.c | 4 ++-- .../registry/reg_backend_nt4/reg_backend_nt4.c | 16 ++++++++-------- source/lib/registry/tools/regshell.c | 4 ++-- source/lib/replace.c | 2 +- source/lib/util_file.c | 2 +- source/lib/util_getent.c | 12 ++++++------ source/lib/wins_srv.c | 2 +- source/lib/xfile.c | 2 +- source/libads/ldap.c | 12 ++++++------ source/libcli/auth/clikrb5.c | 4 ++-- source/libcli/auth/spnego_parse.c | 2 +- source/libcli/ldap/ldap.c | 9 ++++----- source/libcli/nmblib.c | 4 ++-- source/libcli/raw/raweas.c | 4 ++-- source/libcli/raw/rawnotify.c | 3 +-- source/librpc/rpc/dcerpc.c | 4 ++-- source/ntvfs/cifs/vfs_cifs.c | 2 +- source/param/loadparm.c | 2 +- source/rpc_server/spoolss/dcesrv_spoolss.c | 2 +- source/smb_server/nttrans.c | 2 +- source/smb_server/trans2.c | 2 +- source/torture/basic/aliases.c | 4 ++-- source/torture/nbench/nbio.c | 2 +- source/torture/raw/mkdir.c | 2 +- source/torture/raw/open.c | 2 +- source/utils/setntacl.c | 2 +- 31 files changed, 64 insertions(+), 67 deletions(-) diff --git a/source/auth/pampass.c b/source/auth/pampass.c index a5c9a5de1..8612aa9ac 100644 --- a/source/auth/pampass.c +++ b/source/auth/pampass.c @@ -130,7 +130,7 @@ static int smb_pam_conv(int num_msg, return PAM_CONV_ERR; } - reply = malloc(sizeof(struct pam_response) * num_msg); + reply = malloc_array_p(struct pam_response, num_msg); if (!reply) return PAM_CONV_ERR; @@ -210,7 +210,7 @@ static struct chat_struct *make_pw_chat(char *p) struct chat_struct *t; while (1) { - t = (struct chat_struct *)malloc(sizeof(*t)); + t = malloc_p(struct chat_struct); if (!t) { DEBUG(0,("make_pw_chat: malloc failed!\n")); return NULL; @@ -289,7 +289,7 @@ static int smb_pam_passchange_conv(int num_msg, return PAM_CONV_ERR; } - reply = malloc(sizeof(struct pam_response) * num_msg); + reply = malloc_array_p(struct pam_response, num_msg); if (!reply) { DEBUG(0,("smb_pam_passchange_conv: malloc for reply failed!\n")); free_pw_chat(pw_chat); @@ -405,8 +405,8 @@ static void smb_free_pam_conv(struct pam_conv *pconv) static struct pam_conv *smb_setup_pam_conv(smb_pam_conv_fn smb_pam_conv_fnptr, const char *user, const char *passwd, const char *newpass) { - struct pam_conv *pconv = (struct pam_conv *)malloc(sizeof(struct pam_conv)); - struct smb_pam_userdata *udp = (struct smb_pam_userdata *)malloc(sizeof(struct smb_pam_userdata)); + struct pam_conv *pconv = malloc_p(struct pam_conv); + struct smb_pam_userdata *udp = malloc_p(struct smb_pam_userdata); if (pconv == NULL || udp == NULL) { SAFE_FREE(pconv); diff --git a/source/client/client.c b/source/client/client.c index e4a7dc7cb..dae24ce92 100644 --- a/source/client/client.c +++ b/source/client/client.c @@ -2593,7 +2593,7 @@ static char **remote_completion(const char *text, int len) if (len >= PATH_MAX) return(NULL); - info.matches = (char **)malloc(sizeof(info.matches[0])*MAX_COMPLETIONS); + info.matches = malloc_array_p(char *, MAX_COMPLETIONS); if (!info.matches) return NULL; info.matches[0] = NULL; @@ -2673,7 +2673,7 @@ static char **completion_fn(const char *text, int start, int end) char **matches; int i, len, samelen = 0, count=1; - matches = (char **)malloc(sizeof(matches[0])*MAX_COMPLETIONS); + matches = malloc_array_p(char *, MAX_COMPLETIONS); if (!matches) return NULL; matches[0] = NULL; diff --git a/source/include/smb_interfaces.h b/source/include/smb_interfaces.h index 5d31f0c6c..bc5c43f59 100644 --- a/source/include/smb_interfaces.h +++ b/source/include/smb_interfaces.h @@ -1644,7 +1644,7 @@ struct smb_notify { struct { uint32_t num_changes; - struct { + struct notify_changes { uint32_t action; WIRE_STRING name; } *changes; diff --git a/source/lib/gencache.c b/source/lib/gencache.c index f32db598f..160367cfe 100644 --- a/source/lib/gencache.c +++ b/source/lib/gencache.c @@ -253,8 +253,7 @@ BOOL gencache_get(const char *keystr, char **valstr, time_t *timeout) time_t t; unsigned i; - v = (char*)malloc(sizeof(char) * - (databuf.dsize - TIMEOUT_LEN)); + v = malloc_array_p(char, databuf.dsize - TIMEOUT_LEN); SAFE_FREE(databuf.dptr); sscanf(entry_buf, CACHE_DATA_FMT, (int*)&i, v); @@ -338,7 +337,7 @@ void gencache_iterate(void (*fn)(const char* key, const char *value, time_t time } entry = strndup(databuf.dptr, databuf.dsize); SAFE_FREE(databuf.dptr); - valstr = (char*)malloc(sizeof(char) * (databuf.dsize - TIMEOUT_LEN)); + valstr = malloc_array_p(char, databuf.dsize - TIMEOUT_LEN); sscanf(entry, CACHE_DATA_FMT, (int*)(&i), valstr); timeout = i; diff --git a/source/lib/netif/interface.c b/source/lib/netif/interface.c index 355517012..c73a2e3d7 100644 --- a/source/lib/netif/interface.c +++ b/source/lib/netif/interface.c @@ -83,7 +83,7 @@ static void add_interface(struct in_addr ip, struct in_addr nmask) return; } - iface = (struct interface *)malloc(sizeof(*iface)); + iface = malloc_p(struct interface); if (!iface) return; ZERO_STRUCTPN(iface); diff --git a/source/lib/registry/common/reg_interface.c b/source/lib/registry/common/reg_interface.c index dea886174..f7d3af070 100644 --- a/source/lib/registry/common/reg_interface.c +++ b/source/lib/registry/common/reg_interface.c @@ -51,7 +51,7 @@ NTSTATUS registry_register(const void *_function) return NT_STATUS_OBJECT_NAME_COLLISION; } - entry = malloc(sizeof(struct reg_init_function_entry)); + entry = malloc_p(struct reg_init_function_entry); entry->functions = functions; DLIST_ADD(backends, entry); @@ -85,7 +85,7 @@ WERROR reg_create(struct registry_context **_ret) TALLOC_CTX *mem_ctx; struct registry_context *ret; mem_ctx = talloc_init("registry handle"); - ret = talloc(mem_ctx, sizeof(struct registry_context)); + ret = talloc_p(mem_ctx, struct registry_context); ret->mem_ctx = mem_ctx; ZERO_STRUCTP(ret); *_ret = ret; diff --git a/source/lib/registry/reg_backend_nt4/reg_backend_nt4.c b/source/lib/registry/reg_backend_nt4/reg_backend_nt4.c index aac6e548a..381f0c3bc 100644 --- a/source/lib/registry/reg_backend_nt4/reg_backend_nt4.c +++ b/source/lib/registry/reg_backend_nt4/reg_backend_nt4.c @@ -540,7 +540,7 @@ static SEC_DESC *nt_create_def_sec_desc(struct registry_hive *regf) { SEC_DESC *tmp; - tmp = (SEC_DESC *)malloc(sizeof(SEC_DESC)); + tmp = malloc_p(SEC_DESC); tmp->revision = 1; tmp->type = SEC_DESC_SELF_RELATIVE | SEC_DESC_DACL_PRESENT; @@ -577,7 +577,7 @@ static KEY_SEC_DESC *nt_create_init_sec(struct registry_hive *h) REGF *regf = h->backend_data; KEY_SEC_DESC *tsec = NULL; - tsec = (KEY_SEC_DESC *)malloc(sizeof(KEY_SEC_DESC)); + tsec = malloc_p(KEY_SEC_DESC); tsec->ref_cnt = 1; tsec->state = SEC_DESC_NBK; @@ -682,7 +682,7 @@ static SK_MAP *alloc_sk_map_entry(struct registry_hive *h, KEY_SEC_DESC *tmp, in { REGF *regf = h->backend_data; if (!regf->sk_map) { /* Allocate a block of 10 */ - regf->sk_map = (SK_MAP *)malloc(sizeof(SK_MAP) * 10); + regf->sk_map = malloc_array_p(SK_MAP, 10); regf->sk_map_size = 10; regf->sk_count = 1; (regf->sk_map)[0].sk_off = sk_off; @@ -742,7 +742,7 @@ static KEY_SEC_DESC *lookup_create_sec_key(struct registry_hive *h, SK_MAP *sk_m return tmp; } else { /* Allocate a new one */ - tmp = (KEY_SEC_DESC *)malloc(sizeof(KEY_SEC_DESC)); + tmp = malloc_p(KEY_SEC_DESC); memset(tmp, 0, sizeof(KEY_SEC_DESC)); /* Neatly sets offset to 0 */ tmp->state = SEC_DESC_RES; if (!alloc_sk_map_entry(h, tmp, sk_off)) { @@ -756,7 +756,7 @@ static SEC_DESC *process_sec_desc(struct registry_hive *regf, SEC_DESC *sec_desc { SEC_DESC *tmp = NULL; - tmp = (SEC_DESC *)malloc(sizeof(SEC_DESC)); + tmp = malloc_p(SEC_DESC); tmp->revision = SVAL(&sec_desc->revision,0); tmp->type = SVAL(&sec_desc->type,0); @@ -838,7 +838,7 @@ static KEY_SEC_DESC *process_sk(struct registry_hive *regf, SK_HDR *sk_hdr, int */ if (!tmp) { - tmp = (KEY_SEC_DESC *)malloc(sizeof(KEY_SEC_DESC)); + tmp = malloc_p(KEY_SEC_DESC); memset(tmp, 0, sizeof(KEY_SEC_DESC)); /* @@ -1154,7 +1154,7 @@ static HBIN_BLK *nt_create_hbin_blk(struct registry_hive *h, int size) size = (size + (REGF_HDR_BLKSIZ - 1)) & ~(REGF_HDR_BLKSIZ - 1); - tmp = (HBIN_BLK *)malloc(sizeof(HBIN_BLK)); + tmp = malloc_p(HBIN_BLK); memset(tmp, 0, sizeof(HBIN_BLK)); tmp->data = malloc(size); @@ -1553,7 +1553,7 @@ static REGF_HDR *nt_get_reg_header(struct registry_hive *h) { REGF *regf = h->backend_data; HBIN_BLK *tmp = NULL; - tmp = (HBIN_BLK *)malloc(sizeof(HBIN_BLK)); + tmp = malloc_p(HBIN_BLK); memset(tmp, 0, sizeof(HBIN_BLK)); tmp->type = REG_OUTBLK_HDR; diff --git a/source/lib/registry/tools/regshell.c b/source/lib/registry/tools/regshell.c index 333329908..f18b01272 100644 --- a/source/lib/registry/tools/regshell.c +++ b/source/lib/registry/tools/regshell.c @@ -247,7 +247,7 @@ static char **reg_complete_command(const char *text, int end) char **matches; int i, len, samelen=0, count=1; - matches = (char **)malloc(sizeof(matches[0])*MAX_COMPLETIONS); + matches = malloc_array_p(char *, MAX_COMPLETIONS); if (!matches) return NULL; matches[0] = NULL; @@ -301,7 +301,7 @@ static char **reg_complete_key(const char *text, int end) TALLOC_CTX *mem_ctx; /* Complete argument */ - matches = (char **)malloc(sizeof(matches[0])*MAX_COMPLETIONS); + matches = malloc_array_p(char *, MAX_COMPLETIONS); if (!matches) return NULL; matches[0] = NULL; diff --git a/source/lib/replace.c b/source/lib/replace.c index 35e0277c5..ca367da9b 100644 --- a/source/lib/replace.c +++ b/source/lib/replace.c @@ -205,7 +205,7 @@ Corrections by richard.kettlewell@kewill.com struct group *g; char *gr; - if((grouplst = (gid_t *)malloc(sizeof(gid_t) * max_gr)) == NULL) { + if((grouplst = malloc_array_p(gid_t, max_gr)) == NULL) { DEBUG(0,("initgroups: malloc fail !\n")); return -1; } diff --git a/source/lib/util_file.c b/source/lib/util_file.c index f9697fb33..2b2fe2b2a 100644 --- a/source/lib/util_file.c +++ b/source/lib/util_file.c @@ -281,7 +281,7 @@ static char **file_lines_parse(char *p, size_t size, int *numlines) if (s[0] == '\n') i++; } - ret = (char **)malloc(sizeof(ret[0])*(i+2)); + ret = malloc_array_p(char *, i+2); if (!ret) { SAFE_FREE(p); return NULL; diff --git a/source/lib/util_getent.c b/source/lib/util_getent.c index 599e4bb91..9f58472fb 100644 --- a/source/lib/util_getent.c +++ b/source/lib/util_getent.c @@ -33,7 +33,7 @@ struct sys_grent * getgrent_list(void) struct sys_grent *gent; struct group *grp; - gent = (struct sys_grent *) malloc(sizeof(struct sys_grent)); + gent = malloc_p(struct sys_grent); if (gent == NULL) { DEBUG (0, ("Out of memory in getgrent_list!\n")); return NULL; @@ -67,7 +67,7 @@ struct sys_grent * getgrent_list(void) ; /* alloc space for gr_mem string pointers */ - if ((gent->gr_mem = (char **) malloc((num+1) * sizeof(char *))) == NULL) + if ((gent->gr_mem = malloc_array_p(char *, num+1)) == NULL) goto err; memset(gent->gr_mem, '\0', (num+1) * sizeof(char *)); @@ -80,7 +80,7 @@ struct sys_grent * getgrent_list(void) grp = getgrent(); if (grp) { - gent->next = (struct sys_grent *) malloc(sizeof(struct sys_grent)); + gent->next = malloc_p(struct sys_grent); if (gent->next == NULL) goto err; gent = gent->next; @@ -134,7 +134,7 @@ struct sys_pwent * getpwent_list(void) struct sys_pwent *pent; struct passwd *pwd; - pent = (struct sys_pwent *) malloc(sizeof(struct sys_pwent)); + pent = malloc_p(struct sys_pwent); if (pent == NULL) { DEBUG (0, ("Out of memory in getpwent_list!\n")); return NULL; @@ -170,7 +170,7 @@ struct sys_pwent * getpwent_list(void) pwd = getpwent(); if (pwd) { - pent->next = (struct sys_pwent *) malloc(sizeof(struct sys_pwent)); + pent->next = malloc_p(struct sys_pwent); if (pent->next == NULL) goto err; pent = pent->next; @@ -223,7 +223,7 @@ static struct sys_userlist *add_members_to_userlist(struct sys_userlist *list_he ; for (i = 0; i < num_users; i++) { - struct sys_userlist *entry = (struct sys_userlist *)malloc(sizeof(*entry)); + struct sys_userlist *entry = malloc_p(struct sys_userlist); if (entry == NULL) { free_userlist(list_head); return NULL; diff --git a/source/lib/wins_srv.c b/source/lib/wins_srv.c index 094de8d6b..0338db8b3 100644 --- a/source/lib/wins_srv.c +++ b/source/lib/wins_srv.c @@ -204,7 +204,7 @@ char **wins_srv_tags(void) if (lp_wins_support()) { /* give the caller something to chew on. This makes the rest of the logic simpler (ie. less special cases) */ - ret = (char **)malloc(sizeof(char *)*2); + ret = malloc_array_p(char *, 2); if (!ret) return NULL; ret[0] = strdup("*"); ret[1] = NULL; diff --git a/source/lib/xfile.c b/source/lib/xfile.c index 856e5dd6e..794e3f0f5 100644 --- a/source/lib/xfile.c +++ b/source/lib/xfile.c @@ -96,7 +96,7 @@ XFILE *x_fopen(const char *fname, int flags, mode_t mode) { XFILE *ret; - ret = (XFILE *)malloc(sizeof(XFILE)); + ret = malloc_p(XFILE); if (!ret) return NULL; memset(ret, 0, sizeof(XFILE)); diff --git a/source/libads/ldap.c b/source/libads/ldap.c index d4b363cae..cd551af7f 100644 --- a/source/libads/ldap.c +++ b/source/libads/ldap.c @@ -276,7 +276,7 @@ static struct berval *dup_berval(TALLOC_CTX *ctx, const struct berval *in_val) if (!in_val) return NULL; - value = talloc_zero(ctx, sizeof(struct berval)); + value = talloc_zero_p(ctx, struct berval); if (value == NULL) return NULL; if (in_val->bv_len == 0) return value; @@ -317,7 +317,7 @@ static char **ads_push_strvals(TALLOC_CTX *ctx, const char **in_vals) if (!in_vals) return NULL; for (i=0; in_vals[i]; i++); /* count values */ - values = (char ** ) talloc_zero(ctx, (i+1)*sizeof(char *)); + values = talloc_zero_array_p(ctx, char *, i+1); if (!values) return NULL; for (i=0; in_vals[i]; i++) { @@ -336,7 +336,7 @@ static char **ads_pull_strvals(TALLOC_CTX *ctx, const char **in_vals) if (!in_vals) return NULL; for (i=0; in_vals[i]; i++); /* count values */ - values = (char **) talloc_zero(ctx, (i+1)*sizeof(char *)); + values = talloc_zero_array_p(ctx, char *, i+1); if (!values) return NULL; for (i=0; in_vals[i]; i++) { @@ -758,11 +758,11 @@ ADS_MODLIST ads_init_mods(TALLOC_CTX *ctx) #define ADS_MODLIST_ALLOC_SIZE 10 LDAPMod **mods; - if ((mods = (LDAPMod **) talloc_zero(ctx, sizeof(LDAPMod *) * - (ADS_MODLIST_ALLOC_SIZE + 1)))) + if ((mods = talloc_zero_array_p(ctx, LDAPMod *, ADS_MODLIST_ALLOC_SIZE + 1))) { /* -1 is safety to make sure we don't go over the end. need to reset it to NULL before doing ldap modify */ mods[ADS_MODLIST_ALLOC_SIZE] = (LDAPMod *) -1; + } return mods; } @@ -804,7 +804,7 @@ static ADS_STATUS ads_modlist_add(TALLOC_CTX *ctx, ADS_MODLIST *mods, *mods = modlist; } - if (!(modlist[curmod] = talloc_zero(ctx, sizeof(LDAPMod)))) + if (!(modlist[curmod] = talloc_zero_p(ctx, LDAPMod))) return ADS_ERROR(LDAP_NO_MEMORY); modlist[curmod]->mod_type = talloc_strdup(ctx, name); if (mod_op & LDAP_MOD_BVALUES) { diff --git a/source/libcli/auth/clikrb5.c b/source/libcli/auth/clikrb5.c index 48e1f8850..7ad8dd7b6 100644 --- a/source/libcli/auth/clikrb5.c +++ b/source/libcli/auth/clikrb5.c @@ -212,7 +212,7 @@ return -1; } - sa = malloc( sizeof(struct sockaddr) * num_kdcs ); + sa = malloc_array_p(struct sockaddr, num_kdcs); if (!sa) { DEBUG(0, ("krb5_locate_kdc: malloc failed\n")); krb5_krbhst_free(ctx, hnd); @@ -220,7 +220,7 @@ return -1; } - *addr_pp = malloc(sizeof(struct sockaddr) * num_kdcs); + *addr_pp = malloc_array_p(struct sockaddr, num_kdcs); memset(*addr_pp, '\0', sizeof(struct sockaddr) * num_kdcs ); for (i = 0; i < num_kdcs && (rc = krb5_krbhst_next(ctx, hnd, &hinfo) == 0); i++) { diff --git a/source/libcli/auth/spnego_parse.c b/source/libcli/auth/spnego_parse.c index 825b0a78d..2cf38728a 100644 --- a/source/libcli/auth/spnego_parse.c +++ b/source/libcli/auth/spnego_parse.c @@ -49,7 +49,7 @@ static BOOL read_negTokenInit(struct asn1_data *asn1, struct spnego_negTokenInit asn1_start_tag(asn1, ASN1_CONTEXT(0)); asn1_start_tag(asn1, ASN1_SEQUENCE(0)); - token->mechTypes = talloc(NULL, sizeof(*token->mechTypes)); + token->mechTypes = talloc_p(NULL, const char *); for (i = 0; !asn1->has_error && 0 < asn1_tag_remaining(asn1); i++) { token->mechTypes = diff --git a/source/libcli/ldap/ldap.c b/source/libcli/ldap/ldap.c index dd689027f..076d088ee 100644 --- a/source/libcli/ldap/ldap.c +++ b/source/libcli/ldap/ldap.c @@ -130,7 +130,7 @@ static struct ldap_parse_tree *ldap_parse_simple(TALLOC_CTX *mem_ctx, if (val && strchr("()&|", *val)) return NULL; - ret = talloc(mem_ctx, sizeof(*ret)); + ret = talloc_p(mem_ctx, struct ldap_parse_tree); if (!ret) { errno = ENOMEM; return NULL; @@ -157,8 +157,7 @@ static struct ldap_parse_tree *ldap_parse_filterlist(TALLOC_CTX *mem_ctx, { struct ldap_parse_tree *ret, *next; - ret = talloc(mem_ctx, sizeof(*ret)); - + ret = talloc_p(mem_ctx, struct ldap_parse_tree); if (!ret) { errno = ENOMEM; return NULL; @@ -166,7 +165,7 @@ static struct ldap_parse_tree *ldap_parse_filterlist(TALLOC_CTX *mem_ctx, ret->operation = op; ret->u.list.num_elements = 1; - ret->u.list.elements = talloc(mem_ctx, sizeof(*ret->u.list.elements)); + ret->u.list.elements = talloc_p(mem_ctx, struct ldap_parse_tree *); if (!ret->u.list.elements) { errno = ENOMEM; return NULL; @@ -206,7 +205,7 @@ static struct ldap_parse_tree *ldap_parse_not(TALLOC_CTX *mem_ctx, const char *s { struct ldap_parse_tree *ret; - ret = talloc(mem_ctx, sizeof(*ret)); + ret = talloc_p(mem_ctx, struct ldap_parse_tree); if (!ret) { errno = ENOMEM; return NULL; diff --git a/source/libcli/nmblib.c b/source/libcli/nmblib.c index 70c6fab8d..0a3f72ba7 100644 --- a/source/libcli/nmblib.c +++ b/source/libcli/nmblib.c @@ -333,7 +333,7 @@ static BOOL parse_alloc_res_rec(char *inbuf,int *offset,int length, struct res_rec **recs, int count) { int i; - *recs = (struct res_rec *)malloc(sizeof(**recs)*count); + *recs = malloc_array_p(struct res_rec, count); if (!*recs) return(False); memset((char *)*recs,'\0',sizeof(**recs)*count); @@ -523,7 +523,7 @@ static struct packet_struct *copy_nmb_packet(struct packet_struct *packet) struct nmb_packet *copy_nmb; struct packet_struct *pkt_copy; - if(( pkt_copy = (struct packet_struct *)malloc(sizeof(*packet))) == NULL) + if(( pkt_copy = malloc_p(struct packet_struct)) == NULL) { DEBUG(0,("copy_nmb_packet: malloc fail.\n")); return NULL; diff --git a/source/libcli/raw/raweas.c b/source/libcli/raw/raweas.c index 621181841..027705b38 100644 --- a/source/libcli/raw/raweas.c +++ b/source/libcli/raw/raweas.c @@ -174,7 +174,7 @@ NTSTATUS ea_pull_list(const DATA_BLOB *blob, blob2.data = blob->data + ofs; blob2.length = ea_size - ofs; - *eas = talloc_realloc(mem_ctx, *eas, sizeof(**eas) * (n+1)); + *eas = talloc_realloc_p(mem_ctx, *eas, struct ea_struct, n+1); if (! *eas) return NT_STATUS_NO_MEMORY; len = ea_pull_struct(&blob2, mem_ctx, &(*eas)[n]); @@ -219,7 +219,7 @@ NTSTATUS ea_pull_list_chained(const DATA_BLOB *blob, blob2.data = blob->data + ofs + 4; blob2.length = blob->length - (ofs + 4); - *eas = talloc_realloc(mem_ctx, *eas, sizeof(**eas) * (n+1)); + *eas = talloc_realloc_p(mem_ctx, *eas, struct ea_struct, n+1); if (! *eas) return NT_STATUS_NO_MEMORY; len = ea_pull_struct(&blob2, mem_ctx, &(*eas)[n]); diff --git a/source/libcli/raw/rawnotify.c b/source/libcli/raw/rawnotify.c index ea5fada1e..918fb788c 100644 --- a/source/libcli/raw/rawnotify.c +++ b/source/libcli/raw/rawnotify.c @@ -73,8 +73,7 @@ NTSTATUS smb_raw_changenotify_recv(struct smbcli_request *req, } /* allocate array */ - parms->out.changes = talloc(mem_ctx, sizeof(parms->out.changes[0]) * - parms->out.num_changes); + parms->out.changes = talloc_array_p(mem_ctx, struct notify_changes, parms->out.num_changes); if (!parms->out.changes) { return NT_STATUS_NO_MEMORY; } diff --git a/source/librpc/rpc/dcerpc.c b/source/librpc/rpc/dcerpc.c index 3526c0adf..7cd18d280 100644 --- a/source/librpc/rpc/dcerpc.c +++ b/source/librpc/rpc/dcerpc.c @@ -541,7 +541,7 @@ NTSTATUS dcerpc_bind(struct dcerpc_pipe *p, pkt.u.bind.max_recv_frag = 5840; pkt.u.bind.assoc_group_id = 0; pkt.u.bind.num_contexts = 1; - pkt.u.bind.ctx_list = talloc(mem_ctx, sizeof(pkt.u.bind.ctx_list[0])); + pkt.u.bind.ctx_list = talloc_p(mem_ctx, struct dcerpc_ctx_list); if (!pkt.u.bind.ctx_list) { return NT_STATUS_NO_MEMORY; } @@ -620,7 +620,7 @@ NTSTATUS dcerpc_alter(struct dcerpc_pipe *p, pkt.u.alter.max_recv_frag = 0x2000; pkt.u.alter.assoc_group_id = 0; pkt.u.alter.num_contexts = 1; - pkt.u.alter.ctx_list = talloc(mem_ctx, sizeof(pkt.u.alter.ctx_list[0])); + pkt.u.alter.ctx_list = talloc_p(mem_ctx, struct dcerpc_ctx_list); if (!pkt.u.alter.ctx_list) { return NT_STATUS_NO_MEMORY; } diff --git a/source/ntvfs/cifs/vfs_cifs.c b/source/ntvfs/cifs/vfs_cifs.c index bfba31b46..736aa3652 100644 --- a/source/ntvfs/cifs/vfs_cifs.c +++ b/source/ntvfs/cifs/vfs_cifs.c @@ -121,7 +121,7 @@ static NTSTATUS cvfs_connect(struct ntvfs_module_context *ntvfs, return NT_STATUS_INVALID_PARAMETER; } - private = talloc(req->tcon, sizeof(struct cvfs_private)); + private = talloc_p(req->tcon, struct cvfs_private); if (!private) { return NT_STATUS_NO_MEMORY; } diff --git a/source/param/loadparm.c b/source/param/loadparm.c index 8975f066f..334ec982e 100644 --- a/source/param/loadparm.c +++ b/source/param/loadparm.c @@ -2185,7 +2185,7 @@ static void init_copymap(service * pservice) { int i; SAFE_FREE(pservice->copymap); - pservice->copymap = (BOOL *)malloc(sizeof(BOOL) * NUMPARAMETERS); + pservice->copymap = malloc_array_p(BOOL, NUMPARAMETERS); if (!pservice->copymap) DEBUG(0, ("Couldn't allocate copymap!! (size %d)\n", diff --git a/source/rpc_server/spoolss/dcesrv_spoolss.c b/source/rpc_server/spoolss/dcesrv_spoolss.c index 17c23dcba..25210913f 100644 --- a/source/rpc_server/spoolss/dcesrv_spoolss.c +++ b/source/rpc_server/spoolss/dcesrv_spoolss.c @@ -168,7 +168,7 @@ static WERROR spoolss_EnumPrinters(struct dcesrv_call_state *dce_call, TALLOC_CT goto done; } - r->out.buffer = (DATA_BLOB *)talloc(mem_ctx, sizeof(DATA_BLOB)); + r->out.buffer = talloc_p(mem_ctx, DATA_BLOB); if (!r->out.buffer) { result = WERR_NOMEM; diff --git a/source/smb_server/nttrans.c b/source/smb_server/nttrans.c index 0a268ccbf..31391b88c 100644 --- a/source/smb_server/nttrans.c +++ b/source/smb_server/nttrans.c @@ -383,7 +383,7 @@ void reply_nttrans(struct smbsrv_request *req) } /* parse out the setup words */ - trans.in.setup = talloc(req, trans.in.setup_count * sizeof(uint16_t)); + trans.in.setup = talloc_array_p(req, uint16_t, trans.in.setup_count); if (!trans.in.setup) { req_reply_error(req, NT_STATUS_NO_MEMORY); return; diff --git a/source/smb_server/trans2.c b/source/smb_server/trans2.c index 427583954..8f995e2f6 100644 --- a/source/smb_server/trans2.c +++ b/source/smb_server/trans2.c @@ -1350,7 +1350,7 @@ void reply_trans_generic(struct smbsrv_request *req, uint8_t command) } /* parse out the setup words */ - trans.in.setup = talloc(req, trans.in.setup_count * sizeof(uint16_t)); + trans.in.setup = talloc_array_p(req, uint16_t, trans.in.setup_count); if (trans.in.setup_count && !trans.in.setup) { req_reply_error(req, NT_STATUS_NO_MEMORY); return; diff --git a/source/torture/basic/aliases.c b/source/torture/basic/aliases.c index ba4bf69f1..50aabb825 100644 --- a/source/torture/basic/aliases.c +++ b/source/torture/basic/aliases.c @@ -48,7 +48,7 @@ static void gen_aliases(struct smbcli_state *cli, struct smb_trans2 *t2, int lev status = smb_raw_trans2(cli->tree, mem_ctx, t2); if (!NT_STATUS_IS_OK(status)) continue; - t2b = talloc(mem_ctx, sizeof(*t2b)); + t2b = talloc_p(mem_ctx, struct trans2_blobs); t2b->level = level; t2b->params = t2->out.params; t2b->data = t2->out.data; @@ -278,7 +278,7 @@ static void gen_set_aliases(struct smbcli_state *cli, struct smb_trans2 *t2, int if (!NT_STATUS_IS_OK(status) && !NT_STATUS_EQUAL(status, NT_STATUS_INVALID_PARAMETER)) continue; - t2b = talloc(mem_ctx, sizeof(*t2b)); + t2b = talloc_p(mem_ctx, struct trans2_blobs); t2b->level = level; t2b->params = t2->out.params; t2b->data = t2->out.data; diff --git a/source/torture/nbench/nbio.c b/source/torture/nbench/nbio.c index 34de81c5b..32bd10844 100644 --- a/source/torture/nbench/nbio.c +++ b/source/torture/nbench/nbio.c @@ -281,7 +281,7 @@ void nb_createx(const char *fname, if (!NT_STATUS_IS_OK(ret)) return; - f = malloc(sizeof(struct ftable)); + f = malloc_p(struct ftable); f->handle = handle; f->fd = io.ntcreatex.out.fnum; diff --git a/source/torture/raw/mkdir.c b/source/torture/raw/mkdir.c index 2d7fa678e..539258946 100644 --- a/source/torture/raw/mkdir.c +++ b/source/torture/raw/mkdir.c @@ -101,7 +101,7 @@ static BOOL test_mkdir(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) /* with EAs */ md.t2mkdir.in.num_eas = 1; - md.t2mkdir.in.eas = talloc(mem_ctx, sizeof(md.t2mkdir.in.eas[0])); + md.t2mkdir.in.eas = talloc_p(mem_ctx, struct ea_struct); md.t2mkdir.in.eas[0].flags = 0; md.t2mkdir.in.eas[0].name.s = "EAONE"; md.t2mkdir.in.eas[0].value = data_blob_talloc(mem_ctx, "1", 1); diff --git a/source/torture/raw/open.c b/source/torture/raw/open.c index fb50ec6c4..fe0d4fe4f 100644 --- a/source/torture/raw/open.c +++ b/source/torture/raw/open.c @@ -499,7 +499,7 @@ static BOOL test_t2open(struct smbcli_state *cli, TALLOC_CTX *mem_ctx) io.t2open.in.size = 0; io.t2open.in.timeout = 0; - io.t2open.in.eas = talloc(mem_ctx, sizeof(io.t2open.in.eas[0])); + io.t2open.in.eas = talloc_p(mem_ctx, struct ea_struct); io.t2open.in.num_eas = 1; io.t2open.in.eas[0].flags = 0; io.t2open.in.eas[0].name.s = "EAONE"; diff --git a/source/utils/setntacl.c b/source/utils/setntacl.c index cd9f262e1..0535c3037 100644 --- a/source/utils/setntacl.c +++ b/source/utils/setntacl.c @@ -75,7 +75,7 @@ static void setntacl(char *filename, struct security_descriptor *sd) fgets(line, sizeof(line), stdin); sd->group_sid = dom_sid_parse_talloc(mem_ctx, line); - acl = talloc(mem_ctx, sizeof(struct security_acl)); + acl = talloc_p(mem_ctx, struct security_acl); acl->revision = 2; acl->size = 0; -- 2.34.1