summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordoug <>2014-10-23 05:48:40 +0000
committerdoug <>2014-10-23 05:48:40 +0000
commit29aad45bff189f574f5a2afddabe28b0d8cd7b16 (patch)
treee53c5e5ee1b95a416e81b3f20d5cac681cc1bb5c /src
parent94bf30fecb343725db81902304e3d1d1e2707172 (diff)
downloadopenbsd-29aad45bff189f574f5a2afddabe28b0d8cd7b16.tar.gz
openbsd-29aad45bff189f574f5a2afddabe28b0d8cd7b16.tar.bz2
openbsd-29aad45bff189f574f5a2afddabe28b0d8cd7b16.zip
Save space in man page: err() -> errc() and combine vars.
Suggested by millert@ and schwarze@. OK schwarze@, millert@
Diffstat (limited to 'src')
-rw-r--r--src/lib/libc/stdlib/malloc.329
1 files changed, 11 insertions, 18 deletions
diff --git a/src/lib/libc/stdlib/malloc.3 b/src/lib/libc/stdlib/malloc.3
index caf1da2207..2647434eaa 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.82 2014/10/22 05:19:27 doug Exp $ 33.\" $OpenBSD: malloc.3,v 1.83 2014/10/23 05:48:40 doug Exp $
34.\" 34.\"
35.Dd $Mdocdate: October 22 2014 $ 35.Dd $Mdocdate: October 23 2014 $
36.Dt MALLOC 3 36.Dt MALLOC 3
37.Os 37.Os
38.Sh NAME 38.Sh NAME
@@ -303,15 +303,13 @@ If
303.Fn malloc 303.Fn malloc
304must be used with multiplication, be sure to test for overflow: 304must be used with multiplication, be sure to test for overflow:
305.Bd -literal -offset indent 305.Bd -literal -offset indent
306size_t size; 306size_t num, size;
307size_t num;
308\&... 307\&...
309 308
310/* Check for size_t overflow */ 309/* Check for size_t overflow */
311if (size && num > SIZE_MAX / size) { 310if (size && num > SIZE_MAX / size)
312 errno = EOVERFLOW; 311 errc(1, EOVERFLOW, "overflow");
313 err(1, "overflow"); 312
314}
315if ((p = malloc(size * num)) == NULL) 313if ((p = malloc(size * num)) == NULL)
316 err(1, "malloc"); 314 err(1, "malloc");
317.Ed 315.Ed
@@ -319,21 +317,16 @@ if ((p = malloc(size * num)) == NULL)
319The above test is not sufficient in all cases. 317The above test is not sufficient in all cases.
320For example, multiplying ints requires a different set of checks: 318For example, multiplying ints requires a different set of checks:
321.Bd -literal -offset indent 319.Bd -literal -offset indent
322int size; 320int num, size;
323int num;
324\&... 321\&...
325 322
326/* Avoid invalid requests */ 323/* Avoid invalid requests */
327if (size < 0 || num < 0) { 324if (size < 0 || num < 0)
328 errno = EOVERFLOW; 325 errc(1, EOVERFLOW, "overflow");
329 err(1, "overflow");
330}
331 326
332/* Check for signed int overflow */ 327/* Check for signed int overflow */
333if (size && num > INT_MAX / size) { 328if (size && num > INT_MAX / size)
334 errno = EOVERFLOW; 329 errc(1, EOVERFLOW, "overflow");
335 err(1, "overflow");
336}
337 330
338if ((p = malloc(size * num)) == NULL) 331if ((p = malloc(size * num)) == NULL)
339 err(1, "malloc"); 332 err(1, "malloc");