From d0bdef850e7bf0edc1a8ee1f05880cdf867aeeb6 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Thu, 2 Jul 2009 15:25:58 +0200 Subject: [PATCH] prefer sizeof *VAR over sizeof TYPE (no semantic change) * src/generator.ml: Slightly safer, in case the declared type ever changes. --- src/generator.ml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/generator.ml b/src/generator.ml index ed5810b..4b7efa0 100755 --- a/src/generator.ml +++ b/src/generator.ml @@ -8228,16 +8228,16 @@ print_strings (char * const* const argv) pr " return strs;\n" | RIntBool _ -> pr " struct guestfs_int_bool *r;\n"; - pr " r = malloc (sizeof (struct guestfs_int_bool));\n"; + pr " r = malloc (sizeof *r);\n"; pr " sscanf (val, \"%%\" SCNi32, &r->i);\n"; pr " r->b = 0;\n"; pr " return r;\n" | RPVList _ -> pr " struct guestfs_lvm_pv_list *r;\n"; pr " int i;\n"; - pr " r = malloc (sizeof (struct guestfs_lvm_pv_list));\n"; + pr " r = malloc (sizeof *r);\n"; pr " sscanf (val, \"%%d\", &r->len);\n"; - pr " r->val = calloc (r->len, sizeof (struct guestfs_lvm_pv));\n"; + pr " r->val = calloc (r->len, sizeof *r->val);\n"; pr " for (i = 0; i < r->len; ++i) {\n"; pr " r->val[i].pv_name = malloc (16);\n"; pr " snprintf (r->val[i].pv_name, 16, \"%%d\", i);\n"; @@ -8246,9 +8246,9 @@ print_strings (char * const* const argv) | RVGList _ -> pr " struct guestfs_lvm_vg_list *r;\n"; pr " int i;\n"; - pr " r = malloc (sizeof (struct guestfs_lvm_vg_list));\n"; + pr " r = malloc (sizeof *r);\n"; pr " sscanf (val, \"%%d\", &r->len);\n"; - pr " r->val = calloc (r->len, sizeof (struct guestfs_lvm_vg));\n"; + pr " r->val = calloc (r->len, sizeof *r->val);\n"; pr " for (i = 0; i < r->len; ++i) {\n"; pr " r->val[i].vg_name = malloc (16);\n"; pr " snprintf (r->val[i].vg_name, 16, \"%%d\", i);\n"; @@ -8257,9 +8257,9 @@ print_strings (char * const* const argv) | RLVList _ -> pr " struct guestfs_lvm_lv_list *r;\n"; pr " int i;\n"; - pr " r = malloc (sizeof (struct guestfs_lvm_lv_list));\n"; + pr " r = malloc (sizeof *r);\n"; pr " sscanf (val, \"%%d\", &r->len);\n"; - pr " r->val = calloc (r->len, sizeof (struct guestfs_lvm_lv));\n"; + pr " r->val = calloc (r->len, sizeof *r->val);\n"; pr " for (i = 0; i < r->len; ++i) {\n"; pr " r->val[i].lv_name = malloc (16);\n"; pr " snprintf (r->val[i].lv_name, 16, \"%%d\", i);\n"; @@ -8279,7 +8279,7 @@ print_strings (char * const* const argv) pr " char **strs;\n"; pr " int n, i;\n"; pr " sscanf (val, \"%%d\", &n);\n"; - pr " strs = malloc ((n*2+1) * sizeof (char *));\n"; + pr " strs = malloc ((n*2+1) * sizeof (*strs));\n"; pr " for (i = 0; i < n; ++i) {\n"; pr " strs[i*2] = malloc (16);\n"; pr " strs[i*2+1] = malloc (16);\n"; @@ -8291,9 +8291,9 @@ print_strings (char * const* const argv) | RDirentList _ -> pr " struct guestfs_dirent_list *r;\n"; pr " int i;\n"; - pr " r = malloc (sizeof (struct guestfs_dirent_list));\n"; + pr " r = malloc (sizeof *r);\n"; pr " sscanf (val, \"%%d\", &r->len);\n"; - pr " r->val = calloc (r->len, sizeof (struct guestfs_dirent));\n"; + pr " r->val = calloc (r->len, sizeof *r->val);\n"; pr " for (i = 0; i < r->len; ++i)\n"; pr " r->val[i].ino = i;\n"; pr " return r;\n" -- 1.8.3.1