summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/libc/stdlib/malloc.316
1 files changed, 8 insertions, 8 deletions
diff --git a/src/lib/libc/stdlib/malloc.3 b/src/lib/libc/stdlib/malloc.3
index 6cb6011ae4..2e820047d0 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.92 2016/01/06 17:57:22 tedu Exp $ 33.\" $OpenBSD: malloc.3,v 1.93 2016/02/05 15:09:09 schwarze Exp $
34.\" 34.\"
35.Dd $Mdocdate: January 6 2016 $ 35.Dd $Mdocdate: February 5 2016 $
36.Dt MALLOC 3 36.Dt MALLOC 3
37.Os 37.Os
38.Sh NAME 38.Sh NAME
@@ -191,7 +191,7 @@ or
191For example, avoid this common idiom as it may lead to integer overflow: 191For example, avoid this common idiom as it may lead to integer overflow:
192.Bd -literal -offset indent 192.Bd -literal -offset indent
193if ((p = malloc(num * size)) == NULL) 193if ((p = malloc(num * size)) == NULL)
194 err(1, "malloc"); 194 err(1, NULL);
195.Ed 195.Ed
196.Pp 196.Pp
197A drop-in replacement is the 197A drop-in replacement is the
@@ -200,7 +200,7 @@ extension
200.Fn reallocarray : 200.Fn reallocarray :
201.Bd -literal -offset indent 201.Bd -literal -offset indent
202if ((p = reallocarray(NULL, num, size)) == NULL) 202if ((p = reallocarray(NULL, num, size)) == NULL)
203 err(1, "reallocarray"); 203 err(1, NULL);
204.Ed 204.Ed
205.Pp 205.Pp
206Alternatively, 206Alternatively,
@@ -295,7 +295,7 @@ if (size && num > SIZE_MAX / size)
295 errc(1, EOVERFLOW, "overflow"); 295 errc(1, EOVERFLOW, "overflow");
296 296
297if ((p = malloc(size * num)) == NULL) 297if ((p = malloc(size * num)) == NULL)
298 err(1, "malloc"); 298 err(1, NULL);
299.Ed 299.Ed
300.Pp 300.Pp
301The above test is not sufficient in all cases. 301The above test is not sufficient in all cases.
@@ -313,7 +313,7 @@ if (size && num > INT_MAX / size)
313 errc(1, EOVERFLOW, "overflow"); 313 errc(1, EOVERFLOW, "overflow");
314 314
315if ((p = malloc(size * num)) == NULL) 315if ((p = malloc(size * num)) == NULL)
316 err(1, "malloc"); 316 err(1, NULL);
317.Ed 317.Ed
318.Pp 318.Pp
319Assuming the implementation checks for integer overflow as 319Assuming the implementation checks for integer overflow as
@@ -326,13 +326,13 @@ or
326The above examples could be simplified to: 326The above examples could be simplified to:
327.Bd -literal -offset indent 327.Bd -literal -offset indent
328if ((p = reallocarray(NULL, num, size)) == NULL) 328if ((p = reallocarray(NULL, num, size)) == NULL)
329 err(1, "reallocarray"); 329 err(1, NULL);
330.Ed 330.Ed
331.Pp 331.Pp
332or at the cost of initialization: 332or at the cost of initialization:
333.Bd -literal -offset indent 333.Bd -literal -offset indent
334if ((p = calloc(num, size)) == NULL) 334if ((p = calloc(num, size)) == NULL)
335 err(1, "calloc"); 335 err(1, NULL);
336.Ed 336.Ed
337.Sh DIAGNOSTICS 337.Sh DIAGNOSTICS
338If 338If