diff options
Diffstat (limited to 'xmalloc.c')
-rw-r--r-- | xmalloc.c | 10 |
1 files changed, 5 insertions, 5 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: xmalloc.c,v 1.20 2006/03/25 13:17:03 djm Exp $ */ | 1 | /* $OpenBSD: xmalloc.c,v 1.21 2006/03/27 01:21:18 deraadt Exp $ */ |
2 | /* | 2 | /* |
3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 3 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland | 4 | * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland |
@@ -36,10 +36,10 @@ xcalloc(size_t nmemb, size_t size) | |||
36 | { | 36 | { |
37 | void *ptr; | 37 | void *ptr; |
38 | 38 | ||
39 | if (nmemb && size && SIZE_T_MAX / nmemb < size) | ||
40 | fatal("xcalloc: nmemb * size > SIZE_T_MAX"); | ||
41 | if (size == 0 || nmemb == 0) | 39 | if (size == 0 || nmemb == 0) |
42 | fatal("xcalloc: zero size"); | 40 | fatal("xcalloc: zero size"); |
41 | if (SIZE_T_MAX / nmemb < size) | ||
42 | fatal("xcalloc: nmemb * size > SIZE_T_MAX"); | ||
43 | ptr = calloc(nmemb, size); | 43 | ptr = calloc(nmemb, size); |
44 | if (ptr == NULL) | 44 | if (ptr == NULL) |
45 | fatal("xcalloc: out of memory (allocating %lu bytes)", | 45 | fatal("xcalloc: out of memory (allocating %lu bytes)", |
@@ -53,10 +53,10 @@ xrealloc(void *ptr, size_t nmemb, size_t size) | |||
53 | void *new_ptr; | 53 | void *new_ptr; |
54 | size_t new_size = nmemb * size; | 54 | size_t new_size = nmemb * size; |
55 | 55 | ||
56 | if (nmemb && size && SIZE_T_MAX / nmemb < size) | ||
57 | fatal("xrealloc: nmemb * size > SIZE_T_MAX"); | ||
58 | if (new_size == 0) | 56 | if (new_size == 0) |
59 | fatal("xrealloc: zero size"); | 57 | fatal("xrealloc: zero size"); |
58 | if (SIZE_T_MAX / nmemb < size) | ||
59 | fatal("xrealloc: nmemb * size > SIZE_T_MAX"); | ||
60 | if (ptr == NULL) | 60 | if (ptr == NULL) |
61 | new_ptr = malloc(new_size); | 61 | new_ptr = malloc(new_size); |
62 | else | 62 | else |