diff options
author | 2016-02-05 15:09:09 +0000 | |
---|---|---|
committer | 2016-02-05 15:09:09 +0000 | |
commit | 79e5f08ecba4190fc318fe2dbf71f0d90095e11b (patch) | |
tree | d7ffc798a7b9ded3807ac6f4582d9a7a20fc5efc /lib/libc/stdlib/malloc.3 | |
parent | Only check errno if read() has returned an error. EOF is not an error. (diff) | |
download | wireguard-openbsd-79e5f08ecba4190fc318fe2dbf71f0d90095e11b.tar.xz wireguard-openbsd-79e5f08ecba4190fc318fe2dbf71f0d90095e11b.zip |
Fix err(3) calls after allocation failures in examples.
There is long-standing consensus that err(1, NULL) is the best idiom
after failure of malloc(3) and friends.
Quirk in the manual noticed by tb@.
Diffstat (limited to 'lib/libc/stdlib/malloc.3')
-rw-r--r-- | lib/libc/stdlib/malloc.3 | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/lib/libc/stdlib/malloc.3 b/lib/libc/stdlib/malloc.3 index 6cb6011ae4b..2e820047d01 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.92 2016/01/06 17:57:22 tedu Exp $ +.\" $OpenBSD: malloc.3,v 1.93 2016/02/05 15:09:09 schwarze Exp $ .\" -.Dd $Mdocdate: January 6 2016 $ +.Dd $Mdocdate: February 5 2016 $ .Dt MALLOC 3 .Os .Sh NAME @@ -191,7 +191,7 @@ or For example, avoid this common idiom as it may lead to integer overflow: .Bd -literal -offset indent if ((p = malloc(num * size)) == NULL) - err(1, "malloc"); + err(1, NULL); .Ed .Pp A drop-in replacement is the @@ -200,7 +200,7 @@ extension .Fn reallocarray : .Bd -literal -offset indent if ((p = reallocarray(NULL, num, size)) == NULL) - err(1, "reallocarray"); + err(1, NULL); .Ed .Pp Alternatively, @@ -295,7 +295,7 @@ if (size && num > SIZE_MAX / size) errc(1, EOVERFLOW, "overflow"); if ((p = malloc(size * num)) == NULL) - err(1, "malloc"); + err(1, NULL); .Ed .Pp The above test is not sufficient in all cases. @@ -313,7 +313,7 @@ if (size && num > INT_MAX / size) errc(1, EOVERFLOW, "overflow"); if ((p = malloc(size * num)) == NULL) - err(1, "malloc"); + err(1, NULL); .Ed .Pp Assuming the implementation checks for integer overflow as @@ -326,13 +326,13 @@ or The above examples could be simplified to: .Bd -literal -offset indent if ((p = reallocarray(NULL, num, size)) == NULL) - err(1, "reallocarray"); + err(1, NULL); .Ed .Pp or at the cost of initialization: .Bd -literal -offset indent if ((p = calloc(num, size)) == NULL) - err(1, "calloc"); + err(1, NULL); .Ed .Sh DIAGNOSTICS If |