diff options
| author | schwarze <> | 2014-10-20 19:35:23 +0000 |
|---|---|---|
| committer | schwarze <> | 2014-10-20 19:35:23 +0000 |
| commit | 785282b5b9dd6b6677feec360b12d5162c203b52 (patch) | |
| tree | 851c2f8d6a47706a7d55fbb2aabeb7c612e66d28 /src/lib/libc/stdlib/malloc.3 | |
| parent | 10a9b1df4b5ad5428b68d2cae5f7ae6a82108db2 (diff) | |
| download | openbsd-785282b5b9dd6b6677feec360b12d5162c203b52.tar.gz openbsd-785282b5b9dd6b6677feec360b12d5162c203b52.tar.bz2 openbsd-785282b5b9dd6b6677feec360b12d5162c203b52.zip | |
List extensions in the STANDARDS section, replacing some text below CAVEATS.
Remove excessive technicalities on zero-sized objects as suggested by deraadt@.
contributions and ok deraadt@, ok jmc@ on an earlier version
Diffstat (limited to 'src/lib/libc/stdlib/malloc.3')
| -rw-r--r-- | src/lib/libc/stdlib/malloc.3 | 63 |
1 files changed, 30 insertions, 33 deletions
diff --git a/src/lib/libc/stdlib/malloc.3 b/src/lib/libc/stdlib/malloc.3 index d6c8b375ae..8305b14d35 100644 --- a/src/lib/libc/stdlib/malloc.3 +++ b/src/lib/libc/stdlib/malloc.3 | |||
| @@ -30,9 +30,9 @@ | |||
| 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.80 2014/10/19 21:05:53 schwarze Exp $ | 33 | .\" $OpenBSD: malloc.3,v 1.81 2014/10/20 19:35:23 schwarze Exp $ |
| 34 | .\" | 34 | .\" |
| 35 | .Dd $Mdocdate: October 19 2014 $ | 35 | .Dd $Mdocdate: October 20 2014 $ |
| 36 | .Dt MALLOC 3 | 36 | .Dt MALLOC 3 |
| 37 | .Os | 37 | .Os |
| 38 | .Sh NAME | 38 | .Sh NAME |
| @@ -159,12 +159,16 @@ pointer is returned and | |||
| 159 | .Va errno | 159 | .Va errno |
| 160 | is set to | 160 | is set to |
| 161 | .Er ENOMEM . | 161 | .Er ENOMEM . |
| 162 | .Pp | ||
| 162 | If | 163 | If |
| 163 | .Fa size | 164 | .Fa size |
| 164 | or | 165 | or |
| 165 | .Fa nmemb | 166 | .Fa nmemb |
| 166 | is equal to 0, | 167 | is equal to 0, a unique pointer to an access protected, |
| 167 | a pointer to an access protected, zero sized object is returned. | 168 | zero sized object is returned. |
| 169 | Access via this pointer will generate a | ||
| 170 | .Dv SIGSEGV | ||
| 171 | exception. | ||
| 168 | .Pp | 172 | .Pp |
| 169 | If multiplying | 173 | If multiplying |
| 170 | .Fa nmemb | 174 | .Fa nmemb |
| @@ -564,6 +568,28 @@ and | |||
| 564 | .Fn free | 568 | .Fn free |
| 565 | functions conform to | 569 | functions conform to |
| 566 | .St -ansiC . | 570 | .St -ansiC . |
| 571 | .Pp | ||
| 572 | If | ||
| 573 | .Fa size | ||
| 574 | or | ||
| 575 | .Fa nmemb | ||
| 576 | are 0, the return value is implementation defined; | ||
| 577 | other conforming implementations may return | ||
| 578 | .Dv NULL | ||
| 579 | in this case. | ||
| 580 | .Pp | ||
| 581 | The standard does not require | ||
| 582 | .Fn calloc | ||
| 583 | to check for integer overflow, | ||
| 584 | but most modern implementations provide this check. | ||
| 585 | .Pp | ||
| 586 | The | ||
| 587 | .Ev MALLOC_OPTIONS | ||
| 588 | environment variable, the file | ||
| 589 | .Pa /etc/malloc.conf , | ||
| 590 | and the | ||
| 591 | .Sx DIAGNOSTICS | ||
| 592 | output are extensions to the standard. | ||
| 567 | .Sh HISTORY | 593 | .Sh HISTORY |
| 568 | A | 594 | A |
| 569 | .Fn free | 595 | .Fn free |
| @@ -618,35 +644,6 @@ The | |||
| 618 | .Fn cfree | 644 | .Fn cfree |
| 619 | function appeared in SunOS 4.x. | 645 | function appeared in SunOS 4.x. |
| 620 | .Sh CAVEATS | 646 | .Sh CAVEATS |
| 621 | The | ||
| 622 | .Fn calloc | ||
| 623 | function checks for integer overflow in | ||
| 624 | .Ox | ||
| 625 | and most other modern platforms. | ||
| 626 | Software targeting ancient platforms should not rely on this behavior. | ||
| 627 | .Pp | ||
| 628 | The | ||
| 629 | .Fn malloc , | ||
| 630 | .Fn calloc , | ||
| 631 | and | ||
| 632 | .Fn realloc | ||
| 633 | functions have implementation defined behavior when | ||
| 634 | .Fa size | ||
| 635 | or | ||
| 636 | .Fa nmemb | ||
| 637 | are zero. | ||
| 638 | .Pp | ||
| 639 | Allocation of a zero size object returns a pointer to an access protected zero | ||
| 640 | size object. | ||
| 641 | Many zero-sized objects can be placed consecutively in shared | ||
| 642 | protected pages. | ||
| 643 | The minimum size of the protection on each object is suitably aligned and | ||
| 644 | sized as previously stated, but the protection may extend further depending | ||
| 645 | on where in a protected zone the object lands. | ||
| 646 | Attempting to access these objects will generate a | ||
| 647 | .Pq Dv SIGSEGV | ||
| 648 | exception. | ||
| 649 | .Pp | ||
| 650 | When using | 647 | When using |
| 651 | .Fn malloc , | 648 | .Fn malloc , |
| 652 | be wary of signed integer and | 649 | be wary of signed integer and |
