diff options
Diffstat (limited to 'meta/recipes-bsp/grub/files/0003-calloc-Use-calloc-at-most-places.patch')
-rw-r--r-- | meta/recipes-bsp/grub/files/0003-calloc-Use-calloc-at-most-places.patch | 1859 |
1 files changed, 1859 insertions, 0 deletions
diff --git a/meta/recipes-bsp/grub/files/0003-calloc-Use-calloc-at-most-places.patch b/meta/recipes-bsp/grub/files/0003-calloc-Use-calloc-at-most-places.patch new file mode 100644 index 0000000000..eb3e42c3af --- /dev/null +++ b/meta/recipes-bsp/grub/files/0003-calloc-Use-calloc-at-most-places.patch | |||
@@ -0,0 +1,1859 @@ | |||
1 | From bcdd6a55952222ec9829a59348240a4f983b0b56 Mon Sep 17 00:00:00 2001 | ||
2 | From: Peter Jones <pjones@redhat.com> | ||
3 | Date: Mon, 15 Jun 2020 12:26:01 -0400 | ||
4 | Subject: [PATCH 4/9] calloc: Use calloc() at most places | ||
5 | |||
6 | This modifies most of the places we do some form of: | ||
7 | |||
8 | X = malloc(Y * Z); | ||
9 | |||
10 | to use calloc(Y, Z) instead. | ||
11 | |||
12 | Among other issues, this fixes: | ||
13 | - allocation of integer overflow in grub_png_decode_image_header() | ||
14 | reported by Chris Coulson, | ||
15 | - allocation of integer overflow in luks_recover_key() | ||
16 | reported by Chris Coulson, | ||
17 | - allocation of integer overflow in grub_lvm_detect() | ||
18 | reported by Chris Coulson. | ||
19 | |||
20 | Fixes: CVE-2020-14308 | ||
21 | |||
22 | Upstream-Status: Backport [commit f725fa7cb2ece547c5af01eeeecfe8d95802ed41 | ||
23 | from https://git.savannah.gnu.org/git/grub.git] | ||
24 | |||
25 | Signed-off-by: Peter Jones <pjones@redhat.com> | ||
26 | Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com> | ||
27 | [YL: don't patch on grub-core/lib/json/json.c, which is not existing in grub 2.04] | ||
28 | Signed-off-by: Yongxin Liu <yongxin.liu@windriver.com> | ||
29 | --- | ||
30 | grub-core/bus/usb/usbhub.c | 8 ++++---- | ||
31 | grub-core/commands/efi/lsefisystab.c | 3 ++- | ||
32 | grub-core/commands/legacycfg.c | 6 +++--- | ||
33 | grub-core/commands/menuentry.c | 2 +- | ||
34 | grub-core/commands/nativedisk.c | 2 +- | ||
35 | grub-core/commands/parttool.c | 12 +++++++++--- | ||
36 | grub-core/commands/regexp.c | 2 +- | ||
37 | grub-core/commands/search_wrap.c | 2 +- | ||
38 | grub-core/disk/diskfilter.c | 4 ++-- | ||
39 | grub-core/disk/ieee1275/ofdisk.c | 2 +- | ||
40 | grub-core/disk/ldm.c | 14 +++++++------- | ||
41 | grub-core/disk/luks.c | 2 +- | ||
42 | grub-core/disk/lvm.c | 12 ++++++------ | ||
43 | grub-core/disk/xen/xendisk.c | 2 +- | ||
44 | grub-core/efiemu/loadcore.c | 2 +- | ||
45 | grub-core/efiemu/mm.c | 6 +++--- | ||
46 | grub-core/font/font.c | 3 +-- | ||
47 | grub-core/fs/affs.c | 6 +++--- | ||
48 | grub-core/fs/btrfs.c | 6 +++--- | ||
49 | grub-core/fs/hfs.c | 2 +- | ||
50 | grub-core/fs/hfsplus.c | 6 +++--- | ||
51 | grub-core/fs/iso9660.c | 2 +- | ||
52 | grub-core/fs/ntfs.c | 4 ++-- | ||
53 | grub-core/fs/sfs.c | 2 +- | ||
54 | grub-core/fs/tar.c | 2 +- | ||
55 | grub-core/fs/udf.c | 4 ++-- | ||
56 | grub-core/fs/zfs/zfs.c | 4 ++-- | ||
57 | grub-core/gfxmenu/gui_string_util.c | 2 +- | ||
58 | grub-core/gfxmenu/widget-box.c | 4 ++-- | ||
59 | grub-core/io/gzio.c | 2 +- | ||
60 | grub-core/kern/efi/efi.c | 6 +++--- | ||
61 | grub-core/kern/emu/hostdisk.c | 2 +- | ||
62 | grub-core/kern/fs.c | 2 +- | ||
63 | grub-core/kern/misc.c | 2 +- | ||
64 | grub-core/kern/parser.c | 2 +- | ||
65 | grub-core/kern/uboot/uboot.c | 2 +- | ||
66 | grub-core/lib/libgcrypt/cipher/ac.c | 8 ++++---- | ||
67 | grub-core/lib/libgcrypt/cipher/primegen.c | 4 ++-- | ||
68 | grub-core/lib/libgcrypt/cipher/pubkey.c | 4 ++-- | ||
69 | grub-core/lib/priority_queue.c | 2 +- | ||
70 | grub-core/lib/reed_solomon.c | 7 +++---- | ||
71 | grub-core/lib/relocator.c | 10 +++++----- | ||
72 | grub-core/lib/zstd/fse_decompress.c | 2 +- | ||
73 | grub-core/loader/arm/linux.c | 2 +- | ||
74 | grub-core/loader/efi/chainloader.c | 2 +- | ||
75 | grub-core/loader/i386/bsdXX.c | 2 +- | ||
76 | grub-core/loader/i386/xnu.c | 4 ++-- | ||
77 | grub-core/loader/macho.c | 2 +- | ||
78 | grub-core/loader/multiboot_elfxx.c | 2 +- | ||
79 | grub-core/loader/xnu.c | 2 +- | ||
80 | grub-core/mmap/mmap.c | 4 ++-- | ||
81 | grub-core/net/bootp.c | 2 +- | ||
82 | grub-core/net/dns.c | 10 +++++----- | ||
83 | grub-core/net/net.c | 4 ++-- | ||
84 | grub-core/normal/charset.c | 10 +++++----- | ||
85 | grub-core/normal/cmdline.c | 14 +++++++------- | ||
86 | grub-core/normal/menu_entry.c | 14 +++++++------- | ||
87 | grub-core/normal/menu_text.c | 4 ++-- | ||
88 | grub-core/normal/term.c | 4 ++-- | ||
89 | grub-core/osdep/linux/getroot.c | 6 +++--- | ||
90 | grub-core/osdep/unix/config.c | 2 +- | ||
91 | grub-core/osdep/windows/getroot.c | 2 +- | ||
92 | grub-core/osdep/windows/hostdisk.c | 4 ++-- | ||
93 | grub-core/osdep/windows/init.c | 2 +- | ||
94 | grub-core/osdep/windows/platform.c | 4 ++-- | ||
95 | grub-core/osdep/windows/relpath.c | 2 +- | ||
96 | grub-core/partmap/gpt.c | 2 +- | ||
97 | grub-core/partmap/msdos.c | 2 +- | ||
98 | grub-core/script/execute.c | 2 +- | ||
99 | grub-core/tests/fake_input.c | 2 +- | ||
100 | grub-core/tests/video_checksum.c | 6 +++--- | ||
101 | grub-core/video/capture.c | 2 +- | ||
102 | grub-core/video/emu/sdl.c | 2 +- | ||
103 | grub-core/video/i386/pc/vga.c | 2 +- | ||
104 | grub-core/video/readers/png.c | 2 +- | ||
105 | include/grub/unicode.h | 4 ++-- | ||
106 | util/getroot.c | 2 +- | ||
107 | util/grub-file.c | 2 +- | ||
108 | util/grub-fstest.c | 4 ++-- | ||
109 | util/grub-install-common.c | 2 +- | ||
110 | util/grub-install.c | 4 ++-- | ||
111 | util/grub-mkimagexx.c | 6 ++---- | ||
112 | util/grub-mkrescue.c | 4 ++-- | ||
113 | util/grub-mkstandalone.c | 2 +- | ||
114 | util/grub-pe2elf.c | 12 +++++------- | ||
115 | util/grub-probe.c | 4 ++-- | ||
116 | 86 files changed, 178 insertions(+), 177 deletions(-) | ||
117 | |||
118 | diff --git a/grub-core/bus/usb/usbhub.c b/grub-core/bus/usb/usbhub.c | ||
119 | index 34a7ff1..a06cce3 100644 | ||
120 | --- a/grub-core/bus/usb/usbhub.c | ||
121 | +++ b/grub-core/bus/usb/usbhub.c | ||
122 | @@ -149,8 +149,8 @@ grub_usb_add_hub (grub_usb_device_t dev) | ||
123 | grub_usb_set_configuration (dev, 1); | ||
124 | |||
125 | dev->nports = hubdesc.portcnt; | ||
126 | - dev->children = grub_zalloc (hubdesc.portcnt * sizeof (dev->children[0])); | ||
127 | - dev->ports = grub_zalloc (dev->nports * sizeof (dev->ports[0])); | ||
128 | + dev->children = grub_calloc (hubdesc.portcnt, sizeof (dev->children[0])); | ||
129 | + dev->ports = grub_calloc (dev->nports, sizeof (dev->ports[0])); | ||
130 | if (!dev->children || !dev->ports) | ||
131 | { | ||
132 | grub_free (dev->children); | ||
133 | @@ -268,8 +268,8 @@ grub_usb_controller_dev_register_iter (grub_usb_controller_t controller, void *d | ||
134 | |||
135 | /* Query the number of ports the root Hub has. */ | ||
136 | hub->nports = controller->dev->hubports (controller); | ||
137 | - hub->devices = grub_zalloc (sizeof (hub->devices[0]) * hub->nports); | ||
138 | - hub->ports = grub_zalloc (sizeof (hub->ports[0]) * hub->nports); | ||
139 | + hub->devices = grub_calloc (hub->nports, sizeof (hub->devices[0])); | ||
140 | + hub->ports = grub_calloc (hub->nports, sizeof (hub->ports[0])); | ||
141 | if (!hub->devices || !hub->ports) | ||
142 | { | ||
143 | grub_free (hub->devices); | ||
144 | diff --git a/grub-core/commands/efi/lsefisystab.c b/grub-core/commands/efi/lsefisystab.c | ||
145 | index df10302..cd81507 100644 | ||
146 | --- a/grub-core/commands/efi/lsefisystab.c | ||
147 | +++ b/grub-core/commands/efi/lsefisystab.c | ||
148 | @@ -71,7 +71,8 @@ grub_cmd_lsefisystab (struct grub_command *cmd __attribute__ ((unused)), | ||
149 | grub_printf ("Vendor: "); | ||
150 | |||
151 | for (vendor_utf16 = st->firmware_vendor; *vendor_utf16; vendor_utf16++); | ||
152 | - vendor = grub_malloc (4 * (vendor_utf16 - st->firmware_vendor) + 1); | ||
153 | + /* Allocate extra 3 bytes to simplify math. */ | ||
154 | + vendor = grub_calloc (4, vendor_utf16 - st->firmware_vendor + 1); | ||
155 | if (!vendor) | ||
156 | return grub_errno; | ||
157 | *grub_utf16_to_utf8 ((grub_uint8_t *) vendor, st->firmware_vendor, | ||
158 | diff --git a/grub-core/commands/legacycfg.c b/grub-core/commands/legacycfg.c | ||
159 | index db7a8f0..5e3ec0d 100644 | ||
160 | --- a/grub-core/commands/legacycfg.c | ||
161 | +++ b/grub-core/commands/legacycfg.c | ||
162 | @@ -314,7 +314,7 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)), | ||
163 | if (argc < 2) | ||
164 | return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("filename expected")); | ||
165 | |||
166 | - cutargs = grub_malloc (sizeof (cutargs[0]) * (argc - 1)); | ||
167 | + cutargs = grub_calloc (argc - 1, sizeof (cutargs[0])); | ||
168 | if (!cutargs) | ||
169 | return grub_errno; | ||
170 | cutargc = argc - 1; | ||
171 | @@ -436,7 +436,7 @@ grub_cmd_legacy_kernel (struct grub_command *mycmd __attribute__ ((unused)), | ||
172 | { | ||
173 | char rbuf[3] = "-r"; | ||
174 | bsdargc = cutargc + 2; | ||
175 | - bsdargs = grub_malloc (sizeof (bsdargs[0]) * bsdargc); | ||
176 | + bsdargs = grub_calloc (bsdargc, sizeof (bsdargs[0])); | ||
177 | if (!bsdargs) | ||
178 | { | ||
179 | err = grub_errno; | ||
180 | @@ -559,7 +559,7 @@ grub_cmd_legacy_initrdnounzip (struct grub_command *mycmd __attribute__ ((unused | ||
181 | return grub_error (GRUB_ERR_BAD_ARGUMENT, N_("can't find command `%s'"), | ||
182 | "module"); | ||
183 | |||
184 | - newargs = grub_malloc ((argc + 1) * sizeof (newargs[0])); | ||
185 | + newargs = grub_calloc (argc + 1, sizeof (newargs[0])); | ||
186 | if (!newargs) | ||
187 | return grub_errno; | ||
188 | grub_memcpy (newargs + 1, args, argc * sizeof (newargs[0])); | ||
189 | diff --git a/grub-core/commands/menuentry.c b/grub-core/commands/menuentry.c | ||
190 | index 2c5363d..9164df7 100644 | ||
191 | --- a/grub-core/commands/menuentry.c | ||
192 | +++ b/grub-core/commands/menuentry.c | ||
193 | @@ -154,7 +154,7 @@ grub_normal_add_menu_entry (int argc, const char **args, | ||
194 | goto fail; | ||
195 | |||
196 | /* Save argc, args to pass as parameters to block arg later. */ | ||
197 | - menu_args = grub_malloc (sizeof (char*) * (argc + 1)); | ||
198 | + menu_args = grub_calloc (argc + 1, sizeof (char *)); | ||
199 | if (! menu_args) | ||
200 | goto fail; | ||
201 | |||
202 | diff --git a/grub-core/commands/nativedisk.c b/grub-core/commands/nativedisk.c | ||
203 | index 699447d..7c8f97f 100644 | ||
204 | --- a/grub-core/commands/nativedisk.c | ||
205 | +++ b/grub-core/commands/nativedisk.c | ||
206 | @@ -195,7 +195,7 @@ grub_cmd_nativedisk (grub_command_t cmd __attribute__ ((unused)), | ||
207 | else | ||
208 | path_prefix = prefix; | ||
209 | |||
210 | - mods = grub_malloc (argc * sizeof (mods[0])); | ||
211 | + mods = grub_calloc (argc, sizeof (mods[0])); | ||
212 | if (!mods) | ||
213 | return grub_errno; | ||
214 | |||
215 | diff --git a/grub-core/commands/parttool.c b/grub-core/commands/parttool.c | ||
216 | index 22b46b1..051e313 100644 | ||
217 | --- a/grub-core/commands/parttool.c | ||
218 | +++ b/grub-core/commands/parttool.c | ||
219 | @@ -59,7 +59,13 @@ grub_parttool_register(const char *part_name, | ||
220 | for (nargs = 0; args[nargs].name != 0; nargs++); | ||
221 | cur->nargs = nargs; | ||
222 | cur->args = (struct grub_parttool_argdesc *) | ||
223 | - grub_malloc ((nargs + 1) * sizeof (struct grub_parttool_argdesc)); | ||
224 | + grub_calloc (nargs + 1, sizeof (struct grub_parttool_argdesc)); | ||
225 | + if (!cur->args) | ||
226 | + { | ||
227 | + grub_free (cur); | ||
228 | + curhandle--; | ||
229 | + return -1; | ||
230 | + } | ||
231 | grub_memcpy (cur->args, args, | ||
232 | (nargs + 1) * sizeof (struct grub_parttool_argdesc)); | ||
233 | |||
234 | @@ -257,7 +263,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)), | ||
235 | return err; | ||
236 | } | ||
237 | |||
238 | - parsed = (int *) grub_zalloc (argc * sizeof (int)); | ||
239 | + parsed = (int *) grub_calloc (argc, sizeof (int)); | ||
240 | |||
241 | for (i = 1; i < argc; i++) | ||
242 | if (! parsed[i]) | ||
243 | @@ -290,7 +296,7 @@ grub_cmd_parttool (grub_command_t cmd __attribute__ ((unused)), | ||
244 | } | ||
245 | ptool = cur; | ||
246 | pargs = (struct grub_parttool_args *) | ||
247 | - grub_zalloc (ptool->nargs * sizeof (struct grub_parttool_args)); | ||
248 | + grub_calloc (ptool->nargs, sizeof (struct grub_parttool_args)); | ||
249 | for (j = i; j < argc; j++) | ||
250 | if (! parsed[j]) | ||
251 | { | ||
252 | diff --git a/grub-core/commands/regexp.c b/grub-core/commands/regexp.c | ||
253 | index f00b184..4019164 100644 | ||
254 | --- a/grub-core/commands/regexp.c | ||
255 | +++ b/grub-core/commands/regexp.c | ||
256 | @@ -116,7 +116,7 @@ grub_cmd_regexp (grub_extcmd_context_t ctxt, int argc, char **args) | ||
257 | if (ret) | ||
258 | goto fail; | ||
259 | |||
260 | - matches = grub_zalloc (sizeof (*matches) * (regex.re_nsub + 1)); | ||
261 | + matches = grub_calloc (regex.re_nsub + 1, sizeof (*matches)); | ||
262 | if (! matches) | ||
263 | goto fail; | ||
264 | |||
265 | diff --git a/grub-core/commands/search_wrap.c b/grub-core/commands/search_wrap.c | ||
266 | index d7fd26b..47fc8eb 100644 | ||
267 | --- a/grub-core/commands/search_wrap.c | ||
268 | +++ b/grub-core/commands/search_wrap.c | ||
269 | @@ -122,7 +122,7 @@ grub_cmd_search (grub_extcmd_context_t ctxt, int argc, char **args) | ||
270 | for (i = 0; state[SEARCH_HINT_BAREMETAL].args[i]; i++) | ||
271 | nhints++; | ||
272 | |||
273 | - hints = grub_malloc (sizeof (hints[0]) * nhints); | ||
274 | + hints = grub_calloc (nhints, sizeof (hints[0])); | ||
275 | if (!hints) | ||
276 | return grub_errno; | ||
277 | j = 0; | ||
278 | diff --git a/grub-core/disk/diskfilter.c b/grub-core/disk/diskfilter.c | ||
279 | index c3b578a..68ca9e0 100644 | ||
280 | --- a/grub-core/disk/diskfilter.c | ||
281 | +++ b/grub-core/disk/diskfilter.c | ||
282 | @@ -1134,7 +1134,7 @@ grub_diskfilter_make_raid (grub_size_t uuidlen, char *uuid, int nmemb, | ||
283 | array->lvs->segments->node_count = nmemb; | ||
284 | array->lvs->segments->raid_member_size = disk_size; | ||
285 | array->lvs->segments->nodes | ||
286 | - = grub_zalloc (nmemb * sizeof (array->lvs->segments->nodes[0])); | ||
287 | + = grub_calloc (nmemb, sizeof (array->lvs->segments->nodes[0])); | ||
288 | array->lvs->segments->stripe_size = stripe_size; | ||
289 | for (i = 0; i < nmemb; i++) | ||
290 | { | ||
291 | @@ -1226,7 +1226,7 @@ insert_array (grub_disk_t disk, const struct grub_diskfilter_pv_id *id, | ||
292 | grub_partition_t p; | ||
293 | for (p = disk->partition; p; p = p->parent) | ||
294 | s++; | ||
295 | - pv->partmaps = xmalloc (s * sizeof (pv->partmaps[0])); | ||
296 | + pv->partmaps = xcalloc (s, sizeof (pv->partmaps[0])); | ||
297 | s = 0; | ||
298 | for (p = disk->partition; p; p = p->parent) | ||
299 | pv->partmaps[s++] = xstrdup (p->partmap->name); | ||
300 | diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c | ||
301 | index f73257e..03674cb 100644 | ||
302 | --- a/grub-core/disk/ieee1275/ofdisk.c | ||
303 | +++ b/grub-core/disk/ieee1275/ofdisk.c | ||
304 | @@ -297,7 +297,7 @@ dev_iterate (const struct grub_ieee1275_devalias *alias) | ||
305 | /* Power machines documentation specify 672 as maximum SAS disks in | ||
306 | one system. Using a slightly larger value to be safe. */ | ||
307 | table_size = 768; | ||
308 | - table = grub_malloc (table_size * sizeof (grub_uint64_t)); | ||
309 | + table = grub_calloc (table_size, sizeof (grub_uint64_t)); | ||
310 | |||
311 | if (!table) | ||
312 | { | ||
313 | diff --git a/grub-core/disk/ldm.c b/grub-core/disk/ldm.c | ||
314 | index 2a22d2d..e632370 100644 | ||
315 | --- a/grub-core/disk/ldm.c | ||
316 | +++ b/grub-core/disk/ldm.c | ||
317 | @@ -323,8 +323,8 @@ make_vg (grub_disk_t disk, | ||
318 | lv->segments->type = GRUB_DISKFILTER_MIRROR; | ||
319 | lv->segments->node_count = 0; | ||
320 | lv->segments->node_alloc = 8; | ||
321 | - lv->segments->nodes = grub_zalloc (sizeof (*lv->segments->nodes) | ||
322 | - * lv->segments->node_alloc); | ||
323 | + lv->segments->nodes = grub_calloc (lv->segments->node_alloc, | ||
324 | + sizeof (*lv->segments->nodes)); | ||
325 | if (!lv->segments->nodes) | ||
326 | goto fail2; | ||
327 | ptr = vblk[i].dynamic; | ||
328 | @@ -543,8 +543,8 @@ make_vg (grub_disk_t disk, | ||
329 | { | ||
330 | comp->segment_alloc = 8; | ||
331 | comp->segment_count = 0; | ||
332 | - comp->segments = grub_malloc (sizeof (*comp->segments) | ||
333 | - * comp->segment_alloc); | ||
334 | + comp->segments = grub_calloc (comp->segment_alloc, | ||
335 | + sizeof (*comp->segments)); | ||
336 | if (!comp->segments) | ||
337 | goto fail2; | ||
338 | } | ||
339 | @@ -590,8 +590,8 @@ make_vg (grub_disk_t disk, | ||
340 | } | ||
341 | comp->segments->node_count = read_int (ptr + 1, *ptr); | ||
342 | comp->segments->node_alloc = comp->segments->node_count; | ||
343 | - comp->segments->nodes = grub_zalloc (sizeof (*comp->segments->nodes) | ||
344 | - * comp->segments->node_alloc); | ||
345 | + comp->segments->nodes = grub_calloc (comp->segments->node_alloc, | ||
346 | + sizeof (*comp->segments->nodes)); | ||
347 | if (!lv->segments->nodes) | ||
348 | goto fail2; | ||
349 | } | ||
350 | @@ -1017,7 +1017,7 @@ grub_util_ldm_embed (struct grub_disk *disk, unsigned int *nsectors, | ||
351 | *nsectors = lv->size; | ||
352 | if (*nsectors > max_nsectors) | ||
353 | *nsectors = max_nsectors; | ||
354 | - *sectors = grub_malloc (*nsectors * sizeof (**sectors)); | ||
355 | + *sectors = grub_calloc (*nsectors, sizeof (**sectors)); | ||
356 | if (!*sectors) | ||
357 | return grub_errno; | ||
358 | for (i = 0; i < *nsectors; i++) | ||
359 | diff --git a/grub-core/disk/luks.c b/grub-core/disk/luks.c | ||
360 | index 86c50c6..18b3a8b 100644 | ||
361 | --- a/grub-core/disk/luks.c | ||
362 | +++ b/grub-core/disk/luks.c | ||
363 | @@ -336,7 +336,7 @@ luks_recover_key (grub_disk_t source, | ||
364 | && grub_be_to_cpu32 (header.keyblock[i].stripes) > max_stripes) | ||
365 | max_stripes = grub_be_to_cpu32 (header.keyblock[i].stripes); | ||
366 | |||
367 | - split_key = grub_malloc (keysize * max_stripes); | ||
368 | + split_key = grub_calloc (keysize, max_stripes); | ||
369 | if (!split_key) | ||
370 | return grub_errno; | ||
371 | |||
372 | diff --git a/grub-core/disk/lvm.c b/grub-core/disk/lvm.c | ||
373 | index dc6b83b..7b5fbbc 100644 | ||
374 | --- a/grub-core/disk/lvm.c | ||
375 | +++ b/grub-core/disk/lvm.c | ||
376 | @@ -209,7 +209,7 @@ grub_lvm_detect (grub_disk_t disk, | ||
377 | first one. */ | ||
378 | |||
379 | /* Allocate buffer space for the circular worst-case scenario. */ | ||
380 | - metadatabuf = grub_malloc (2 * mda_size); | ||
381 | + metadatabuf = grub_calloc (2, mda_size); | ||
382 | if (! metadatabuf) | ||
383 | goto fail; | ||
384 | |||
385 | @@ -464,7 +464,7 @@ grub_lvm_detect (grub_disk_t disk, | ||
386 | #endif | ||
387 | goto lvs_fail; | ||
388 | } | ||
389 | - lv->segments = grub_zalloc (sizeof (*seg) * lv->segment_count); | ||
390 | + lv->segments = grub_calloc (lv->segment_count, sizeof (*seg)); | ||
391 | seg = lv->segments; | ||
392 | |||
393 | for (i = 0; i < lv->segment_count; i++) | ||
394 | @@ -521,8 +521,8 @@ grub_lvm_detect (grub_disk_t disk, | ||
395 | if (seg->node_count != 1) | ||
396 | seg->stripe_size = grub_lvm_getvalue (&p, "stripe_size = "); | ||
397 | |||
398 | - seg->nodes = grub_zalloc (sizeof (*stripe) | ||
399 | - * seg->node_count); | ||
400 | + seg->nodes = grub_calloc (seg->node_count, | ||
401 | + sizeof (*stripe)); | ||
402 | stripe = seg->nodes; | ||
403 | |||
404 | p = grub_strstr (p, "stripes = ["); | ||
405 | @@ -898,7 +898,7 @@ grub_lvm_detect (grub_disk_t disk, | ||
406 | break; | ||
407 | if (lv) | ||
408 | { | ||
409 | - cache->lv->segments = grub_malloc (lv->segment_count * sizeof (*lv->segments)); | ||
410 | + cache->lv->segments = grub_calloc (lv->segment_count, sizeof (*lv->segments)); | ||
411 | if (!cache->lv->segments) | ||
412 | { | ||
413 | grub_lvm_free_cache_lvs (cache_lvs); | ||
414 | @@ -911,7 +911,7 @@ grub_lvm_detect (grub_disk_t disk, | ||
415 | struct grub_diskfilter_node *nodes = lv->segments[i].nodes; | ||
416 | grub_size_t node_count = lv->segments[i].node_count; | ||
417 | |||
418 | - cache->lv->segments[i].nodes = grub_malloc (node_count * sizeof (*nodes)); | ||
419 | + cache->lv->segments[i].nodes = grub_calloc (node_count, sizeof (*nodes)); | ||
420 | if (!cache->lv->segments[i].nodes) | ||
421 | { | ||
422 | for (j = 0; j < i; ++j) | ||
423 | diff --git a/grub-core/disk/xen/xendisk.c b/grub-core/disk/xen/xendisk.c | ||
424 | index 48476cb..d6612ee 100644 | ||
425 | --- a/grub-core/disk/xen/xendisk.c | ||
426 | +++ b/grub-core/disk/xen/xendisk.c | ||
427 | @@ -426,7 +426,7 @@ grub_xendisk_init (void) | ||
428 | if (!ctr) | ||
429 | return; | ||
430 | |||
431 | - virtdisks = grub_malloc (ctr * sizeof (virtdisks[0])); | ||
432 | + virtdisks = grub_calloc (ctr, sizeof (virtdisks[0])); | ||
433 | if (!virtdisks) | ||
434 | return; | ||
435 | if (grub_xenstore_dir ("device/vbd", fill, &ctr)) | ||
436 | diff --git a/grub-core/efiemu/loadcore.c b/grub-core/efiemu/loadcore.c | ||
437 | index 44085ef..2b92462 100644 | ||
438 | --- a/grub-core/efiemu/loadcore.c | ||
439 | +++ b/grub-core/efiemu/loadcore.c | ||
440 | @@ -201,7 +201,7 @@ grub_efiemu_count_symbols (const Elf_Ehdr *e) | ||
441 | |||
442 | grub_efiemu_nelfsyms = (unsigned) s->sh_size / (unsigned) s->sh_entsize; | ||
443 | grub_efiemu_elfsyms = (struct grub_efiemu_elf_sym *) | ||
444 | - grub_malloc (sizeof (struct grub_efiemu_elf_sym) * grub_efiemu_nelfsyms); | ||
445 | + grub_calloc (grub_efiemu_nelfsyms, sizeof (struct grub_efiemu_elf_sym)); | ||
446 | |||
447 | /* Relocators */ | ||
448 | for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff); | ||
449 | diff --git a/grub-core/efiemu/mm.c b/grub-core/efiemu/mm.c | ||
450 | index 52a032f..9b8e0d0 100644 | ||
451 | --- a/grub-core/efiemu/mm.c | ||
452 | +++ b/grub-core/efiemu/mm.c | ||
453 | @@ -554,11 +554,11 @@ grub_efiemu_mmap_sort_and_uniq (void) | ||
454 | /* Initialize variables*/ | ||
455 | grub_memset (present, 0, sizeof (int) * GRUB_EFI_MAX_MEMORY_TYPE); | ||
456 | scanline_events = (struct grub_efiemu_mmap_scan *) | ||
457 | - grub_malloc (sizeof (struct grub_efiemu_mmap_scan) * 2 * mmap_num); | ||
458 | + grub_calloc (mmap_num, sizeof (struct grub_efiemu_mmap_scan) * 2); | ||
459 | |||
460 | /* Number of chunks can't increase more than by factor of 2 */ | ||
461 | result = (grub_efi_memory_descriptor_t *) | ||
462 | - grub_malloc (sizeof (grub_efi_memory_descriptor_t) * 2 * mmap_num); | ||
463 | + grub_calloc (mmap_num, sizeof (grub_efi_memory_descriptor_t) * 2); | ||
464 | if (!result || !scanline_events) | ||
465 | { | ||
466 | grub_free (result); | ||
467 | @@ -660,7 +660,7 @@ grub_efiemu_mm_do_alloc (void) | ||
468 | |||
469 | /* Preallocate mmap */ | ||
470 | efiemu_mmap = (grub_efi_memory_descriptor_t *) | ||
471 | - grub_malloc (mmap_reserved_size * sizeof (grub_efi_memory_descriptor_t)); | ||
472 | + grub_calloc (mmap_reserved_size, sizeof (grub_efi_memory_descriptor_t)); | ||
473 | if (!efiemu_mmap) | ||
474 | { | ||
475 | grub_efiemu_unload (); | ||
476 | diff --git a/grub-core/font/font.c b/grub-core/font/font.c | ||
477 | index 85a2925..8e118b3 100644 | ||
478 | --- a/grub-core/font/font.c | ||
479 | +++ b/grub-core/font/font.c | ||
480 | @@ -293,8 +293,7 @@ load_font_index (grub_file_t file, grub_uint32_t sect_length, struct | ||
481 | font->num_chars = sect_length / FONT_CHAR_INDEX_ENTRY_SIZE; | ||
482 | |||
483 | /* Allocate the character index array. */ | ||
484 | - font->char_index = grub_malloc (font->num_chars | ||
485 | - * sizeof (struct char_index_entry)); | ||
486 | + font->char_index = grub_calloc (font->num_chars, sizeof (struct char_index_entry)); | ||
487 | if (!font->char_index) | ||
488 | return 1; | ||
489 | font->bmp_idx = grub_malloc (0x10000 * sizeof (grub_uint16_t)); | ||
490 | diff --git a/grub-core/fs/affs.c b/grub-core/fs/affs.c | ||
491 | index 6b6a2bc..220b371 100644 | ||
492 | --- a/grub-core/fs/affs.c | ||
493 | +++ b/grub-core/fs/affs.c | ||
494 | @@ -301,7 +301,7 @@ grub_affs_read_symlink (grub_fshelp_node_t node) | ||
495 | return 0; | ||
496 | } | ||
497 | latin1[symlink_size] = 0; | ||
498 | - utf8 = grub_malloc (symlink_size * GRUB_MAX_UTF8_PER_LATIN1 + 1); | ||
499 | + utf8 = grub_calloc (GRUB_MAX_UTF8_PER_LATIN1 + 1, symlink_size); | ||
500 | if (!utf8) | ||
501 | { | ||
502 | grub_free (latin1); | ||
503 | @@ -422,7 +422,7 @@ grub_affs_iterate_dir (grub_fshelp_node_t dir, | ||
504 | return 1; | ||
505 | } | ||
506 | |||
507 | - hashtable = grub_zalloc (data->htsize * sizeof (*hashtable)); | ||
508 | + hashtable = grub_calloc (data->htsize, sizeof (*hashtable)); | ||
509 | if (!hashtable) | ||
510 | return 1; | ||
511 | |||
512 | @@ -628,7 +628,7 @@ grub_affs_label (grub_device_t device, char **label) | ||
513 | len = file.namelen; | ||
514 | if (len > sizeof (file.name)) | ||
515 | len = sizeof (file.name); | ||
516 | - *label = grub_malloc (len * GRUB_MAX_UTF8_PER_LATIN1 + 1); | ||
517 | + *label = grub_calloc (GRUB_MAX_UTF8_PER_LATIN1 + 1, len); | ||
518 | if (*label) | ||
519 | *grub_latin1_to_utf8 ((grub_uint8_t *) *label, file.name, len) = '\0'; | ||
520 | } | ||
521 | diff --git a/grub-core/fs/btrfs.c b/grub-core/fs/btrfs.c | ||
522 | index 48bd3d0..11272ef 100644 | ||
523 | --- a/grub-core/fs/btrfs.c | ||
524 | +++ b/grub-core/fs/btrfs.c | ||
525 | @@ -413,7 +413,7 @@ lower_bound (struct grub_btrfs_data *data, | ||
526 | { | ||
527 | desc->allocated = 16; | ||
528 | desc->depth = 0; | ||
529 | - desc->data = grub_malloc (sizeof (desc->data[0]) * desc->allocated); | ||
530 | + desc->data = grub_calloc (desc->allocated, sizeof (desc->data[0])); | ||
531 | if (!desc->data) | ||
532 | return grub_errno; | ||
533 | } | ||
534 | @@ -752,7 +752,7 @@ raid56_read_retry (struct grub_btrfs_data *data, | ||
535 | grub_err_t ret = GRUB_ERR_OUT_OF_MEMORY; | ||
536 | grub_uint64_t i, failed_devices; | ||
537 | |||
538 | - buffers = grub_zalloc (sizeof(*buffers) * nstripes); | ||
539 | + buffers = grub_calloc (nstripes, sizeof (*buffers)); | ||
540 | if (!buffers) | ||
541 | goto cleanup; | ||
542 | |||
543 | @@ -2160,7 +2160,7 @@ grub_btrfs_embed (grub_device_t device __attribute__ ((unused)), | ||
544 | *nsectors = 64 * 2 - 1; | ||
545 | if (*nsectors > max_nsectors) | ||
546 | *nsectors = max_nsectors; | ||
547 | - *sectors = grub_malloc (*nsectors * sizeof (**sectors)); | ||
548 | + *sectors = grub_calloc (*nsectors, sizeof (**sectors)); | ||
549 | if (!*sectors) | ||
550 | return grub_errno; | ||
551 | for (i = 0; i < *nsectors; i++) | ||
552 | diff --git a/grub-core/fs/hfs.c b/grub-core/fs/hfs.c | ||
553 | index ac0a409..3fe842b 100644 | ||
554 | --- a/grub-core/fs/hfs.c | ||
555 | +++ b/grub-core/fs/hfs.c | ||
556 | @@ -1360,7 +1360,7 @@ grub_hfs_label (grub_device_t device, char **label) | ||
557 | grub_size_t len = data->sblock.volname[0]; | ||
558 | if (len > sizeof (data->sblock.volname) - 1) | ||
559 | len = sizeof (data->sblock.volname) - 1; | ||
560 | - *label = grub_malloc (len * MAX_UTF8_PER_MAC_ROMAN + 1); | ||
561 | + *label = grub_calloc (MAX_UTF8_PER_MAC_ROMAN + 1, len); | ||
562 | if (*label) | ||
563 | macroman_to_utf8 (*label, data->sblock.volname + 1, | ||
564 | len + 1, 0); | ||
565 | diff --git a/grub-core/fs/hfsplus.c b/grub-core/fs/hfsplus.c | ||
566 | index 54786bb..dae43be 100644 | ||
567 | --- a/grub-core/fs/hfsplus.c | ||
568 | +++ b/grub-core/fs/hfsplus.c | ||
569 | @@ -720,7 +720,7 @@ list_nodes (void *record, void *hook_arg) | ||
570 | if (! filename) | ||
571 | return 0; | ||
572 | |||
573 | - keyname = grub_malloc (grub_be_to_cpu16 (catkey->namelen) * sizeof (*keyname)); | ||
574 | + keyname = grub_calloc (grub_be_to_cpu16 (catkey->namelen), sizeof (*keyname)); | ||
575 | if (!keyname) | ||
576 | { | ||
577 | grub_free (filename); | ||
578 | @@ -1007,7 +1007,7 @@ grub_hfsplus_label (grub_device_t device, char **label) | ||
579 | grub_hfsplus_btree_recptr (&data->catalog_tree, node, ptr); | ||
580 | |||
581 | label_len = grub_be_to_cpu16 (catkey->namelen); | ||
582 | - label_name = grub_malloc (label_len * sizeof (*label_name)); | ||
583 | + label_name = grub_calloc (label_len, sizeof (*label_name)); | ||
584 | if (!label_name) | ||
585 | { | ||
586 | grub_free (node); | ||
587 | @@ -1029,7 +1029,7 @@ grub_hfsplus_label (grub_device_t device, char **label) | ||
588 | } | ||
589 | } | ||
590 | |||
591 | - *label = grub_malloc (label_len * GRUB_MAX_UTF8_PER_UTF16 + 1); | ||
592 | + *label = grub_calloc (label_len, GRUB_MAX_UTF8_PER_UTF16 + 1); | ||
593 | if (! *label) | ||
594 | { | ||
595 | grub_free (label_name); | ||
596 | diff --git a/grub-core/fs/iso9660.c b/grub-core/fs/iso9660.c | ||
597 | index 49c0c63..4f1b52a 100644 | ||
598 | --- a/grub-core/fs/iso9660.c | ||
599 | +++ b/grub-core/fs/iso9660.c | ||
600 | @@ -331,7 +331,7 @@ grub_iso9660_convert_string (grub_uint8_t *us, int len) | ||
601 | int i; | ||
602 | grub_uint16_t t[MAX_NAMELEN / 2 + 1]; | ||
603 | |||
604 | - p = grub_malloc (len * GRUB_MAX_UTF8_PER_UTF16 + 1); | ||
605 | + p = grub_calloc (len, GRUB_MAX_UTF8_PER_UTF16 + 1); | ||
606 | if (! p) | ||
607 | return NULL; | ||
608 | |||
609 | diff --git a/grub-core/fs/ntfs.c b/grub-core/fs/ntfs.c | ||
610 | index fc4e1f6..2f34f76 100644 | ||
611 | --- a/grub-core/fs/ntfs.c | ||
612 | +++ b/grub-core/fs/ntfs.c | ||
613 | @@ -556,8 +556,8 @@ get_utf8 (grub_uint8_t *in, grub_size_t len) | ||
614 | grub_uint16_t *tmp; | ||
615 | grub_size_t i; | ||
616 | |||
617 | - buf = grub_malloc (len * GRUB_MAX_UTF8_PER_UTF16 + 1); | ||
618 | - tmp = grub_malloc (len * sizeof (tmp[0])); | ||
619 | + buf = grub_calloc (len, GRUB_MAX_UTF8_PER_UTF16 + 1); | ||
620 | + tmp = grub_calloc (len, sizeof (tmp[0])); | ||
621 | if (!buf || !tmp) | ||
622 | { | ||
623 | grub_free (buf); | ||
624 | diff --git a/grub-core/fs/sfs.c b/grub-core/fs/sfs.c | ||
625 | index 50c1fe7..90f7fb3 100644 | ||
626 | --- a/grub-core/fs/sfs.c | ||
627 | +++ b/grub-core/fs/sfs.c | ||
628 | @@ -266,7 +266,7 @@ grub_sfs_read_block (grub_fshelp_node_t node, grub_disk_addr_t fileblock) | ||
629 | node->next_extent = node->block; | ||
630 | node->cache_size = 0; | ||
631 | |||
632 | - node->cache = grub_malloc (sizeof (node->cache[0]) * cache_size); | ||
633 | + node->cache = grub_calloc (cache_size, sizeof (node->cache[0])); | ||
634 | if (!node->cache) | ||
635 | { | ||
636 | grub_errno = 0; | ||
637 | diff --git a/grub-core/fs/tar.c b/grub-core/fs/tar.c | ||
638 | index 7d63e0c..c551ed6 100644 | ||
639 | --- a/grub-core/fs/tar.c | ||
640 | +++ b/grub-core/fs/tar.c | ||
641 | @@ -120,7 +120,7 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name, | ||
642 | if (data->linkname_alloc < linksize + 1) | ||
643 | { | ||
644 | char *n; | ||
645 | - n = grub_malloc (2 * (linksize + 1)); | ||
646 | + n = grub_calloc (2, linksize + 1); | ||
647 | if (!n) | ||
648 | return grub_errno; | ||
649 | grub_free (data->linkname); | ||
650 | diff --git a/grub-core/fs/udf.c b/grub-core/fs/udf.c | ||
651 | index dc8b6e2..a837616 100644 | ||
652 | --- a/grub-core/fs/udf.c | ||
653 | +++ b/grub-core/fs/udf.c | ||
654 | @@ -873,7 +873,7 @@ read_string (const grub_uint8_t *raw, grub_size_t sz, char *outbuf) | ||
655 | { | ||
656 | unsigned i; | ||
657 | utf16len = sz - 1; | ||
658 | - utf16 = grub_malloc (utf16len * sizeof (utf16[0])); | ||
659 | + utf16 = grub_calloc (utf16len, sizeof (utf16[0])); | ||
660 | if (!utf16) | ||
661 | return NULL; | ||
662 | for (i = 0; i < utf16len; i++) | ||
663 | @@ -883,7 +883,7 @@ read_string (const grub_uint8_t *raw, grub_size_t sz, char *outbuf) | ||
664 | { | ||
665 | unsigned i; | ||
666 | utf16len = (sz - 1) / 2; | ||
667 | - utf16 = grub_malloc (utf16len * sizeof (utf16[0])); | ||
668 | + utf16 = grub_calloc (utf16len, sizeof (utf16[0])); | ||
669 | if (!utf16) | ||
670 | return NULL; | ||
671 | for (i = 0; i < utf16len; i++) | ||
672 | diff --git a/grub-core/fs/zfs/zfs.c b/grub-core/fs/zfs/zfs.c | ||
673 | index 2f72e42..381dde5 100644 | ||
674 | --- a/grub-core/fs/zfs/zfs.c | ||
675 | +++ b/grub-core/fs/zfs/zfs.c | ||
676 | @@ -3325,7 +3325,7 @@ dnode_get_fullpath (const char *fullpath, struct subvolume *subvol, | ||
677 | } | ||
678 | subvol->nkeys = 0; | ||
679 | zap_iterate (&keychain_dn, 8, count_zap_keys, &ctx, data); | ||
680 | - subvol->keyring = grub_zalloc (subvol->nkeys * sizeof (subvol->keyring[0])); | ||
681 | + subvol->keyring = grub_calloc (subvol->nkeys, sizeof (subvol->keyring[0])); | ||
682 | if (!subvol->keyring) | ||
683 | { | ||
684 | grub_free (fsname); | ||
685 | @@ -4336,7 +4336,7 @@ grub_zfs_embed (grub_device_t device __attribute__ ((unused)), | ||
686 | *nsectors = (VDEV_BOOT_SIZE >> GRUB_DISK_SECTOR_BITS); | ||
687 | if (*nsectors > max_nsectors) | ||
688 | *nsectors = max_nsectors; | ||
689 | - *sectors = grub_malloc (*nsectors * sizeof (**sectors)); | ||
690 | + *sectors = grub_calloc (*nsectors, sizeof (**sectors)); | ||
691 | if (!*sectors) | ||
692 | return grub_errno; | ||
693 | for (i = 0; i < *nsectors; i++) | ||
694 | diff --git a/grub-core/gfxmenu/gui_string_util.c b/grub-core/gfxmenu/gui_string_util.c | ||
695 | index a9a415e..ba1e1ea 100644 | ||
696 | --- a/grub-core/gfxmenu/gui_string_util.c | ||
697 | +++ b/grub-core/gfxmenu/gui_string_util.c | ||
698 | @@ -55,7 +55,7 @@ canonicalize_path (const char *path) | ||
699 | if (*p == '/') | ||
700 | components++; | ||
701 | |||
702 | - char **path_array = grub_malloc (components * sizeof (*path_array)); | ||
703 | + char **path_array = grub_calloc (components, sizeof (*path_array)); | ||
704 | if (! path_array) | ||
705 | return 0; | ||
706 | |||
707 | diff --git a/grub-core/gfxmenu/widget-box.c b/grub-core/gfxmenu/widget-box.c | ||
708 | index b606028..470597d 100644 | ||
709 | --- a/grub-core/gfxmenu/widget-box.c | ||
710 | +++ b/grub-core/gfxmenu/widget-box.c | ||
711 | @@ -303,10 +303,10 @@ grub_gfxmenu_create_box (const char *pixmaps_prefix, | ||
712 | box->content_height = 0; | ||
713 | box->raw_pixmaps = | ||
714 | (struct grub_video_bitmap **) | ||
715 | - grub_malloc (BOX_NUM_PIXMAPS * sizeof (struct grub_video_bitmap *)); | ||
716 | + grub_calloc (BOX_NUM_PIXMAPS, sizeof (struct grub_video_bitmap *)); | ||
717 | box->scaled_pixmaps = | ||
718 | (struct grub_video_bitmap **) | ||
719 | - grub_malloc (BOX_NUM_PIXMAPS * sizeof (struct grub_video_bitmap *)); | ||
720 | + grub_calloc (BOX_NUM_PIXMAPS, sizeof (struct grub_video_bitmap *)); | ||
721 | |||
722 | /* Initialize all pixmap pointers to NULL so that proper destruction can | ||
723 | be performed if an error is encountered partway through construction. */ | ||
724 | diff --git a/grub-core/io/gzio.c b/grub-core/io/gzio.c | ||
725 | index 6208a97..43d98a7 100644 | ||
726 | --- a/grub-core/io/gzio.c | ||
727 | +++ b/grub-core/io/gzio.c | ||
728 | @@ -554,7 +554,7 @@ huft_build (unsigned *b, /* code lengths in bits (all assumed <= BMAX) */ | ||
729 | z = 1 << j; /* table entries for j-bit table */ | ||
730 | |||
731 | /* allocate and link in new table */ | ||
732 | - q = (struct huft *) grub_zalloc ((z + 1) * sizeof (struct huft)); | ||
733 | + q = (struct huft *) grub_calloc (z + 1, sizeof (struct huft)); | ||
734 | if (! q) | ||
735 | { | ||
736 | if (h) | ||
737 | diff --git a/grub-core/kern/efi/efi.c b/grub-core/kern/efi/efi.c | ||
738 | index 6e1ceb9..dc31caa 100644 | ||
739 | --- a/grub-core/kern/efi/efi.c | ||
740 | +++ b/grub-core/kern/efi/efi.c | ||
741 | @@ -202,7 +202,7 @@ grub_efi_set_variable(const char *var, const grub_efi_guid_t *guid, | ||
742 | |||
743 | len = grub_strlen (var); | ||
744 | len16 = len * GRUB_MAX_UTF16_PER_UTF8; | ||
745 | - var16 = grub_malloc ((len16 + 1) * sizeof (var16[0])); | ||
746 | + var16 = grub_calloc (len16 + 1, sizeof (var16[0])); | ||
747 | if (!var16) | ||
748 | return grub_errno; | ||
749 | len16 = grub_utf8_to_utf16 (var16, len16, (grub_uint8_t *) var, len, NULL); | ||
750 | @@ -237,7 +237,7 @@ grub_efi_get_variable (const char *var, const grub_efi_guid_t *guid, | ||
751 | |||
752 | len = grub_strlen (var); | ||
753 | len16 = len * GRUB_MAX_UTF16_PER_UTF8; | ||
754 | - var16 = grub_malloc ((len16 + 1) * sizeof (var16[0])); | ||
755 | + var16 = grub_calloc (len16 + 1, sizeof (var16[0])); | ||
756 | if (!var16) | ||
757 | return NULL; | ||
758 | len16 = grub_utf8_to_utf16 (var16, len16, (grub_uint8_t *) var, len, NULL); | ||
759 | @@ -383,7 +383,7 @@ grub_efi_get_filename (grub_efi_device_path_t *dp0) | ||
760 | while (len > 0 && fp->path_name[len - 1] == 0) | ||
761 | len--; | ||
762 | |||
763 | - dup_name = grub_malloc (len * sizeof (*dup_name)); | ||
764 | + dup_name = grub_calloc (len, sizeof (*dup_name)); | ||
765 | if (!dup_name) | ||
766 | { | ||
767 | grub_free (name); | ||
768 | diff --git a/grub-core/kern/emu/hostdisk.c b/grub-core/kern/emu/hostdisk.c | ||
769 | index e9ec680..d975265 100644 | ||
770 | --- a/grub-core/kern/emu/hostdisk.c | ||
771 | +++ b/grub-core/kern/emu/hostdisk.c | ||
772 | @@ -615,7 +615,7 @@ static char * | ||
773 | grub_util_path_concat_real (size_t n, int ext, va_list ap) | ||
774 | { | ||
775 | size_t totlen = 0; | ||
776 | - char **l = xmalloc ((n + ext) * sizeof (l[0])); | ||
777 | + char **l = xcalloc (n + ext, sizeof (l[0])); | ||
778 | char *r, *p, *pi; | ||
779 | size_t i; | ||
780 | int first = 1; | ||
781 | diff --git a/grub-core/kern/fs.c b/grub-core/kern/fs.c | ||
782 | index 2b85f49..f90be65 100644 | ||
783 | --- a/grub-core/kern/fs.c | ||
784 | +++ b/grub-core/kern/fs.c | ||
785 | @@ -151,7 +151,7 @@ grub_fs_blocklist_open (grub_file_t file, const char *name) | ||
786 | while (p); | ||
787 | |||
788 | /* Allocate a block list. */ | ||
789 | - blocks = grub_zalloc (sizeof (struct grub_fs_block) * (num + 1)); | ||
790 | + blocks = grub_calloc (num + 1, sizeof (struct grub_fs_block)); | ||
791 | if (! blocks) | ||
792 | return 0; | ||
793 | |||
794 | diff --git a/grub-core/kern/misc.c b/grub-core/kern/misc.c | ||
795 | index 3b633d5..a7abd36 100644 | ||
796 | --- a/grub-core/kern/misc.c | ||
797 | +++ b/grub-core/kern/misc.c | ||
798 | @@ -690,7 +690,7 @@ parse_printf_args (const char *fmt0, struct printf_args *args, | ||
799 | args->ptr = args->prealloc; | ||
800 | else | ||
801 | { | ||
802 | - args->ptr = grub_malloc (args->count * sizeof (args->ptr[0])); | ||
803 | + args->ptr = grub_calloc (args->count, sizeof (args->ptr[0])); | ||
804 | if (!args->ptr) | ||
805 | { | ||
806 | grub_errno = GRUB_ERR_NONE; | ||
807 | diff --git a/grub-core/kern/parser.c b/grub-core/kern/parser.c | ||
808 | index 78175aa..619db31 100644 | ||
809 | --- a/grub-core/kern/parser.c | ||
810 | +++ b/grub-core/kern/parser.c | ||
811 | @@ -213,7 +213,7 @@ grub_parser_split_cmdline (const char *cmdline, | ||
812 | return grub_errno; | ||
813 | grub_memcpy (args, buffer, bp - buffer); | ||
814 | |||
815 | - *argv = grub_malloc (sizeof (char *) * (*argc + 1)); | ||
816 | + *argv = grub_calloc (*argc + 1, sizeof (char *)); | ||
817 | if (!*argv) | ||
818 | { | ||
819 | grub_free (args); | ||
820 | diff --git a/grub-core/kern/uboot/uboot.c b/grub-core/kern/uboot/uboot.c | ||
821 | index be4816f..aac8f9a 100644 | ||
822 | --- a/grub-core/kern/uboot/uboot.c | ||
823 | +++ b/grub-core/kern/uboot/uboot.c | ||
824 | @@ -133,7 +133,7 @@ grub_uboot_dev_enum (void) | ||
825 | return num_devices; | ||
826 | |||
827 | max_devices = 2; | ||
828 | - enum_devices = grub_malloc (sizeof(struct device_info) * max_devices); | ||
829 | + enum_devices = grub_calloc (max_devices, sizeof(struct device_info)); | ||
830 | if (!enum_devices) | ||
831 | return 0; | ||
832 | |||
833 | diff --git a/grub-core/lib/libgcrypt/cipher/ac.c b/grub-core/lib/libgcrypt/cipher/ac.c | ||
834 | index f5e946a..63f6fcd 100644 | ||
835 | --- a/grub-core/lib/libgcrypt/cipher/ac.c | ||
836 | +++ b/grub-core/lib/libgcrypt/cipher/ac.c | ||
837 | @@ -185,7 +185,7 @@ ac_data_mpi_copy (gcry_ac_mpi_t *data_mpis, unsigned int data_mpis_n, | ||
838 | gcry_mpi_t mpi; | ||
839 | char *label; | ||
840 | |||
841 | - data_mpis_new = gcry_malloc (sizeof (*data_mpis_new) * data_mpis_n); | ||
842 | + data_mpis_new = gcry_calloc (data_mpis_n, sizeof (*data_mpis_new)); | ||
843 | if (! data_mpis_new) | ||
844 | { | ||
845 | err = gcry_error_from_errno (errno); | ||
846 | @@ -572,7 +572,7 @@ _gcry_ac_data_to_sexp (gcry_ac_data_t data, gcry_sexp_t *sexp, | ||
847 | } | ||
848 | |||
849 | /* Add MPI list. */ | ||
850 | - arg_list = gcry_malloc (sizeof (*arg_list) * (data_n + 1)); | ||
851 | + arg_list = gcry_calloc (data_n + 1, sizeof (*arg_list)); | ||
852 | if (! arg_list) | ||
853 | { | ||
854 | err = gcry_error_from_errno (errno); | ||
855 | @@ -1283,7 +1283,7 @@ ac_data_construct (const char *identifier, int include_flags, | ||
856 | /* We build a list of arguments to pass to | ||
857 | gcry_sexp_build_array(). */ | ||
858 | data_length = _gcry_ac_data_length (data); | ||
859 | - arg_list = gcry_malloc (sizeof (*arg_list) * (data_length * 2)); | ||
860 | + arg_list = gcry_calloc (data_length, sizeof (*arg_list) * 2); | ||
861 | if (! arg_list) | ||
862 | { | ||
863 | err = gcry_error_from_errno (errno); | ||
864 | @@ -1593,7 +1593,7 @@ _gcry_ac_key_pair_generate (gcry_ac_handle_t handle, unsigned int nbits, | ||
865 | arg_list_n += 2; | ||
866 | |||
867 | /* Allocate list. */ | ||
868 | - arg_list = gcry_malloc (sizeof (*arg_list) * arg_list_n); | ||
869 | + arg_list = gcry_calloc (arg_list_n, sizeof (*arg_list)); | ||
870 | if (! arg_list) | ||
871 | { | ||
872 | err = gcry_error_from_errno (errno); | ||
873 | diff --git a/grub-core/lib/libgcrypt/cipher/primegen.c b/grub-core/lib/libgcrypt/cipher/primegen.c | ||
874 | index 2788e34..b12e79b 100644 | ||
875 | --- a/grub-core/lib/libgcrypt/cipher/primegen.c | ||
876 | +++ b/grub-core/lib/libgcrypt/cipher/primegen.c | ||
877 | @@ -383,7 +383,7 @@ prime_generate_internal (int need_q_factor, | ||
878 | } | ||
879 | |||
880 | /* Allocate an array to track pool usage. */ | ||
881 | - pool_in_use = gcry_malloc (n * sizeof *pool_in_use); | ||
882 | + pool_in_use = gcry_calloc (n, sizeof *pool_in_use); | ||
883 | if (!pool_in_use) | ||
884 | { | ||
885 | err = gpg_err_code_from_errno (errno); | ||
886 | @@ -765,7 +765,7 @@ gen_prime (unsigned int nbits, int secret, int randomlevel, | ||
887 | if (nbits < 16) | ||
888 | log_fatal ("can't generate a prime with less than %d bits\n", 16); | ||
889 | |||
890 | - mods = gcry_xmalloc( no_of_small_prime_numbers * sizeof *mods ); | ||
891 | + mods = gcry_xcalloc( no_of_small_prime_numbers, sizeof *mods); | ||
892 | /* Make nbits fit into gcry_mpi_t implementation. */ | ||
893 | val_2 = mpi_alloc_set_ui( 2 ); | ||
894 | val_3 = mpi_alloc_set_ui( 3); | ||
895 | diff --git a/grub-core/lib/libgcrypt/cipher/pubkey.c b/grub-core/lib/libgcrypt/cipher/pubkey.c | ||
896 | index 9109821..ca087ad 100644 | ||
897 | --- a/grub-core/lib/libgcrypt/cipher/pubkey.c | ||
898 | +++ b/grub-core/lib/libgcrypt/cipher/pubkey.c | ||
899 | @@ -2941,7 +2941,7 @@ gcry_pk_encrypt (gcry_sexp_t *r_ciph, gcry_sexp_t s_data, gcry_sexp_t s_pkey) | ||
900 | * array to a format string, so we have to do it this way :-(. */ | ||
901 | /* FIXME: There is now such a format specifier, so we can | ||
902 | change the code to be more clear. */ | ||
903 | - arg_list = malloc (nelem * sizeof *arg_list); | ||
904 | + arg_list = calloc (nelem, sizeof *arg_list); | ||
905 | if (!arg_list) | ||
906 | { | ||
907 | rc = gpg_err_code_from_syserror (); | ||
908 | @@ -3233,7 +3233,7 @@ gcry_pk_sign (gcry_sexp_t *r_sig, gcry_sexp_t s_hash, gcry_sexp_t s_skey) | ||
909 | } | ||
910 | strcpy (p, "))"); | ||
911 | |||
912 | - arg_list = malloc (nelem * sizeof *arg_list); | ||
913 | + arg_list = calloc (nelem, sizeof *arg_list); | ||
914 | if (!arg_list) | ||
915 | { | ||
916 | rc = gpg_err_code_from_syserror (); | ||
917 | diff --git a/grub-core/lib/priority_queue.c b/grub-core/lib/priority_queue.c | ||
918 | index 659be0b..7d5e7c0 100644 | ||
919 | --- a/grub-core/lib/priority_queue.c | ||
920 | +++ b/grub-core/lib/priority_queue.c | ||
921 | @@ -92,7 +92,7 @@ grub_priority_queue_new (grub_size_t elsize, | ||
922 | { | ||
923 | struct grub_priority_queue *ret; | ||
924 | void *els; | ||
925 | - els = grub_malloc (elsize * 8); | ||
926 | + els = grub_calloc (8, elsize); | ||
927 | if (!els) | ||
928 | return 0; | ||
929 | ret = (struct grub_priority_queue *) grub_malloc (sizeof (*ret)); | ||
930 | diff --git a/grub-core/lib/reed_solomon.c b/grub-core/lib/reed_solomon.c | ||
931 | index ee9fa7b..467305b 100644 | ||
932 | --- a/grub-core/lib/reed_solomon.c | ||
933 | +++ b/grub-core/lib/reed_solomon.c | ||
934 | @@ -20,6 +20,7 @@ | ||
935 | #include <stdio.h> | ||
936 | #include <string.h> | ||
937 | #include <stdlib.h> | ||
938 | +#define xcalloc calloc | ||
939 | #define xmalloc malloc | ||
940 | #define grub_memset memset | ||
941 | #define grub_memcpy memcpy | ||
942 | @@ -158,11 +159,9 @@ rs_encode (gf_single_t *data, grub_size_t s, grub_size_t rs) | ||
943 | gf_single_t *rs_polynomial; | ||
944 | int i, j; | ||
945 | gf_single_t *m; | ||
946 | - m = xmalloc ((s + rs) * sizeof (gf_single_t)); | ||
947 | + m = xcalloc (s + rs, sizeof (gf_single_t)); | ||
948 | grub_memcpy (m, data, s * sizeof (gf_single_t)); | ||
949 | - grub_memset (m + s, 0, rs * sizeof (gf_single_t)); | ||
950 | - rs_polynomial = xmalloc ((rs + 1) * sizeof (gf_single_t)); | ||
951 | - grub_memset (rs_polynomial, 0, (rs + 1) * sizeof (gf_single_t)); | ||
952 | + rs_polynomial = xcalloc (rs + 1, sizeof (gf_single_t)); | ||
953 | rs_polynomial[rs] = 1; | ||
954 | /* Multiply with X - a^r */ | ||
955 | for (j = 0; j < rs; j++) | ||
956 | diff --git a/grub-core/lib/relocator.c b/grub-core/lib/relocator.c | ||
957 | index ea3ebc7..5847aac 100644 | ||
958 | --- a/grub-core/lib/relocator.c | ||
959 | +++ b/grub-core/lib/relocator.c | ||
960 | @@ -495,9 +495,9 @@ malloc_in_range (struct grub_relocator *rel, | ||
961 | } | ||
962 | #endif | ||
963 | |||
964 | - eventt = grub_malloc (maxevents * sizeof (events[0])); | ||
965 | + eventt = grub_calloc (maxevents, sizeof (events[0])); | ||
966 | counter = grub_malloc ((DIGITSORT_MASK + 2) * sizeof (counter[0])); | ||
967 | - events = grub_malloc (maxevents * sizeof (events[0])); | ||
968 | + events = grub_calloc (maxevents, sizeof (events[0])); | ||
969 | if (!events || !eventt || !counter) | ||
970 | { | ||
971 | grub_dprintf ("relocator", "events or counter allocation failed %d\n", | ||
972 | @@ -963,7 +963,7 @@ malloc_in_range (struct grub_relocator *rel, | ||
973 | #endif | ||
974 | unsigned cural = 0; | ||
975 | int oom = 0; | ||
976 | - res->subchunks = grub_malloc (sizeof (res->subchunks[0]) * nallocs); | ||
977 | + res->subchunks = grub_calloc (nallocs, sizeof (res->subchunks[0])); | ||
978 | if (!res->subchunks) | ||
979 | oom = 1; | ||
980 | res->nsubchunks = nallocs; | ||
981 | @@ -1562,8 +1562,8 @@ grub_relocator_prepare_relocs (struct grub_relocator *rel, grub_addr_t addr, | ||
982 | count[(chunk->src & 0xff) + 1]++; | ||
983 | } | ||
984 | } | ||
985 | - from = grub_malloc (nchunks * sizeof (sorted[0])); | ||
986 | - to = grub_malloc (nchunks * sizeof (sorted[0])); | ||
987 | + from = grub_calloc (nchunks, sizeof (sorted[0])); | ||
988 | + to = grub_calloc (nchunks, sizeof (sorted[0])); | ||
989 | if (!from || !to) | ||
990 | { | ||
991 | grub_free (from); | ||
992 | diff --git a/grub-core/lib/zstd/fse_decompress.c b/grub-core/lib/zstd/fse_decompress.c | ||
993 | index 72bbead..2227b84 100644 | ||
994 | --- a/grub-core/lib/zstd/fse_decompress.c | ||
995 | +++ b/grub-core/lib/zstd/fse_decompress.c | ||
996 | @@ -82,7 +82,7 @@ | ||
997 | FSE_DTable* FSE_createDTable (unsigned tableLog) | ||
998 | { | ||
999 | if (tableLog > FSE_TABLELOG_ABSOLUTE_MAX) tableLog = FSE_TABLELOG_ABSOLUTE_MAX; | ||
1000 | - return (FSE_DTable*)malloc( FSE_DTABLE_SIZE_U32(tableLog) * sizeof (U32) ); | ||
1001 | + return (FSE_DTable*)calloc( FSE_DTABLE_SIZE_U32(tableLog), sizeof (U32) ); | ||
1002 | } | ||
1003 | |||
1004 | void FSE_freeDTable (FSE_DTable* dt) | ||
1005 | diff --git a/grub-core/loader/arm/linux.c b/grub-core/loader/arm/linux.c | ||
1006 | index 5168491..d70c174 100644 | ||
1007 | --- a/grub-core/loader/arm/linux.c | ||
1008 | +++ b/grub-core/loader/arm/linux.c | ||
1009 | @@ -78,7 +78,7 @@ linux_prepare_atag (void *target_atag) | ||
1010 | |||
1011 | /* some place for cmdline, initrd and terminator. */ | ||
1012 | tmp_size = get_atag_size (atag_orig) + 20 + (arg_size) / 4; | ||
1013 | - tmp_atag = grub_malloc (tmp_size * sizeof (grub_uint32_t)); | ||
1014 | + tmp_atag = grub_calloc (tmp_size, sizeof (grub_uint32_t)); | ||
1015 | if (!tmp_atag) | ||
1016 | return grub_errno; | ||
1017 | |||
1018 | diff --git a/grub-core/loader/efi/chainloader.c b/grub-core/loader/efi/chainloader.c | ||
1019 | index cd92ea3..daf8c6b 100644 | ||
1020 | --- a/grub-core/loader/efi/chainloader.c | ||
1021 | +++ b/grub-core/loader/efi/chainloader.c | ||
1022 | @@ -116,7 +116,7 @@ copy_file_path (grub_efi_file_path_device_path_t *fp, | ||
1023 | fp->header.type = GRUB_EFI_MEDIA_DEVICE_PATH_TYPE; | ||
1024 | fp->header.subtype = GRUB_EFI_FILE_PATH_DEVICE_PATH_SUBTYPE; | ||
1025 | |||
1026 | - path_name = grub_malloc (len * GRUB_MAX_UTF16_PER_UTF8 * sizeof (*path_name)); | ||
1027 | + path_name = grub_calloc (len, GRUB_MAX_UTF16_PER_UTF8 * sizeof (*path_name)); | ||
1028 | if (!path_name) | ||
1029 | return; | ||
1030 | |||
1031 | diff --git a/grub-core/loader/i386/bsdXX.c b/grub-core/loader/i386/bsdXX.c | ||
1032 | index af6741d..a8d8bf7 100644 | ||
1033 | --- a/grub-core/loader/i386/bsdXX.c | ||
1034 | +++ b/grub-core/loader/i386/bsdXX.c | ||
1035 | @@ -48,7 +48,7 @@ read_headers (grub_file_t file, const char *filename, Elf_Ehdr *e, char **shdr) | ||
1036 | if (e->e_ident[EI_CLASS] != SUFFIX (ELFCLASS)) | ||
1037 | return grub_error (GRUB_ERR_BAD_OS, N_("invalid arch-dependent ELF magic")); | ||
1038 | |||
1039 | - *shdr = grub_malloc ((grub_uint32_t) e->e_shnum * e->e_shentsize); | ||
1040 | + *shdr = grub_calloc (e->e_shnum, e->e_shentsize); | ||
1041 | if (! *shdr) | ||
1042 | return grub_errno; | ||
1043 | |||
1044 | diff --git a/grub-core/loader/i386/xnu.c b/grub-core/loader/i386/xnu.c | ||
1045 | index e64ed08..b7d176b 100644 | ||
1046 | --- a/grub-core/loader/i386/xnu.c | ||
1047 | +++ b/grub-core/loader/i386/xnu.c | ||
1048 | @@ -295,7 +295,7 @@ grub_xnu_devprop_add_property_utf8 (struct grub_xnu_devprop_device_descriptor *d | ||
1049 | return grub_errno; | ||
1050 | |||
1051 | len = grub_strlen (name); | ||
1052 | - utf16 = grub_malloc (sizeof (grub_uint16_t) * len); | ||
1053 | + utf16 = grub_calloc (len, sizeof (grub_uint16_t)); | ||
1054 | if (!utf16) | ||
1055 | { | ||
1056 | grub_free (utf8); | ||
1057 | @@ -331,7 +331,7 @@ grub_xnu_devprop_add_property_utf16 (struct grub_xnu_devprop_device_descriptor * | ||
1058 | grub_uint16_t *utf16; | ||
1059 | grub_err_t err; | ||
1060 | |||
1061 | - utf16 = grub_malloc (sizeof (grub_uint16_t) * namelen); | ||
1062 | + utf16 = grub_calloc (namelen, sizeof (grub_uint16_t)); | ||
1063 | if (!utf16) | ||
1064 | return grub_errno; | ||
1065 | grub_memcpy (utf16, name, sizeof (grub_uint16_t) * namelen); | ||
1066 | diff --git a/grub-core/loader/macho.c b/grub-core/loader/macho.c | ||
1067 | index 085f9c6..05710c4 100644 | ||
1068 | --- a/grub-core/loader/macho.c | ||
1069 | +++ b/grub-core/loader/macho.c | ||
1070 | @@ -97,7 +97,7 @@ grub_macho_file (grub_file_t file, const char *filename, int is_64bit) | ||
1071 | if (grub_file_seek (macho->file, sizeof (struct grub_macho_fat_header)) | ||
1072 | == (grub_off_t) -1) | ||
1073 | goto fail; | ||
1074 | - archs = grub_malloc (sizeof (struct grub_macho_fat_arch) * narchs); | ||
1075 | + archs = grub_calloc (narchs, sizeof (struct grub_macho_fat_arch)); | ||
1076 | if (!archs) | ||
1077 | goto fail; | ||
1078 | if (grub_file_read (macho->file, archs, | ||
1079 | diff --git a/grub-core/loader/multiboot_elfxx.c b/grub-core/loader/multiboot_elfxx.c | ||
1080 | index 70cd1db..cc68536 100644 | ||
1081 | --- a/grub-core/loader/multiboot_elfxx.c | ||
1082 | +++ b/grub-core/loader/multiboot_elfxx.c | ||
1083 | @@ -217,7 +217,7 @@ CONCAT(grub_multiboot_load_elf, XX) (mbi_load_data_t *mld) | ||
1084 | { | ||
1085 | grub_uint8_t *shdr, *shdrptr; | ||
1086 | |||
1087 | - shdr = grub_malloc ((grub_uint32_t) ehdr->e_shnum * ehdr->e_shentsize); | ||
1088 | + shdr = grub_calloc (ehdr->e_shnum, ehdr->e_shentsize); | ||
1089 | if (!shdr) | ||
1090 | return grub_errno; | ||
1091 | |||
1092 | diff --git a/grub-core/loader/xnu.c b/grub-core/loader/xnu.c | ||
1093 | index 7f74d1d..77d7060 100644 | ||
1094 | --- a/grub-core/loader/xnu.c | ||
1095 | +++ b/grub-core/loader/xnu.c | ||
1096 | @@ -800,7 +800,7 @@ grub_cmd_xnu_mkext (grub_command_t cmd __attribute__ ((unused)), | ||
1097 | if (grub_be_to_cpu32 (head.magic) == GRUB_MACHO_FAT_MAGIC) | ||
1098 | { | ||
1099 | narchs = grub_be_to_cpu32 (head.nfat_arch); | ||
1100 | - archs = grub_malloc (sizeof (struct grub_macho_fat_arch) * narchs); | ||
1101 | + archs = grub_calloc (narchs, sizeof (struct grub_macho_fat_arch)); | ||
1102 | if (! archs) | ||
1103 | { | ||
1104 | grub_file_close (file); | ||
1105 | diff --git a/grub-core/mmap/mmap.c b/grub-core/mmap/mmap.c | ||
1106 | index 6a31cba..57b4e9a 100644 | ||
1107 | --- a/grub-core/mmap/mmap.c | ||
1108 | +++ b/grub-core/mmap/mmap.c | ||
1109 | @@ -143,9 +143,9 @@ grub_mmap_iterate (grub_memory_hook_t hook, void *hook_data) | ||
1110 | |||
1111 | /* Initialize variables. */ | ||
1112 | ctx.scanline_events = (struct grub_mmap_scan *) | ||
1113 | - grub_malloc (sizeof (struct grub_mmap_scan) * 2 * mmap_num); | ||
1114 | + grub_calloc (mmap_num, sizeof (struct grub_mmap_scan) * 2); | ||
1115 | |||
1116 | - present = grub_zalloc (sizeof (present[0]) * current_priority); | ||
1117 | + present = grub_calloc (current_priority, sizeof (present[0])); | ||
1118 | |||
1119 | if (! ctx.scanline_events || !present) | ||
1120 | { | ||
1121 | diff --git a/grub-core/net/bootp.c b/grub-core/net/bootp.c | ||
1122 | index 04cfbb0..6539572 100644 | ||
1123 | --- a/grub-core/net/bootp.c | ||
1124 | +++ b/grub-core/net/bootp.c | ||
1125 | @@ -766,7 +766,7 @@ grub_cmd_bootp (struct grub_command *cmd __attribute__ ((unused)), | ||
1126 | if (ncards == 0) | ||
1127 | return grub_error (GRUB_ERR_NET_NO_CARD, N_("no network card found")); | ||
1128 | |||
1129 | - ifaces = grub_zalloc (ncards * sizeof (ifaces[0])); | ||
1130 | + ifaces = grub_calloc (ncards, sizeof (ifaces[0])); | ||
1131 | if (!ifaces) | ||
1132 | return grub_errno; | ||
1133 | |||
1134 | diff --git a/grub-core/net/dns.c b/grub-core/net/dns.c | ||
1135 | index 5d9afe0..e332d5e 100644 | ||
1136 | --- a/grub-core/net/dns.c | ||
1137 | +++ b/grub-core/net/dns.c | ||
1138 | @@ -285,8 +285,8 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)), | ||
1139 | ptr++; | ||
1140 | ptr += 4; | ||
1141 | } | ||
1142 | - *data->addresses = grub_malloc (sizeof ((*data->addresses)[0]) | ||
1143 | - * grub_be_to_cpu16 (head->ancount)); | ||
1144 | + *data->addresses = grub_calloc (grub_be_to_cpu16 (head->ancount), | ||
1145 | + sizeof ((*data->addresses)[0])); | ||
1146 | if (!*data->addresses) | ||
1147 | { | ||
1148 | grub_errno = GRUB_ERR_NONE; | ||
1149 | @@ -406,8 +406,8 @@ recv_hook (grub_net_udp_socket_t sock __attribute__ ((unused)), | ||
1150 | dns_cache[h].addresses = 0; | ||
1151 | dns_cache[h].name = grub_strdup (data->oname); | ||
1152 | dns_cache[h].naddresses = *data->naddresses; | ||
1153 | - dns_cache[h].addresses = grub_malloc (*data->naddresses | ||
1154 | - * sizeof (dns_cache[h].addresses[0])); | ||
1155 | + dns_cache[h].addresses = grub_calloc (*data->naddresses, | ||
1156 | + sizeof (dns_cache[h].addresses[0])); | ||
1157 | dns_cache[h].limit_time = grub_get_time_ms () + 1000 * ttl_all; | ||
1158 | if (!dns_cache[h].addresses || !dns_cache[h].name) | ||
1159 | { | ||
1160 | @@ -479,7 +479,7 @@ grub_net_dns_lookup (const char *name, | ||
1161 | } | ||
1162 | } | ||
1163 | |||
1164 | - sockets = grub_malloc (sizeof (sockets[0]) * n_servers); | ||
1165 | + sockets = grub_calloc (n_servers, sizeof (sockets[0])); | ||
1166 | if (!sockets) | ||
1167 | return grub_errno; | ||
1168 | |||
1169 | diff --git a/grub-core/net/net.c b/grub-core/net/net.c | ||
1170 | index d5d726a..38f19df 100644 | ||
1171 | --- a/grub-core/net/net.c | ||
1172 | +++ b/grub-core/net/net.c | ||
1173 | @@ -333,8 +333,8 @@ grub_cmd_ipv6_autoconf (struct grub_command *cmd __attribute__ ((unused)), | ||
1174 | ncards++; | ||
1175 | } | ||
1176 | |||
1177 | - ifaces = grub_zalloc (ncards * sizeof (ifaces[0])); | ||
1178 | - slaacs = grub_zalloc (ncards * sizeof (slaacs[0])); | ||
1179 | + ifaces = grub_calloc (ncards, sizeof (ifaces[0])); | ||
1180 | + slaacs = grub_calloc (ncards, sizeof (slaacs[0])); | ||
1181 | if (!ifaces || !slaacs) | ||
1182 | { | ||
1183 | grub_free (ifaces); | ||
1184 | diff --git a/grub-core/normal/charset.c b/grub-core/normal/charset.c | ||
1185 | index b0ab47d..d57fb72 100644 | ||
1186 | --- a/grub-core/normal/charset.c | ||
1187 | +++ b/grub-core/normal/charset.c | ||
1188 | @@ -203,7 +203,7 @@ grub_utf8_to_ucs4_alloc (const char *msg, grub_uint32_t **unicode_msg, | ||
1189 | { | ||
1190 | grub_size_t msg_len = grub_strlen (msg); | ||
1191 | |||
1192 | - *unicode_msg = grub_malloc (msg_len * sizeof (grub_uint32_t)); | ||
1193 | + *unicode_msg = grub_calloc (msg_len, sizeof (grub_uint32_t)); | ||
1194 | |||
1195 | if (!*unicode_msg) | ||
1196 | return -1; | ||
1197 | @@ -488,7 +488,7 @@ grub_unicode_aglomerate_comb (const grub_uint32_t *in, grub_size_t inlen, | ||
1198 | } | ||
1199 | else | ||
1200 | { | ||
1201 | - n = grub_malloc (sizeof (n[0]) * (out->ncomb + 1)); | ||
1202 | + n = grub_calloc (out->ncomb + 1, sizeof (n[0])); | ||
1203 | if (!n) | ||
1204 | { | ||
1205 | grub_errno = GRUB_ERR_NONE; | ||
1206 | @@ -842,7 +842,7 @@ grub_bidi_line_logical_to_visual (const grub_uint32_t *logical, | ||
1207 | } \ | ||
1208 | } | ||
1209 | |||
1210 | - visual = grub_malloc (sizeof (visual[0]) * logical_len); | ||
1211 | + visual = grub_calloc (logical_len, sizeof (visual[0])); | ||
1212 | if (!visual) | ||
1213 | return -1; | ||
1214 | |||
1215 | @@ -1165,8 +1165,8 @@ grub_bidi_logical_to_visual (const grub_uint32_t *logical, | ||
1216 | { | ||
1217 | const grub_uint32_t *line_start = logical, *ptr; | ||
1218 | struct grub_unicode_glyph *visual_ptr; | ||
1219 | - *visual_out = visual_ptr = grub_malloc (3 * sizeof (visual_ptr[0]) | ||
1220 | - * (logical_len + 2)); | ||
1221 | + *visual_out = visual_ptr = grub_calloc (logical_len + 2, | ||
1222 | + 3 * sizeof (visual_ptr[0])); | ||
1223 | if (!visual_ptr) | ||
1224 | return -1; | ||
1225 | for (ptr = logical; ptr <= logical + logical_len; ptr++) | ||
1226 | diff --git a/grub-core/normal/cmdline.c b/grub-core/normal/cmdline.c | ||
1227 | index c037d50..c57242e 100644 | ||
1228 | --- a/grub-core/normal/cmdline.c | ||
1229 | +++ b/grub-core/normal/cmdline.c | ||
1230 | @@ -41,7 +41,7 @@ grub_err_t | ||
1231 | grub_set_history (int newsize) | ||
1232 | { | ||
1233 | grub_uint32_t **old_hist_lines = hist_lines; | ||
1234 | - hist_lines = grub_malloc (sizeof (grub_uint32_t *) * newsize); | ||
1235 | + hist_lines = grub_calloc (newsize, sizeof (grub_uint32_t *)); | ||
1236 | |||
1237 | /* Copy the old lines into the new buffer. */ | ||
1238 | if (old_hist_lines) | ||
1239 | @@ -114,7 +114,7 @@ static void | ||
1240 | grub_history_set (int pos, grub_uint32_t *s, grub_size_t len) | ||
1241 | { | ||
1242 | grub_free (hist_lines[pos]); | ||
1243 | - hist_lines[pos] = grub_malloc ((len + 1) * sizeof (grub_uint32_t)); | ||
1244 | + hist_lines[pos] = grub_calloc (len + 1, sizeof (grub_uint32_t)); | ||
1245 | if (!hist_lines[pos]) | ||
1246 | { | ||
1247 | grub_print_error (); | ||
1248 | @@ -349,7 +349,7 @@ grub_cmdline_get (const char *prompt_translated) | ||
1249 | char *ret; | ||
1250 | unsigned nterms; | ||
1251 | |||
1252 | - buf = grub_malloc (max_len * sizeof (grub_uint32_t)); | ||
1253 | + buf = grub_calloc (max_len, sizeof (grub_uint32_t)); | ||
1254 | if (!buf) | ||
1255 | return 0; | ||
1256 | |||
1257 | @@ -377,7 +377,7 @@ grub_cmdline_get (const char *prompt_translated) | ||
1258 | FOR_ACTIVE_TERM_OUTPUTS(cur) | ||
1259 | nterms++; | ||
1260 | |||
1261 | - cl_terms = grub_malloc (sizeof (cl_terms[0]) * nterms); | ||
1262 | + cl_terms = grub_calloc (nterms, sizeof (cl_terms[0])); | ||
1263 | if (!cl_terms) | ||
1264 | { | ||
1265 | grub_free (buf); | ||
1266 | @@ -385,7 +385,7 @@ grub_cmdline_get (const char *prompt_translated) | ||
1267 | } | ||
1268 | cl_term_cur = cl_terms; | ||
1269 | |||
1270 | - unicode_msg = grub_malloc (msg_len * sizeof (grub_uint32_t)); | ||
1271 | + unicode_msg = grub_calloc (msg_len, sizeof (grub_uint32_t)); | ||
1272 | if (!unicode_msg) | ||
1273 | { | ||
1274 | grub_free (buf); | ||
1275 | @@ -495,7 +495,7 @@ grub_cmdline_get (const char *prompt_translated) | ||
1276 | grub_uint32_t *insert; | ||
1277 | |||
1278 | insertlen = grub_strlen (insertu8); | ||
1279 | - insert = grub_malloc ((insertlen + 1) * sizeof (grub_uint32_t)); | ||
1280 | + insert = grub_calloc (insertlen + 1, sizeof (grub_uint32_t)); | ||
1281 | if (!insert) | ||
1282 | { | ||
1283 | grub_free (insertu8); | ||
1284 | @@ -602,7 +602,7 @@ grub_cmdline_get (const char *prompt_translated) | ||
1285 | |||
1286 | grub_free (kill_buf); | ||
1287 | |||
1288 | - kill_buf = grub_malloc ((n + 1) * sizeof(grub_uint32_t)); | ||
1289 | + kill_buf = grub_calloc (n + 1, sizeof (grub_uint32_t)); | ||
1290 | if (grub_errno) | ||
1291 | { | ||
1292 | grub_print_error (); | ||
1293 | diff --git a/grub-core/normal/menu_entry.c b/grub-core/normal/menu_entry.c | ||
1294 | index cdf3590..1993995 100644 | ||
1295 | --- a/grub-core/normal/menu_entry.c | ||
1296 | +++ b/grub-core/normal/menu_entry.c | ||
1297 | @@ -95,8 +95,8 @@ init_line (struct screen *screen, struct line *linep) | ||
1298 | { | ||
1299 | linep->len = 0; | ||
1300 | linep->max_len = 80; | ||
1301 | - linep->buf = grub_malloc ((linep->max_len + 1) * sizeof (linep->buf[0])); | ||
1302 | - linep->pos = grub_zalloc (screen->nterms * sizeof (linep->pos[0])); | ||
1303 | + linep->buf = grub_calloc (linep->max_len + 1, sizeof (linep->buf[0])); | ||
1304 | + linep->pos = grub_calloc (screen->nterms, sizeof (linep->pos[0])); | ||
1305 | if (! linep->buf || !linep->pos) | ||
1306 | { | ||
1307 | grub_free (linep->buf); | ||
1308 | @@ -287,7 +287,7 @@ update_screen (struct screen *screen, struct per_term_screen *term_screen, | ||
1309 | pos = linep->pos + (term_screen - screen->terms); | ||
1310 | |||
1311 | if (!*pos) | ||
1312 | - *pos = grub_zalloc ((linep->len + 1) * sizeof (**pos)); | ||
1313 | + *pos = grub_calloc (linep->len + 1, sizeof (**pos)); | ||
1314 | |||
1315 | if (i == region_start || linep == screen->lines + screen->line | ||
1316 | || (i > region_start && mode == ALL_LINES)) | ||
1317 | @@ -471,7 +471,7 @@ insert_string (struct screen *screen, const char *s, int update) | ||
1318 | |||
1319 | /* Insert the string. */ | ||
1320 | current_linep = screen->lines + screen->line; | ||
1321 | - unicode_msg = grub_malloc ((p - s) * sizeof (grub_uint32_t)); | ||
1322 | + unicode_msg = grub_calloc (p - s, sizeof (grub_uint32_t)); | ||
1323 | |||
1324 | if (!unicode_msg) | ||
1325 | return 0; | ||
1326 | @@ -1023,7 +1023,7 @@ complete (struct screen *screen, int continuous, int update) | ||
1327 | if (completion_buffer.buf) | ||
1328 | { | ||
1329 | buflen = grub_strlen (completion_buffer.buf); | ||
1330 | - ucs4 = grub_malloc (sizeof (grub_uint32_t) * (buflen + 1)); | ||
1331 | + ucs4 = grub_calloc (buflen + 1, sizeof (grub_uint32_t)); | ||
1332 | |||
1333 | if (!ucs4) | ||
1334 | { | ||
1335 | @@ -1268,7 +1268,7 @@ grub_menu_entry_run (grub_menu_entry_t entry) | ||
1336 | for (i = 0; i < (unsigned) screen->num_lines; i++) | ||
1337 | { | ||
1338 | grub_free (screen->lines[i].pos); | ||
1339 | - screen->lines[i].pos = grub_zalloc (screen->nterms * sizeof (screen->lines[i].pos[0])); | ||
1340 | + screen->lines[i].pos = grub_calloc (screen->nterms, sizeof (screen->lines[i].pos[0])); | ||
1341 | if (! screen->lines[i].pos) | ||
1342 | { | ||
1343 | grub_print_error (); | ||
1344 | @@ -1278,7 +1278,7 @@ grub_menu_entry_run (grub_menu_entry_t entry) | ||
1345 | } | ||
1346 | } | ||
1347 | |||
1348 | - screen->terms = grub_zalloc (screen->nterms * sizeof (screen->terms[0])); | ||
1349 | + screen->terms = grub_calloc (screen->nterms, sizeof (screen->terms[0])); | ||
1350 | if (!screen->terms) | ||
1351 | { | ||
1352 | grub_print_error (); | ||
1353 | diff --git a/grub-core/normal/menu_text.c b/grub-core/normal/menu_text.c | ||
1354 | index e22bb91..18240e7 100644 | ||
1355 | --- a/grub-core/normal/menu_text.c | ||
1356 | +++ b/grub-core/normal/menu_text.c | ||
1357 | @@ -78,7 +78,7 @@ grub_print_message_indented_real (const char *msg, int margin_left, | ||
1358 | grub_size_t msg_len = grub_strlen (msg) + 2; | ||
1359 | int ret = 0; | ||
1360 | |||
1361 | - unicode_msg = grub_malloc (msg_len * sizeof (grub_uint32_t)); | ||
1362 | + unicode_msg = grub_calloc (msg_len, sizeof (grub_uint32_t)); | ||
1363 | |||
1364 | if (!unicode_msg) | ||
1365 | return 0; | ||
1366 | @@ -211,7 +211,7 @@ print_entry (int y, int highlight, grub_menu_entry_t entry, | ||
1367 | |||
1368 | title = entry ? entry->title : ""; | ||
1369 | title_len = grub_strlen (title); | ||
1370 | - unicode_title = grub_malloc (title_len * sizeof (*unicode_title)); | ||
1371 | + unicode_title = grub_calloc (title_len, sizeof (*unicode_title)); | ||
1372 | if (! unicode_title) | ||
1373 | /* XXX How to show this error? */ | ||
1374 | return; | ||
1375 | diff --git a/grub-core/normal/term.c b/grub-core/normal/term.c | ||
1376 | index a1e5c5a..cc8c173 100644 | ||
1377 | --- a/grub-core/normal/term.c | ||
1378 | +++ b/grub-core/normal/term.c | ||
1379 | @@ -264,7 +264,7 @@ grub_term_save_pos (void) | ||
1380 | FOR_ACTIVE_TERM_OUTPUTS(cur) | ||
1381 | cnt++; | ||
1382 | |||
1383 | - ret = grub_malloc (cnt * sizeof (ret[0])); | ||
1384 | + ret = grub_calloc (cnt, sizeof (ret[0])); | ||
1385 | if (!ret) | ||
1386 | return NULL; | ||
1387 | |||
1388 | @@ -1013,7 +1013,7 @@ grub_xnputs (const char *str, grub_size_t msg_len) | ||
1389 | |||
1390 | grub_error_push (); | ||
1391 | |||
1392 | - unicode_str = grub_malloc (msg_len * sizeof (grub_uint32_t)); | ||
1393 | + unicode_str = grub_calloc (msg_len, sizeof (grub_uint32_t)); | ||
1394 | |||
1395 | grub_error_pop (); | ||
1396 | |||
1397 | diff --git a/grub-core/osdep/linux/getroot.c b/grub-core/osdep/linux/getroot.c | ||
1398 | index 90d92d3..5b41ad0 100644 | ||
1399 | --- a/grub-core/osdep/linux/getroot.c | ||
1400 | +++ b/grub-core/osdep/linux/getroot.c | ||
1401 | @@ -168,7 +168,7 @@ grub_util_raid_getmembers (const char *name, int bootable) | ||
1402 | if (ret != 0) | ||
1403 | grub_util_error (_("ioctl GET_ARRAY_INFO error: %s"), strerror (errno)); | ||
1404 | |||
1405 | - devicelist = xmalloc ((info.nr_disks + 1) * sizeof (char *)); | ||
1406 | + devicelist = xcalloc (info.nr_disks + 1, sizeof (char *)); | ||
1407 | |||
1408 | for (i = 0, j = 0; j < info.nr_disks; i++) | ||
1409 | { | ||
1410 | @@ -241,7 +241,7 @@ grub_find_root_devices_from_btrfs (const char *dir) | ||
1411 | return NULL; | ||
1412 | } | ||
1413 | |||
1414 | - ret = xmalloc ((fsi.num_devices + 1) * sizeof (ret[0])); | ||
1415 | + ret = xcalloc (fsi.num_devices + 1, sizeof (ret[0])); | ||
1416 | |||
1417 | for (i = 1; i <= fsi.max_id && j < fsi.num_devices; i++) | ||
1418 | { | ||
1419 | @@ -396,7 +396,7 @@ grub_find_root_devices_from_mountinfo (const char *dir, char **relroot) | ||
1420 | if (relroot) | ||
1421 | *relroot = NULL; | ||
1422 | |||
1423 | - entries = xmalloc (entry_max * sizeof (*entries)); | ||
1424 | + entries = xcalloc (entry_max, sizeof (*entries)); | ||
1425 | |||
1426 | again: | ||
1427 | fp = grub_util_fopen ("/proc/self/mountinfo", "r"); | ||
1428 | diff --git a/grub-core/osdep/unix/config.c b/grub-core/osdep/unix/config.c | ||
1429 | index 65effa9..7d63251 100644 | ||
1430 | --- a/grub-core/osdep/unix/config.c | ||
1431 | +++ b/grub-core/osdep/unix/config.c | ||
1432 | @@ -89,7 +89,7 @@ grub_util_load_config (struct grub_util_config *cfg) | ||
1433 | argv[0] = "sh"; | ||
1434 | argv[1] = "-c"; | ||
1435 | |||
1436 | - script = xmalloc (4 * strlen (cfgfile) + 300); | ||
1437 | + script = xcalloc (4, strlen (cfgfile) + 300); | ||
1438 | |||
1439 | ptr = script; | ||
1440 | memcpy (ptr, ". '", 3); | ||
1441 | diff --git a/grub-core/osdep/windows/getroot.c b/grub-core/osdep/windows/getroot.c | ||
1442 | index 661d954..eada663 100644 | ||
1443 | --- a/grub-core/osdep/windows/getroot.c | ||
1444 | +++ b/grub-core/osdep/windows/getroot.c | ||
1445 | @@ -59,7 +59,7 @@ grub_get_mount_point (const TCHAR *path) | ||
1446 | |||
1447 | for (ptr = path; *ptr; ptr++); | ||
1448 | allocsize = (ptr - path + 10) * 2; | ||
1449 | - out = xmalloc (allocsize * sizeof (out[0])); | ||
1450 | + out = xcalloc (allocsize, sizeof (out[0])); | ||
1451 | |||
1452 | /* When pointing to EFI system partition GetVolumePathName fails | ||
1453 | for ESP root and returns abberant information for everything | ||
1454 | diff --git a/grub-core/osdep/windows/hostdisk.c b/grub-core/osdep/windows/hostdisk.c | ||
1455 | index 3551007..0be3273 100644 | ||
1456 | --- a/grub-core/osdep/windows/hostdisk.c | ||
1457 | +++ b/grub-core/osdep/windows/hostdisk.c | ||
1458 | @@ -111,7 +111,7 @@ grub_util_get_windows_path_real (const char *path) | ||
1459 | |||
1460 | while (1) | ||
1461 | { | ||
1462 | - fpa = xmalloc (alloc * sizeof (fpa[0])); | ||
1463 | + fpa = xcalloc (alloc, sizeof (fpa[0])); | ||
1464 | |||
1465 | len = GetFullPathName (tpath, alloc, fpa, NULL); | ||
1466 | if (len >= alloc) | ||
1467 | @@ -399,7 +399,7 @@ grub_util_fd_opendir (const char *name) | ||
1468 | for (l = 0; name_windows[l]; l++); | ||
1469 | for (l--; l >= 0 && (name_windows[l] == '\\' || name_windows[l] == '/'); l--); | ||
1470 | l++; | ||
1471 | - pattern = xmalloc ((l + 3) * sizeof (pattern[0])); | ||
1472 | + pattern = xcalloc (l + 3, sizeof (pattern[0])); | ||
1473 | memcpy (pattern, name_windows, l * sizeof (pattern[0])); | ||
1474 | pattern[l] = '\\'; | ||
1475 | pattern[l + 1] = '*'; | ||
1476 | diff --git a/grub-core/osdep/windows/init.c b/grub-core/osdep/windows/init.c | ||
1477 | index e8ffd62..6297de6 100644 | ||
1478 | --- a/grub-core/osdep/windows/init.c | ||
1479 | +++ b/grub-core/osdep/windows/init.c | ||
1480 | @@ -161,7 +161,7 @@ grub_util_host_init (int *argc __attribute__ ((unused)), | ||
1481 | LPWSTR *targv; | ||
1482 | |||
1483 | targv = CommandLineToArgvW (tcmdline, argc); | ||
1484 | - *argv = xmalloc ((*argc + 1) * sizeof (argv[0])); | ||
1485 | + *argv = xcalloc (*argc + 1, sizeof (argv[0])); | ||
1486 | |||
1487 | for (i = 0; i < *argc; i++) | ||
1488 | (*argv)[i] = grub_util_tchar_to_utf8 (targv[i]); | ||
1489 | diff --git a/grub-core/osdep/windows/platform.c b/grub-core/osdep/windows/platform.c | ||
1490 | index 7eb53fe..1ef86bf 100644 | ||
1491 | --- a/grub-core/osdep/windows/platform.c | ||
1492 | +++ b/grub-core/osdep/windows/platform.c | ||
1493 | @@ -225,8 +225,8 @@ grub_install_register_efi (grub_device_t efidir_grub_dev, | ||
1494 | grub_util_error ("%s", _("no EFI routines are available when running in BIOS mode")); | ||
1495 | |||
1496 | distrib8_len = grub_strlen (efi_distributor); | ||
1497 | - distributor16 = xmalloc ((distrib8_len + 1) * GRUB_MAX_UTF16_PER_UTF8 | ||
1498 | - * sizeof (grub_uint16_t)); | ||
1499 | + distributor16 = xcalloc (distrib8_len + 1, | ||
1500 | + GRUB_MAX_UTF16_PER_UTF8 * sizeof (grub_uint16_t)); | ||
1501 | distrib16_len = grub_utf8_to_utf16 (distributor16, distrib8_len * GRUB_MAX_UTF16_PER_UTF8, | ||
1502 | (const grub_uint8_t *) efi_distributor, | ||
1503 | distrib8_len, 0); | ||
1504 | diff --git a/grub-core/osdep/windows/relpath.c b/grub-core/osdep/windows/relpath.c | ||
1505 | index cb08617..478e8ef 100644 | ||
1506 | --- a/grub-core/osdep/windows/relpath.c | ||
1507 | +++ b/grub-core/osdep/windows/relpath.c | ||
1508 | @@ -72,7 +72,7 @@ grub_make_system_path_relative_to_its_root (const char *path) | ||
1509 | if (dirwindows[0] && dirwindows[1] == ':') | ||
1510 | offset = 2; | ||
1511 | } | ||
1512 | - ret = xmalloc (sizeof (ret[0]) * (flen - offset + 2)); | ||
1513 | + ret = xcalloc (flen - offset + 2, sizeof (ret[0])); | ||
1514 | if (dirwindows[offset] != '\\' | ||
1515 | && dirwindows[offset] != '/' | ||
1516 | && dirwindows[offset]) | ||
1517 | diff --git a/grub-core/partmap/gpt.c b/grub-core/partmap/gpt.c | ||
1518 | index 103f679..72a2e37 100644 | ||
1519 | --- a/grub-core/partmap/gpt.c | ||
1520 | +++ b/grub-core/partmap/gpt.c | ||
1521 | @@ -199,7 +199,7 @@ gpt_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors, | ||
1522 | *nsectors = ctx.len; | ||
1523 | if (*nsectors > max_nsectors) | ||
1524 | *nsectors = max_nsectors; | ||
1525 | - *sectors = grub_malloc (*nsectors * sizeof (**sectors)); | ||
1526 | + *sectors = grub_calloc (*nsectors, sizeof (**sectors)); | ||
1527 | if (!*sectors) | ||
1528 | return grub_errno; | ||
1529 | for (i = 0; i < *nsectors; i++) | ||
1530 | diff --git a/grub-core/partmap/msdos.c b/grub-core/partmap/msdos.c | ||
1531 | index 7b8e450..ee3f249 100644 | ||
1532 | --- a/grub-core/partmap/msdos.c | ||
1533 | +++ b/grub-core/partmap/msdos.c | ||
1534 | @@ -337,7 +337,7 @@ pc_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors, | ||
1535 | avail_nsectors = *nsectors; | ||
1536 | if (*nsectors > max_nsectors) | ||
1537 | *nsectors = max_nsectors; | ||
1538 | - *sectors = grub_malloc (*nsectors * sizeof (**sectors)); | ||
1539 | + *sectors = grub_calloc (*nsectors, sizeof (**sectors)); | ||
1540 | if (!*sectors) | ||
1541 | return grub_errno; | ||
1542 | for (i = 0; i < *nsectors; i++) | ||
1543 | diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c | ||
1544 | index ee299fd..c8d6806 100644 | ||
1545 | --- a/grub-core/script/execute.c | ||
1546 | +++ b/grub-core/script/execute.c | ||
1547 | @@ -553,7 +553,7 @@ gettext_append (struct grub_script_argv *result, const char *orig_str) | ||
1548 | for (iptr = orig_str; *iptr; iptr++) | ||
1549 | if (*iptr == '$') | ||
1550 | dollar_cnt++; | ||
1551 | - ctx.allowed_strings = grub_malloc (sizeof (ctx.allowed_strings[0]) * dollar_cnt); | ||
1552 | + ctx.allowed_strings = grub_calloc (dollar_cnt, sizeof (ctx.allowed_strings[0])); | ||
1553 | |||
1554 | if (parse_string (orig_str, gettext_save_allow, &ctx, 0)) | ||
1555 | goto fail; | ||
1556 | diff --git a/grub-core/tests/fake_input.c b/grub-core/tests/fake_input.c | ||
1557 | index 2d60852..b5eb516 100644 | ||
1558 | --- a/grub-core/tests/fake_input.c | ||
1559 | +++ b/grub-core/tests/fake_input.c | ||
1560 | @@ -49,7 +49,7 @@ grub_terminal_input_fake_sequence (int *seq_in, int nseq_in) | ||
1561 | saved = grub_term_inputs; | ||
1562 | if (seq) | ||
1563 | grub_free (seq); | ||
1564 | - seq = grub_malloc (nseq_in * sizeof (seq[0])); | ||
1565 | + seq = grub_calloc (nseq_in, sizeof (seq[0])); | ||
1566 | if (!seq) | ||
1567 | return; | ||
1568 | |||
1569 | diff --git a/grub-core/tests/video_checksum.c b/grub-core/tests/video_checksum.c | ||
1570 | index 74d5b65..44d0810 100644 | ||
1571 | --- a/grub-core/tests/video_checksum.c | ||
1572 | +++ b/grub-core/tests/video_checksum.c | ||
1573 | @@ -336,7 +336,7 @@ grub_video_capture_write_bmp (const char *fname, | ||
1574 | { | ||
1575 | case 4: | ||
1576 | { | ||
1577 | - grub_uint8_t *buffer = xmalloc (mode_info->width * 3); | ||
1578 | + grub_uint8_t *buffer = xcalloc (3, mode_info->width); | ||
1579 | grub_uint32_t rmask = ((1 << mode_info->red_mask_size) - 1); | ||
1580 | grub_uint32_t gmask = ((1 << mode_info->green_mask_size) - 1); | ||
1581 | grub_uint32_t bmask = ((1 << mode_info->blue_mask_size) - 1); | ||
1582 | @@ -367,7 +367,7 @@ grub_video_capture_write_bmp (const char *fname, | ||
1583 | } | ||
1584 | case 3: | ||
1585 | { | ||
1586 | - grub_uint8_t *buffer = xmalloc (mode_info->width * 3); | ||
1587 | + grub_uint8_t *buffer = xcalloc (3, mode_info->width); | ||
1588 | grub_uint32_t rmask = ((1 << mode_info->red_mask_size) - 1); | ||
1589 | grub_uint32_t gmask = ((1 << mode_info->green_mask_size) - 1); | ||
1590 | grub_uint32_t bmask = ((1 << mode_info->blue_mask_size) - 1); | ||
1591 | @@ -407,7 +407,7 @@ grub_video_capture_write_bmp (const char *fname, | ||
1592 | } | ||
1593 | case 2: | ||
1594 | { | ||
1595 | - grub_uint8_t *buffer = xmalloc (mode_info->width * 3); | ||
1596 | + grub_uint8_t *buffer = xcalloc (3, mode_info->width); | ||
1597 | grub_uint16_t rmask = ((1 << mode_info->red_mask_size) - 1); | ||
1598 | grub_uint16_t gmask = ((1 << mode_info->green_mask_size) - 1); | ||
1599 | grub_uint16_t bmask = ((1 << mode_info->blue_mask_size) - 1); | ||
1600 | diff --git a/grub-core/video/capture.c b/grub-core/video/capture.c | ||
1601 | index 4f83c74..4d3195e 100644 | ||
1602 | --- a/grub-core/video/capture.c | ||
1603 | +++ b/grub-core/video/capture.c | ||
1604 | @@ -89,7 +89,7 @@ grub_video_capture_start (const struct grub_video_mode_info *mode_info, | ||
1605 | framebuffer.mode_info = *mode_info; | ||
1606 | framebuffer.mode_info.blit_format = grub_video_get_blit_format (&framebuffer.mode_info); | ||
1607 | |||
1608 | - framebuffer.ptr = grub_malloc (framebuffer.mode_info.height * framebuffer.mode_info.pitch); | ||
1609 | + framebuffer.ptr = grub_calloc (framebuffer.mode_info.height, framebuffer.mode_info.pitch); | ||
1610 | if (!framebuffer.ptr) | ||
1611 | return grub_errno; | ||
1612 | |||
1613 | diff --git a/grub-core/video/emu/sdl.c b/grub-core/video/emu/sdl.c | ||
1614 | index a2f639f..0ebab6f 100644 | ||
1615 | --- a/grub-core/video/emu/sdl.c | ||
1616 | +++ b/grub-core/video/emu/sdl.c | ||
1617 | @@ -172,7 +172,7 @@ grub_video_sdl_set_palette (unsigned int start, unsigned int count, | ||
1618 | if (start + count > mode_info.number_of_colors) | ||
1619 | count = mode_info.number_of_colors - start; | ||
1620 | |||
1621 | - tmp = grub_malloc (count * sizeof (tmp[0])); | ||
1622 | + tmp = grub_calloc (count, sizeof (tmp[0])); | ||
1623 | for (i = 0; i < count; i++) | ||
1624 | { | ||
1625 | tmp[i].r = palette_data[i].r; | ||
1626 | diff --git a/grub-core/video/i386/pc/vga.c b/grub-core/video/i386/pc/vga.c | ||
1627 | index 01f4711..b2f776c 100644 | ||
1628 | --- a/grub-core/video/i386/pc/vga.c | ||
1629 | +++ b/grub-core/video/i386/pc/vga.c | ||
1630 | @@ -127,7 +127,7 @@ grub_video_vga_setup (unsigned int width, unsigned int height, | ||
1631 | |||
1632 | vga_height = height ? : 480; | ||
1633 | |||
1634 | - framebuffer.temporary_buffer = grub_malloc (vga_height * VGA_WIDTH); | ||
1635 | + framebuffer.temporary_buffer = grub_calloc (vga_height, VGA_WIDTH); | ||
1636 | framebuffer.front_page = 0; | ||
1637 | framebuffer.back_page = 0; | ||
1638 | if (!framebuffer.temporary_buffer) | ||
1639 | diff --git a/grub-core/video/readers/png.c b/grub-core/video/readers/png.c | ||
1640 | index 777e713..61bd645 100644 | ||
1641 | --- a/grub-core/video/readers/png.c | ||
1642 | +++ b/grub-core/video/readers/png.c | ||
1643 | @@ -309,7 +309,7 @@ grub_png_decode_image_header (struct grub_png_data *data) | ||
1644 | if (data->is_16bit || data->is_gray || data->is_palette) | ||
1645 | #endif | ||
1646 | { | ||
1647 | - data->image_data = grub_malloc (data->image_height * data->row_bytes); | ||
1648 | + data->image_data = grub_calloc (data->image_height, data->row_bytes); | ||
1649 | if (grub_errno) | ||
1650 | return grub_errno; | ||
1651 | |||
1652 | diff --git a/include/grub/unicode.h b/include/grub/unicode.h | ||
1653 | index a0403e9..4de986a 100644 | ||
1654 | --- a/include/grub/unicode.h | ||
1655 | +++ b/include/grub/unicode.h | ||
1656 | @@ -293,7 +293,7 @@ grub_unicode_glyph_dup (const struct grub_unicode_glyph *in) | ||
1657 | grub_memcpy (out, in, sizeof (*in)); | ||
1658 | if (in->ncomb > ARRAY_SIZE (out->combining_inline)) | ||
1659 | { | ||
1660 | - out->combining_ptr = grub_malloc (in->ncomb * sizeof (out->combining_ptr[0])); | ||
1661 | + out->combining_ptr = grub_calloc (in->ncomb, sizeof (out->combining_ptr[0])); | ||
1662 | if (!out->combining_ptr) | ||
1663 | { | ||
1664 | grub_free (out); | ||
1665 | @@ -315,7 +315,7 @@ grub_unicode_set_glyph (struct grub_unicode_glyph *out, | ||
1666 | grub_memcpy (out, in, sizeof (*in)); | ||
1667 | if (in->ncomb > ARRAY_SIZE (out->combining_inline)) | ||
1668 | { | ||
1669 | - out->combining_ptr = grub_malloc (in->ncomb * sizeof (out->combining_ptr[0])); | ||
1670 | + out->combining_ptr = grub_calloc (in->ncomb, sizeof (out->combining_ptr[0])); | ||
1671 | if (!out->combining_ptr) | ||
1672 | return; | ||
1673 | grub_memcpy (out->combining_ptr, in->combining_ptr, | ||
1674 | diff --git a/util/getroot.c b/util/getroot.c | ||
1675 | index 847406f..a5eaa64 100644 | ||
1676 | --- a/util/getroot.c | ||
1677 | +++ b/util/getroot.c | ||
1678 | @@ -200,7 +200,7 @@ make_device_name (const char *drive) | ||
1679 | char *ret, *ptr; | ||
1680 | const char *iptr; | ||
1681 | |||
1682 | - ret = xmalloc (strlen (drive) * 2); | ||
1683 | + ret = xcalloc (2, strlen (drive)); | ||
1684 | ptr = ret; | ||
1685 | for (iptr = drive; *iptr; iptr++) | ||
1686 | { | ||
1687 | diff --git a/util/grub-file.c b/util/grub-file.c | ||
1688 | index 50c18b6..b2e7dd6 100644 | ||
1689 | --- a/util/grub-file.c | ||
1690 | +++ b/util/grub-file.c | ||
1691 | @@ -54,7 +54,7 @@ main (int argc, char *argv[]) | ||
1692 | |||
1693 | grub_util_host_init (&argc, &argv); | ||
1694 | |||
1695 | - argv2 = xmalloc (argc * sizeof (argv2[0])); | ||
1696 | + argv2 = xcalloc (argc, sizeof (argv2[0])); | ||
1697 | |||
1698 | if (argc == 2 && strcmp (argv[1], "--version") == 0) | ||
1699 | { | ||
1700 | diff --git a/util/grub-fstest.c b/util/grub-fstest.c | ||
1701 | index f14e02d..57246af 100644 | ||
1702 | --- a/util/grub-fstest.c | ||
1703 | +++ b/util/grub-fstest.c | ||
1704 | @@ -650,7 +650,7 @@ argp_parser (int key, char *arg, struct argp_state *state) | ||
1705 | if (args_count < num_disks) | ||
1706 | { | ||
1707 | if (args_count == 0) | ||
1708 | - images = xmalloc (num_disks * sizeof (images[0])); | ||
1709 | + images = xcalloc (num_disks, sizeof (images[0])); | ||
1710 | images[args_count] = grub_canonicalize_file_name (arg); | ||
1711 | args_count++; | ||
1712 | return 0; | ||
1713 | @@ -734,7 +734,7 @@ main (int argc, char *argv[]) | ||
1714 | |||
1715 | grub_util_host_init (&argc, &argv); | ||
1716 | |||
1717 | - args = xmalloc (argc * sizeof (args[0])); | ||
1718 | + args = xcalloc (argc, sizeof (args[0])); | ||
1719 | |||
1720 | argp_parse (&argp, argc, argv, 0, 0, 0); | ||
1721 | |||
1722 | diff --git a/util/grub-install-common.c b/util/grub-install-common.c | ||
1723 | index ca0ac61..0295d40 100644 | ||
1724 | --- a/util/grub-install-common.c | ||
1725 | +++ b/util/grub-install-common.c | ||
1726 | @@ -286,7 +286,7 @@ handle_install_list (struct install_list *il, const char *val, | ||
1727 | il->n_entries++; | ||
1728 | } | ||
1729 | il->n_alloc = il->n_entries + 1; | ||
1730 | - il->entries = xmalloc (il->n_alloc * sizeof (il->entries[0])); | ||
1731 | + il->entries = xcalloc (il->n_alloc, sizeof (il->entries[0])); | ||
1732 | ptr = val; | ||
1733 | for (ce = il->entries; ; ce++) | ||
1734 | { | ||
1735 | diff --git a/util/grub-install.c b/util/grub-install.c | ||
1736 | index 8a55ad4..a82725f 100644 | ||
1737 | --- a/util/grub-install.c | ||
1738 | +++ b/util/grub-install.c | ||
1739 | @@ -626,7 +626,7 @@ device_map_check_duplicates (const char *dev_map) | ||
1740 | if (! fp) | ||
1741 | return; | ||
1742 | |||
1743 | - d = xmalloc (alloced * sizeof (d[0])); | ||
1744 | + d = xcalloc (alloced, sizeof (d[0])); | ||
1745 | |||
1746 | while (fgets (buf, sizeof (buf), fp)) | ||
1747 | { | ||
1748 | @@ -1260,7 +1260,7 @@ main (int argc, char *argv[]) | ||
1749 | ndev++; | ||
1750 | } | ||
1751 | |||
1752 | - grub_drives = xmalloc (sizeof (grub_drives[0]) * (ndev + 1)); | ||
1753 | + grub_drives = xcalloc (ndev + 1, sizeof (grub_drives[0])); | ||
1754 | |||
1755 | for (curdev = grub_devices, curdrive = grub_drives; *curdev; curdev++, | ||
1756 | curdrive++) | ||
1757 | diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c | ||
1758 | index bc087c2..d97d0e7 100644 | ||
1759 | --- a/util/grub-mkimagexx.c | ||
1760 | +++ b/util/grub-mkimagexx.c | ||
1761 | @@ -2294,10 +2294,8 @@ SUFFIX (grub_mkimage_load_image) (const char *kernel_path, | ||
1762 | + grub_host_to_target16 (e->e_shstrndx) * smd.section_entsize); | ||
1763 | smd.strtab = (char *) e + grub_host_to_target_addr (s->sh_offset); | ||
1764 | |||
1765 | - smd.addrs = xmalloc (sizeof (*smd.addrs) * smd.num_sections); | ||
1766 | - memset (smd.addrs, 0, sizeof (*smd.addrs) * smd.num_sections); | ||
1767 | - smd.vaddrs = xmalloc (sizeof (*smd.vaddrs) * smd.num_sections); | ||
1768 | - memset (smd.vaddrs, 0, sizeof (*smd.vaddrs) * smd.num_sections); | ||
1769 | + smd.addrs = xcalloc (smd.num_sections, sizeof (*smd.addrs)); | ||
1770 | + smd.vaddrs = xcalloc (smd.num_sections, sizeof (*smd.vaddrs)); | ||
1771 | |||
1772 | SUFFIX (locate_sections) (e, kernel_path, &smd, layout, image_target); | ||
1773 | |||
1774 | diff --git a/util/grub-mkrescue.c b/util/grub-mkrescue.c | ||
1775 | index ce2cbc4..5183102 100644 | ||
1776 | --- a/util/grub-mkrescue.c | ||
1777 | +++ b/util/grub-mkrescue.c | ||
1778 | @@ -441,8 +441,8 @@ main (int argc, char *argv[]) | ||
1779 | xorriso = xstrdup ("xorriso"); | ||
1780 | label_font = grub_util_path_concat (2, pkgdatadir, "unicode.pf2"); | ||
1781 | |||
1782 | - argp_argv = xmalloc (sizeof (argp_argv[0]) * argc); | ||
1783 | - xorriso_tail_argv = xmalloc (sizeof (argp_argv[0]) * argc); | ||
1784 | + argp_argv = xcalloc (argc, sizeof (argp_argv[0])); | ||
1785 | + xorriso_tail_argv = xcalloc (argc, sizeof (argp_argv[0])); | ||
1786 | |||
1787 | xorriso_tail_argc = 0; | ||
1788 | /* Program name */ | ||
1789 | diff --git a/util/grub-mkstandalone.c b/util/grub-mkstandalone.c | ||
1790 | index 4907d44..edf3097 100644 | ||
1791 | --- a/util/grub-mkstandalone.c | ||
1792 | +++ b/util/grub-mkstandalone.c | ||
1793 | @@ -296,7 +296,7 @@ main (int argc, char *argv[]) | ||
1794 | grub_util_host_init (&argc, &argv); | ||
1795 | grub_util_disable_fd_syncs (); | ||
1796 | |||
1797 | - files = xmalloc ((argc + 1) * sizeof (files[0])); | ||
1798 | + files = xcalloc (argc + 1, sizeof (files[0])); | ||
1799 | |||
1800 | argp_parse (&argp, argc, argv, 0, 0, 0); | ||
1801 | |||
1802 | diff --git a/util/grub-pe2elf.c b/util/grub-pe2elf.c | ||
1803 | index 0d4084a..1133129 100644 | ||
1804 | --- a/util/grub-pe2elf.c | ||
1805 | +++ b/util/grub-pe2elf.c | ||
1806 | @@ -100,9 +100,9 @@ write_section_data (FILE* fp, const char *name, char *image, | ||
1807 | char *pe_strtab = (image + pe_chdr->symtab_offset | ||
1808 | + pe_chdr->num_symbols * sizeof (struct grub_pe32_symbol)); | ||
1809 | |||
1810 | - section_map = xmalloc ((2 * pe_chdr->num_sections + 5) * sizeof (int)); | ||
1811 | + section_map = xcalloc (2 * pe_chdr->num_sections + 5, sizeof (int)); | ||
1812 | section_map[0] = 0; | ||
1813 | - shdr = xmalloc ((2 * pe_chdr->num_sections + 5) * sizeof (shdr[0])); | ||
1814 | + shdr = xcalloc (2 * pe_chdr->num_sections + 5, sizeof (shdr[0])); | ||
1815 | idx = 1; | ||
1816 | idx_reloc = pe_chdr->num_sections + 1; | ||
1817 | |||
1818 | @@ -233,7 +233,7 @@ write_reloc_section (FILE* fp, const char *name, char *image, | ||
1819 | |||
1820 | pe_sec = pe_shdr + shdr[i].sh_link; | ||
1821 | pe_rel = (struct grub_pe32_reloc *) (image + pe_sec->relocations_offset); | ||
1822 | - rel = (elf_reloc_t *) xmalloc (pe_sec->num_relocations * sizeof (elf_reloc_t)); | ||
1823 | + rel = (elf_reloc_t *) xcalloc (pe_sec->num_relocations, sizeof (elf_reloc_t)); | ||
1824 | num_rels = 0; | ||
1825 | modified = 0; | ||
1826 | |||
1827 | @@ -365,12 +365,10 @@ write_symbol_table (FILE* fp, const char *name, char *image, | ||
1828 | pe_symtab = (struct grub_pe32_symbol *) (image + pe_chdr->symtab_offset); | ||
1829 | pe_strtab = (char *) (pe_symtab + pe_chdr->num_symbols); | ||
1830 | |||
1831 | - symtab = (Elf_Sym *) xmalloc ((pe_chdr->num_symbols + 1) * | ||
1832 | - sizeof (Elf_Sym)); | ||
1833 | - memset (symtab, 0, (pe_chdr->num_symbols + 1) * sizeof (Elf_Sym)); | ||
1834 | + symtab = (Elf_Sym *) xcalloc (pe_chdr->num_symbols + 1, sizeof (Elf_Sym)); | ||
1835 | num_syms = 1; | ||
1836 | |||
1837 | - symtab_map = (int *) xmalloc (pe_chdr->num_symbols * sizeof (int)); | ||
1838 | + symtab_map = (int *) xcalloc (pe_chdr->num_symbols, sizeof (int)); | ||
1839 | |||
1840 | for (i = 0; i < (int) pe_chdr->num_symbols; | ||
1841 | i += pe_symtab->num_aux + 1, pe_symtab += pe_symtab->num_aux + 1) | ||
1842 | diff --git a/util/grub-probe.c b/util/grub-probe.c | ||
1843 | index 81d27ee..cbe6ed9 100644 | ||
1844 | --- a/util/grub-probe.c | ||
1845 | +++ b/util/grub-probe.c | ||
1846 | @@ -361,8 +361,8 @@ probe (const char *path, char **device_names, char delim) | ||
1847 | grub_util_pull_device (*curdev); | ||
1848 | ndev++; | ||
1849 | } | ||
1850 | - | ||
1851 | - drives_names = xmalloc (sizeof (drives_names[0]) * (ndev + 1)); | ||
1852 | + | ||
1853 | + drives_names = xcalloc (ndev + 1, sizeof (drives_names[0])); | ||
1854 | |||
1855 | for (curdev = device_names, curdrive = drives_names; *curdev; curdev++, | ||
1856 | curdrive++) | ||
1857 | -- | ||
1858 | 2.14.4 | ||
1859 | |||