r4058: added a type safe version of smb_xmalloc()
authorAndrew Tridgell <tridge@samba.org>
Sat, 4 Dec 2004 09:30:38 +0000 (09:30 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:06:20 +0000 (13:06 -0500)
source/include/includes.h
source/lib/registry/tools/regpatch.c
source/lib/util_pw.c
source/libads/ads_struct.c
source/param/loadparm.c
source/rpc_server/echo/rpc_echo.c

index 6335780b8910df2f193ddf1b87d84140c478ded5..ad24ff676d5074b697a9aff67636922af6b35c78 100644 (file)
@@ -321,3 +321,8 @@ int asprintf(char **,const char *, ...) PRINTF_ATTRIBUTE(2,3);
 
 #endif /* _INCLUDES_H */
 
+/*
+  type safe varient of smb_xmalloc()
+*/
+#define smb_xmalloc_p(type) (type *)smb_xmalloc(sizeof(type))
+
index a8b2f83ee1417ba6fb3f2eb69ab3a8fe86a55410..9b37b7952b6b71eab11f2335652d450a85723404 100644 (file)
@@ -154,7 +154,7 @@ static void print_line(struct cmd_line *cl)
  */
 static struct cmd_line *get_cmd_line(int fd)
 {
-  struct cmd_line *cl = (CMD_LINE *)smb_xmalloc(sizeof(CMD_LINE));
+  struct cmd_line *cl = smb_xmalloc_p(CMD_LINE);
   int i = 0, rc;
   uint8_t ch;
 
@@ -445,7 +445,7 @@ static CMD *regedit4_get_cmd(int fd)
   struct cmd_line *cl = NULL;
   struct val_spec_list *vl = NULL;
 
-  cmd = (struct command_s *)smb_xmalloc(sizeof(struct command_s));
+  cmd = smb_xmalloc_p(struct command_s);
 
   cmd->cmd = CMD_NONE;
   cmd->key = NULL;
@@ -488,7 +488,7 @@ static CMD *regedit4_get_cmd(int fd)
         * There could be a \ on the end which we need to 
         * handle at some time
         */
-       vl = (struct val_spec_list *)smb_xmalloc(sizeof(struct val_spec_list));
+       vl = smb_xmalloc_p(struct val_spec_list);
        vl->next = NULL;
        vl->val = NULL;
        vl->name = parse_value(cl, &vl->type, &vl->val);
@@ -607,7 +607,7 @@ static CMD_FILE *cmd_file_create(const char *file)
     return NULL;
   }
 
-  tmp = (CMD_FILE *)smb_xmalloc(sizeof(CMD_FILE)); 
+  tmp = smb_xmalloc_p(CMD_FILE); 
 
   /*
    * Let's fill in some of the fields;
index 9d075a05e885bfc080f7257c3298a2cbcdbd8d5c..19893e396f96a0766a5bff2fa0bc084e153f8654 100644 (file)
@@ -24,7 +24,7 @@
 
 static struct passwd *alloc_copy_passwd(const struct passwd *from) 
 {
-       struct passwd *ret = smb_xmalloc(sizeof(struct passwd));
+       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);
index 9774968e1214998f2294844a17a514b856b12dc9..a6c679e002cee8fa3912e813cebb7ae5ea518258 100644 (file)
@@ -87,7 +87,7 @@ ADS_STRUCT *ads_init(const char *realm,
 {
        ADS_STRUCT *ads;
        
-       ads = (ADS_STRUCT *)smb_xmalloc(sizeof(*ads));
+       ads = smb_xmalloc_p(ADS_STRUCT);
        ZERO_STRUCTP(ads);
        
        ads->server.realm = realm? strdup(realm) : NULL;
index 334ec982e0842251d5eab2cfbd1824dbc8c5d543..035ac3422a89a7952c98c9a291c5c312b61c242b 100644 (file)
@@ -1576,8 +1576,7 @@ static int add_a_service(const service *pservice, const char *name)
                }
                else {
                        ServicePtrs = tsp;
-                       ServicePtrs[iNumServices] =
-                               (service *) malloc(sizeof(service));
+                       ServicePtrs[iNumServices] = malloc_p(service);
                }
                if (!ServicePtrs[iNumServices]) {
                        DEBUG(0,("add_a_service: out of memory!\n"));
@@ -1871,7 +1870,7 @@ static void copy_service(service * pserviceDest, service * pserviceSource, BOOL
                        pdata = pdata->next;
                }
                if (not_added) {
-                       paramo = smb_xmalloc(sizeof(*paramo));
+                       paramo = smb_xmalloc_p(struct param_opt);
                        paramo->key = strdup(data->key);
                        paramo->value = strdup(data->value);
                        DLIST_ADD(pserviceDest->param_opt, paramo);
@@ -1940,7 +1939,7 @@ static void add_to_file_list(const char *fname, const char *subfname)
        }
 
        if (!f) {
-               f = (struct file_lists *)malloc(sizeof(file_lists[0]));
+               f = malloc_p(struct file_lists);
                if (!f)
                        return;
                f->next = file_lists;
@@ -2247,7 +2246,7 @@ static BOOL lp_do_parameter_parametric(int snum, const char *pszParmName, const
                }
        }
 
-       paramo = smb_xmalloc(sizeof(*paramo));
+       paramo = smb_xmalloc_p(struct param_opt);
        paramo->key = strdup(name);
        paramo->value = strdup(pszParmValue);
        paramo->flags = flags;
index 6e8b94c61098523f6b928abd5424ba4d8b4a6f4b..f86ae6debf601d22977a270555380f58401f22f9 100644 (file)
@@ -70,7 +70,7 @@ static NTSTATUS echo_TestCall(struct dcesrv_call_state *dce_call, TALLOC_CTX *me
 
 static NTSTATUS echo_TestCall2(struct dcesrv_call_state *dce_call, TALLOC_CTX *mem_ctx, struct echo_TestCall2 *r)
 {
-       r->out.info = talloc(mem_ctx, sizeof(*r->out.info));
+       r->out.info = talloc_p(mem_ctx, union echo_Info);
        if (!r->out.info) {
                return NT_STATUS_NO_MEMORY;
        }