Module Name: src
Committed By: wiz
Date: Fri Feb 6 08:37:39 UTC 2015
Modified Files:
src/lib/libc/stdlib: malloc.3 reallocarray.3
Log Message:
Remove trailing whitespace.
To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/lib/libc/stdlib/malloc.3
cvs rdiff -u -r1.2 -r1.3 src/lib/libc/stdlib/reallocarray.3
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/lib/libc/stdlib/malloc.3
diff -u src/lib/libc/stdlib/malloc.3:1.40 src/lib/libc/stdlib/malloc.3:1.41
--- src/lib/libc/stdlib/malloc.3:1.40 Thu Feb 5 20:02:28 2015
+++ src/lib/libc/stdlib/malloc.3 Fri Feb 6 08:37:39 2015
@@ -1,4 +1,4 @@
-.\" $NetBSD: malloc.3,v 1.40 2015/02/05 20:02:28 christos Exp $
+.\" $NetBSD: malloc.3,v 1.41 2015/02/06 08:37:39 wiz Exp $
.\"
.\" Copyright (c) 1980, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -175,18 +175,18 @@ if (size && number > SIZE_MAX / size) {
The above test is not sufficient in all cases.
For example, multiplying ints requires a different set of checks:
.Bd -literal -offset indent
-int num, size;
-\&.\&.\&.
-
-/* Avoid invalid requests */
-if (size < 0 || num < 0)
- errc(1, EOVERFLOW, "overflow");
-
-/* Check for signed int overflow */
-if (size && num > INT_MAX / size)
- errc(1, EOVERFLOW, "overflow");
-
-if ((p = malloc(size * num)) == NULL)
+int num, size;
+\&.\&.\&.
+
+/* Avoid invalid requests */
+if (size < 0 || num < 0)
+ errc(1, EOVERFLOW, "overflow");
+
+/* Check for signed int overflow */
+if (size && num > INT_MAX / size)
+ errc(1, EOVERFLOW, "overflow");
+
+if ((p = malloc(size * num)) == NULL)
err(1, "malloc");
.Ed
.Pp
@@ -194,18 +194,18 @@ Assuming the implementation checks for i
.Nx
does, it is much easier to use
.Fn calloc
-or
+or
.Xr reallocarr 3 .
.Pp
The above examples could be simplified to:
.Bd -literal -offset indent
ptr = NULL;
-if ((e = reallocarr(&ptr, num, size)))
+if ((e = reallocarr(&ptr, num, size)))
errx(1, "reallocarr", strerror(e));
.Ed
.Bd -literal -offset indent
or at the cost of initialization:
-if ((p = calloc(num, size)) == NULL)
+if ((p = calloc(num, size)) == NULL)
err(1, "calloc");
.Ed
.Pp
Index: src/lib/libc/stdlib/reallocarray.3
diff -u src/lib/libc/stdlib/reallocarray.3:1.2 src/lib/libc/stdlib/reallocarray.3:1.3
--- src/lib/libc/stdlib/reallocarray.3:1.2 Thu Feb 5 22:05:33 2015
+++ src/lib/libc/stdlib/reallocarray.3 Fri Feb 6 08:37:39 2015
@@ -1,4 +1,4 @@
-.\" $NetBSD: reallocarray.3,v 1.2 2015/02/05 22:05:33 christos Exp $
+.\" $NetBSD: reallocarray.3,v 1.3 2015/02/06 08:37:39 wiz Exp $
.\"
.Dd February 5, 2015
.Dt REALLOCARRAY 3
@@ -30,7 +30,7 @@ and making sure that overflow does not h
.Dq "nmemb * size" .
.Pp
This function is provided for source compatibility with
-.Ox
+.Ox
and
its use is discouraged in preference to
.Xr reallocarr 3 .
@@ -50,7 +50,7 @@ or preserving the value from
.Sh SEE ALSO
.Xr malloc 3 ,
.Xr realloc 3 ,
-.Xr reallocarr 3
+.Xr reallocarr 3
.Sh STANDARDS
.Fn reallocarray
is an
@@ -78,14 +78,14 @@ function was designed to facilitate safe
robust programming and overcome the shortcomings of the
.Xr malloc 3
and
-.Xr realloc 3
+.Xr realloc 3
functions by centralizing the overflow check in the multiplication of
.Fa nmemb
and
.Fa size .
.Pp
There are still portability issues (it does not solve
-the
+the
.Dv 0
sized allocation return ambiguity in the C standard: does
.Fn reallocarray