mirror of
https://github.com/leahneukirchen/cwm.git
synced 2023-08-10 21:13:12 +03:00
add some checks
This commit is contained in:
parent
7b00e3fe76
commit
93f64ffc55
@ -23,6 +23,7 @@
|
||||
|
||||
#include <err.h>
|
||||
#include <errno.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@ -35,6 +36,8 @@ xmalloc(size_t siz)
|
||||
{
|
||||
void *p;
|
||||
|
||||
if (siz == 0)
|
||||
errx(1, "xmalloc: zero size");
|
||||
if ((p = malloc(siz)) == NULL)
|
||||
err(1, "malloc");
|
||||
|
||||
@ -46,6 +49,10 @@ xcalloc(size_t no, size_t siz)
|
||||
{
|
||||
void *p;
|
||||
|
||||
if (siz == 0 || no == 0)
|
||||
errx(1, "xcalloc: zero size");
|
||||
if (SIZE_MAX / no < siz)
|
||||
errx(1, "xcalloc: no * siz > SIZE_MAX");
|
||||
if ((p = calloc(no, siz)) == NULL)
|
||||
err(1, "calloc");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user