summary refs log tree commit diff
path: root/xmalloc.c
diff options
context:
space:
mode:
authorokan <okan>2012-11-16 14:15:48 +0000
committerokan <okan>2012-11-16 14:15:48 +0000
commit93f64ffc55d29947614f234a5c6deddcbc2d4e81 (patch)
tree926401192c364335e3327655b2b4d98e96fbd2c2 /xmalloc.c
parent7b00e3fe76148403292f2332b2398d24a16d0453 (diff)
downloadcwm-93f64ffc55d29947614f234a5c6deddcbc2d4e81.tar.gz
cwm-93f64ffc55d29947614f234a5c6deddcbc2d4e81.tar.xz
cwm-93f64ffc55d29947614f234a5c6deddcbc2d4e81.zip
add some checks
Diffstat (limited to 'xmalloc.c')
-rw-r--r--xmalloc.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/xmalloc.c b/xmalloc.c
index 1d0c581..d0697fa 100644
--- a/xmalloc.c
+++ b/xmalloc.c
@@ -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");