aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorokan2012-11-16 14:15:48 +0000
committerokan2012-11-16 14:15:48 +0000
commit94322ab4b003d971f561881fc600cffaa102a345 (patch)
tree0f9397328e8f6a6a699b596fc17f6cac48d49ba1
parent489872dc918fdedd174b89919e56048567209837 (diff)
downloadcwm-94322ab4b003d971f561881fc600cffaa102a345.tar.gz
add some checks
-rw-r--r--xmalloc.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/xmalloc.c b/xmalloc.c
index b41da2e..8e9d22a 100644
--- a/xmalloc.c
+++ b/xmalloc.c
@@ -15,7 +15,7 @@
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
- * $OpenBSD: xmalloc.c,v 1.9 2012/11/09 03:52:02 okan Exp $
+ * $OpenBSD: xmalloc.c,v 1.10 2012/11/16 14:15:48 okan Exp $
*/
#include <sys/param.h>
@@ -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");