diff options
author | tedu <> | 2014-04-22 14:26:26 +0000 |
---|---|---|
committer | tedu <> | 2014-04-22 14:26:26 +0000 |
commit | 5c557d38ed349266c22bfdf0d800f6e873921885 (patch) | |
tree | c8c9415e75220dc3ffecdcd042ee356dc6051ba3 /src/lib/libc/stdlib/malloc.3 | |
parent | 83c4dbaf581d987510fb450e4e68af50d52c6f99 (diff) | |
download | openbsd-5c557d38ed349266c22bfdf0d800f6e873921885.tar.gz openbsd-5c557d38ed349266c22bfdf0d800f6e873921885.tar.bz2 openbsd-5c557d38ed349266c22bfdf0d800f6e873921885.zip |
change mallocarray to reallocarray. useful in a few more situations.
malloc can, as always, be emulated via realloc(NULL).
ok deraadt
Diffstat (limited to 'src/lib/libc/stdlib/malloc.3')
-rw-r--r-- | src/lib/libc/stdlib/malloc.3 | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/src/lib/libc/stdlib/malloc.3 b/src/lib/libc/stdlib/malloc.3 index 2a636b88cc..2f99ea9b80 100644 --- a/src/lib/libc/stdlib/malloc.3 +++ b/src/lib/libc/stdlib/malloc.3 | |||
@@ -30,15 +30,15 @@ | |||
30 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | 30 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
31 | .\" SUCH DAMAGE. | 31 | .\" SUCH DAMAGE. |
32 | .\" | 32 | .\" |
33 | .\" $OpenBSD: malloc.3,v 1.74 2014/04/21 13:17:32 deraadt Exp $ | 33 | .\" $OpenBSD: malloc.3,v 1.75 2014/04/22 14:26:26 tedu Exp $ |
34 | .\" | 34 | .\" |
35 | .Dd $Mdocdate: April 21 2014 $ | 35 | .Dd $Mdocdate: April 22 2014 $ |
36 | .Dt MALLOC 3 | 36 | .Dt MALLOC 3 |
37 | .Os | 37 | .Os |
38 | .Sh NAME | 38 | .Sh NAME |
39 | .Nm malloc , | 39 | .Nm malloc , |
40 | .Nm calloc , | 40 | .Nm calloc , |
41 | .Nm mallocarray , | 41 | .Nm reallocarray , |
42 | .Nm realloc , | 42 | .Nm realloc , |
43 | .Nm free , | 43 | .Nm free , |
44 | .Nm cfree | 44 | .Nm cfree |
@@ -50,7 +50,7 @@ | |||
50 | .Ft void * | 50 | .Ft void * |
51 | .Fn calloc "size_t nmemb" "size_t size" | 51 | .Fn calloc "size_t nmemb" "size_t size" |
52 | .Ft void * | 52 | .Ft void * |
53 | .Fn mallocarray "size_t nmemb" "size_t size" | 53 | .Fn reallocarray "void *ptr" "size_t nmemb" "size_t size" |
54 | .Ft void * | 54 | .Ft void * |
55 | .Fn realloc "void *ptr" "size_t size" | 55 | .Fn realloc "void *ptr" "size_t size" |
56 | .Ft void | 56 | .Ft void |
@@ -96,10 +96,10 @@ if ((p = malloc(num * size)) == NULL) | |||
96 | .Pp | 96 | .Pp |
97 | The multiplication may lead to an integer overflow, which can | 97 | The multiplication may lead to an integer overflow, which can |
98 | be avoided using the extension | 98 | be avoided using the extension |
99 | .Fn mallocarray , | 99 | .Fn reallocarray , |
100 | as follows: | 100 | as follows: |
101 | .Bd -literal -offset indent | 101 | .Bd -literal -offset indent |
102 | if ((p = mallocarray(num, size)) == NULL) | 102 | if ((p = reallocarray(NULL, num, size)) == NULL) |
103 | err(1, "malloc"); | 103 | err(1, "malloc"); |
104 | .Ed | 104 | .Ed |
105 | .Pp | 105 | .Pp |
@@ -125,6 +125,8 @@ objects, each of whose size is | |||
125 | .Fa size . | 125 | .Fa size . |
126 | The space is initialized to zero. | 126 | The space is initialized to zero. |
127 | The use of | 127 | The use of |
128 | .Fn reallocarray | ||
129 | or | ||
128 | .Fn calloc | 130 | .Fn calloc |
129 | is strongly encouraged when allocating multiple sized objects | 131 | is strongly encouraged when allocating multiple sized objects |
130 | in order to avoid possible integer overflows. | 132 | in order to avoid possible integer overflows. |
@@ -309,11 +311,6 @@ malloc_options = "X"; | |||
309 | .Pp | 311 | .Pp |
310 | Note that this will cause code that is supposed to handle | 312 | Note that this will cause code that is supposed to handle |
311 | out-of-memory conditions gracefully to abort instead. | 313 | out-of-memory conditions gracefully to abort instead. |
312 | .It Cm Z | ||
313 | .Dq Zero . | ||
314 | Fill some junk into the area allocated (see | ||
315 | .Cm J ) , | ||
316 | except for the exact length the user asked for, which is zeroed. | ||
317 | .It Cm < | 314 | .It Cm < |
318 | .Dq Half the cache size . | 315 | .Dq Half the cache size . |
319 | Decrease the size of the free page cache by a factor of two. | 316 | Decrease the size of the free page cache by a factor of two. |
@@ -494,6 +491,6 @@ random. | |||
494 | A rewrite by Otto Moerbeek introducing a new central data structure and more | 491 | A rewrite by Otto Moerbeek introducing a new central data structure and more |
495 | randomization appeared in | 492 | randomization appeared in |
496 | .Ox 4.4 . | 493 | .Ox 4.4 . |
497 | .Fn mallocarray | 494 | .Fn reallocarray |
498 | appeared in | 495 | appeared in |
499 | .Ox 5.6 . | 496 | .Ox 5.6 . |