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:
parent
68708c4503
commit
64e26162eb
7 changed files with 85 additions and 3 deletions
|
@ -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 *
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue