diff options
| author | deraadt <> | 2014-04-21 13:17:32 +0000 | 
|---|---|---|
| committer | deraadt <> | 2014-04-21 13:17:32 +0000 | 
| commit | b5701aa73a632ec384dd8e14c19bf595b62d37c7 (patch) | |
| tree | 2e743eaa4b5a39473daad0b655461bf389ae5a12 /src/lib/libc/stdlib/malloc.3 | |
| parent | c7cbcf9bb8536d33ffb30f6eb6a5f8a4776ede31 (diff) | |
| download | openbsd-b5701aa73a632ec384dd8e14c19bf595b62d37c7.tar.gz openbsd-b5701aa73a632ec384dd8e14c19bf595b62d37c7.tar.bz2 openbsd-b5701aa73a632ec384dd8e14c19bf595b62d37c7.zip | |
Introducing:      void *mallocarray(size_t nmemb, size_t size);
Like calloc(), except without the cleared-memory gaurantee
ok beck guenther, discussed for more than a year...
Diffstat (limited to 'src/lib/libc/stdlib/malloc.3')
| -rw-r--r-- | src/lib/libc/stdlib/malloc.3 | 29 | 
1 files changed, 22 insertions, 7 deletions
| diff --git a/src/lib/libc/stdlib/malloc.3 b/src/lib/libc/stdlib/malloc.3 index 414f0a9770..2a636b88cc 100644 --- a/src/lib/libc/stdlib/malloc.3 +++ b/src/lib/libc/stdlib/malloc.3 | |||
| @@ -30,14 +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.73 2013/07/18 10:14:49 schwarze Exp $ | 33 | .\" $OpenBSD: malloc.3,v 1.74 2014/04/21 13:17:32 deraadt Exp $ | 
| 34 | .\" | 34 | .\" | 
| 35 | .Dd $Mdocdate: July 18 2013 $ | 35 | .Dd $Mdocdate: April 21 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 realloc , | 42 | .Nm realloc , | 
| 42 | .Nm free , | 43 | .Nm free , | 
| 43 | .Nm cfree | 44 | .Nm cfree | 
| @@ -49,12 +50,14 @@ | |||
| 49 | .Ft void * | 50 | .Ft void * | 
| 50 | .Fn calloc "size_t nmemb" "size_t size" | 51 | .Fn calloc "size_t nmemb" "size_t size" | 
| 51 | .Ft void * | 52 | .Ft void * | 
| 53 | .Fn mallocarray "size_t nmemb" "size_t size" | ||
| 54 | .Ft void * | ||
| 52 | .Fn realloc "void *ptr" "size_t size" | 55 | .Fn realloc "void *ptr" "size_t size" | 
| 53 | .Ft void | 56 | .Ft void | 
| 54 | .Fn free "void *ptr" | 57 | .Fn free "void *ptr" | 
| 55 | .Ft void | 58 | .Ft void | 
| 56 | .Fn cfree "void *ptr" | 59 | .Fn cfree "void *ptr" | 
| 57 | .Ft char * | 60 | .Ft char * Ns | 
| 58 | .Va malloc_options ; | 61 | .Va malloc_options ; | 
| 59 | .Sh DESCRIPTION | 62 | .Sh DESCRIPTION | 
| 60 | The | 63 | The | 
| @@ -91,10 +94,18 @@ if ((p = malloc(num * size)) == NULL) | |||
| 91 | err(1, "malloc"); | 94 | err(1, "malloc"); | 
| 92 | .Ed | 95 | .Ed | 
| 93 | .Pp | 96 | .Pp | 
| 94 | The multiplication may lead to an integer overflow. | 97 | The multiplication may lead to an integer overflow, which can | 
| 95 | To avoid this, | 98 | be avoided using the extension | 
| 99 | .Fn mallocarray , | ||
| 100 | as follows: | ||
| 101 | .Bd -literal -offset indent | ||
| 102 | if ((p = mallocarray(num, size)) == NULL) | ||
| 103 | err(1, "malloc"); | ||
| 104 | .Ed | ||
| 105 | .Pp | ||
| 106 | Alternatively | ||
| 96 | .Fn calloc | 107 | .Fn calloc | 
| 97 | is recommended. | 108 | is a more portable solution which comes with the cost of clearing memory. | 
| 98 | .Pp | 109 | .Pp | 
| 99 | If | 110 | If | 
| 100 | .Fn malloc | 111 | .Fn malloc | 
| @@ -324,7 +335,8 @@ it is buggy. | |||
| 324 | The default number of free pages cached is 64. | 335 | The default number of free pages cached is 64. | 
| 325 | .Sh RETURN VALUES | 336 | .Sh RETURN VALUES | 
| 326 | The | 337 | The | 
| 327 | .Fn malloc | 338 | .Fn malloc , | 
| 339 | .Fn mallocarray , | ||
| 328 | and | 340 | and | 
| 329 | .Fn calloc | 341 | .Fn calloc | 
| 330 | functions return a pointer to the allocated space if successful; otherwise, | 342 | functions return a pointer to the allocated space if successful; otherwise, | 
| @@ -482,3 +494,6 @@ random. | |||
| 482 | A rewrite by Otto Moerbeek introducing a new central data structure and more | 494 | A rewrite by Otto Moerbeek introducing a new central data structure and more | 
| 483 | randomization appeared in | 495 | randomization appeared in | 
| 484 | .Ox 4.4 . | 496 | .Ox 4.4 . | 
| 497 | .Fn mallocarray | ||
| 498 | appeared in | ||
| 499 | .Ox 5.6 . | ||
