calloc: Make sure we always have an overflow-checking calloc() available

This tries to make sure that everywhere in this source tree, we always have
an appropriate version of calloc() (i.e. grub_calloc(), xcalloc(), etc.)
available, and that they all safely check for overflow and return NULL when
it would occur.

Signed-off-by: Peter Jones <pjones@redhat.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
This commit is contained in:
Peter Jones authored and Daniel Kiper committed 2020-07-29 16:55:47 +02:00
1 parent 68708c4503
commit 64e26162eb
7 files changed
+85 -3

No files matched your search

+7 -1
View File
@@ -21,6 +21,7 @@
#include <grub/mm.h>
#include <grub/misc.h>
#include <grub/safemath.h>
static inline void
free (void *ptr)
@@ -37,7 +38,12 @@ malloc (grub_size_t size)
static inline void *
calloc (grub_size_t size, grub_size_t nelem)
{
return grub_zalloc (size * nelem);
grub_size_t sz;
if (grub_mul (size, nelem, &sz))
return NULL;
return grub_zalloc (sz);
}
static inline void *