diff options
author | Colin Watson <cjwatson@debian.org> | 2015-08-19 17:00:17 +0100 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2015-08-19 17:40:32 +0100 |
commit | 927d0032b865f05679d3cc052bc13cb0e6490283 (patch) | |
tree | 69f782deb79182f26069ff41e9539f17e6e44912 /xmalloc.c | |
parent | d35c65e77ab6a6a95fefa2c852827ba08e507f0b (diff) | |
parent | 810eecd6b2e03770f21e46b5cb8ce8c7fcd46da8 (diff) |
New upstream release (6.9p1).
Diffstat (limited to 'xmalloc.c')
-rw-r--r-- | xmalloc.c | 18 |
1 files changed, 5 insertions, 13 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: xmalloc.c,v 1.31 2015/02/06 23:21:59 millert Exp $ */ | 1 | /* $OpenBSD: xmalloc.c,v 1.32 2015/04/24 01:36:01 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 |
@@ -56,22 +56,14 @@ xcalloc(size_t nmemb, size_t size) | |||
56 | } | 56 | } |
57 | 57 | ||
58 | void * | 58 | void * |
59 | xrealloc(void *ptr, size_t nmemb, size_t size) | 59 | xreallocarray(void *ptr, size_t nmemb, size_t size) |
60 | { | 60 | { |
61 | void *new_ptr; | 61 | void *new_ptr; |
62 | size_t new_size = nmemb * size; | ||
63 | 62 | ||
64 | if (new_size == 0) | 63 | new_ptr = reallocarray(ptr, nmemb, size); |
65 | fatal("xrealloc: zero size"); | ||
66 | if (SIZE_MAX / nmemb < size) | ||
67 | fatal("xrealloc: nmemb * size > SIZE_MAX"); | ||
68 | if (ptr == NULL) | ||
69 | new_ptr = malloc(new_size); | ||
70 | else | ||
71 | new_ptr = realloc(ptr, new_size); | ||
72 | if (new_ptr == NULL) | 64 | if (new_ptr == NULL) |
73 | fatal("xrealloc: out of memory (new_size %zu bytes)", | 65 | fatal("xreallocarray: out of memory (%zu elements of %zu bytes)", |
74 | new_size); | 66 | nmemb, size); |
75 | return new_ptr; | 67 | return new_ptr; |
76 | } | 68 | } |
77 | 69 | ||