diff options
author | Doug Hogan <doug@cvs.openbsd.org> | 2014-10-23 05:48:41 +0000 |
---|---|---|
committer | Doug Hogan <doug@cvs.openbsd.org> | 2014-10-23 05:48:41 +0000 |
commit | c13afb515d9c55d85ab60be1a54b78a7dc167f84 (patch) | |
tree | 1c0d1f87bd9a7ad2b4e8def2fec008acfb7a2b54 | |
parent | ae0764c078f3d96ece001ad051edac2e73efd38c (diff) |
Save space in man page: err() -> errc() and combine vars.
Suggested by millert@ and schwarze@.
OK schwarze@, millert@
-rw-r--r-- | lib/libc/stdlib/malloc.3 | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/lib/libc/stdlib/malloc.3 b/lib/libc/stdlib/malloc.3 index caf1da22076..2647434eaad 100644 --- a/lib/libc/stdlib/malloc.3 +++ b/lib/libc/stdlib/malloc.3 @@ -30,9 +30,9 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" $OpenBSD: malloc.3,v 1.82 2014/10/22 05:19:27 doug Exp $ +.\" $OpenBSD: malloc.3,v 1.83 2014/10/23 05:48:40 doug Exp $ .\" -.Dd $Mdocdate: October 22 2014 $ +.Dd $Mdocdate: October 23 2014 $ .Dt MALLOC 3 .Os .Sh NAME @@ -303,15 +303,13 @@ If .Fn malloc must be used with multiplication, be sure to test for overflow: .Bd -literal -offset indent -size_t size; -size_t num; +size_t num, size; \&... /* Check for size_t overflow */ -if (size && num > SIZE_MAX / size) { - errno = EOVERFLOW; - err(1, "overflow"); -} +if (size && num > SIZE_MAX / size) + errc(1, EOVERFLOW, "overflow"); + if ((p = malloc(size * num)) == NULL) err(1, "malloc"); .Ed @@ -319,21 +317,16 @@ if ((p = malloc(size * num)) == NULL) The above test is not sufficient in all cases. For example, multiplying ints requires a different set of checks: .Bd -literal -offset indent -int size; -int num; +int num, size; \&... /* Avoid invalid requests */ -if (size < 0 || num < 0) { - errno = EOVERFLOW; - err(1, "overflow"); -} +if (size < 0 || num < 0) + errc(1, EOVERFLOW, "overflow"); /* Check for signed int overflow */ -if (size && num > INT_MAX / size) { - errno = EOVERFLOW; - err(1, "overflow"); -} +if (size && num > INT_MAX / size) + errc(1, EOVERFLOW, "overflow"); if ((p = malloc(size * num)) == NULL) err(1, "malloc"); |