summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorschwarze <>2014-10-19 21:05:53 +0000
committerschwarze <>2014-10-19 21:05:53 +0000
commit5961a052ff4e8d579a02b073963a8fb9c1398575 (patch)
tree7ef0a4b8e1e3c4919292d0c80c8b7444f7626200 /src
parent4df28d31f8d900d5d1d164c0c75e270e82e11e81 (diff)
downloadopenbsd-5961a052ff4e8d579a02b073963a8fb9c1398575.tar.gz
openbsd-5961a052ff4e8d579a02b073963a8fb9c1398575.tar.bz2
openbsd-5961a052ff4e8d579a02b073963a8fb9c1398575.zip
make RETURN VALUES more concise
and fix two instances of "new sentence, new line" while here feedback and ok jmc@, ok doug@
Diffstat (limited to 'src')
-rw-r--r--src/lib/libc/stdlib/malloc.3105
1 files changed, 28 insertions, 77 deletions
diff --git a/src/lib/libc/stdlib/malloc.3 b/src/lib/libc/stdlib/malloc.3
index 4185648c84..d6c8b375ae 100644
--- a/src/lib/libc/stdlib/malloc.3
+++ b/src/lib/libc/stdlib/malloc.3
@@ -30,7 +30,7 @@
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.79 2014/10/19 17:58:14 doug Exp $ 33.\" $OpenBSD: malloc.3,v 1.80 2014/10/19 21:05:53 schwarze Exp $
34.\" 34.\"
35.Dd $Mdocdate: October 19 2014 $ 35.Dd $Mdocdate: October 19 2014 $
36.Dt MALLOC 3 36.Dt MALLOC 3
@@ -97,6 +97,14 @@ If the space cannot be allocated, the object
97pointed to by 97pointed to by
98.Fa ptr 98.Fa ptr
99is unchanged. 99is unchanged.
100If
101.Fa ptr
102is
103.Dv NULL ,
104.Fn realloc
105behaves like
106.Fn malloc
107and allocates a new object.
100.Pp 108.Pp
101The 109The
102.Fn reallocarray 110.Fn reallocarray
@@ -139,95 +147,38 @@ function is also provided for compatibility with old systems and other
139libraries; it is simply an alias for 147libraries; it is simply an alias for
140.Fn free . 148.Fn free .
141.Sh RETURN VALUES 149.Sh RETURN VALUES
142If 150Upon successful completion, the functions
143.Fn malloc , 151.Fn malloc ,
144.Fn calloc , 152.Fn calloc ,
145.Fn realloc , 153.Fn realloc ,
146or
147.Fn reallocarray
148is called with
149.Fa size
150or
151.Fa nmemb
152is equal to 0,
153a pointer to an access protected, zero sized object is returned.
154.Pp
155If
156.Fn malloc
157is called with
158.Fa size
159greater than 0, it returns a pointer to the allocated space if successful;
160otherwise, a
161.Dv NULL
162pointer is returned and
163.Va errno
164is set to
165.Er ENOMEM .
166.Pp
167The
168.Fn calloc
169function checks for integer overflow and returns
170.Dv NULL
171if
172.Fa nmemb
173*
174.Fa size
175will result in integer overflow.
176If
177.Fa nmemb
178and 154and
179.Fa size 155.Fn reallocarray
180are greater than 0, 156return a pointer to the allocated space; otherwise, a
181.Fn calloc
182returns a pointer to the allocated space if successful; otherwise, a
183.Dv NULL 157.Dv NULL
184pointer is returned and 158pointer is returned and
185.Va errno 159.Va errno
186is set to 160is set to
187.Er ENOMEM . 161.Er ENOMEM .
188.Pp
189The
190.Fn realloc
191function behaves like
192.Fn malloc
193for the specified
194.Fa size
195when
196.Fa ptr
197is
198.Dv NULL .
199If 162If
200.Fa size 163.Fa size
201is greater than 0, 164or
202.Fn realloc 165.Fa nmemb
203returns a pointer to the allocated space if successful; otherwise, a 166is equal to 0,
204.Dv NULL 167a pointer to an access protected, zero sized object is returned.
205pointer is returned and
206.Va errno
207is set to
208.Er ENOMEM .
209.Pp 168.Pp
210The 169If multiplying
211.Fn reallocarray
212function checks for integer overflow and returns
213.Dv NULL
214if
215.Fa nmemb 170.Fa nmemb
216* 171and
217.Fa size
218will result in integer overflow.
219If
220.Fn reallocarray
221is called with
222.Fa size 172.Fa size
173results in integer overflow,
174.Fn calloc
223and 175and
224.Fa nmemb 176.Fn reallocarray
225greater than 0, it returns a pointer to the allocated space if successful; 177return
226otherwise, a
227.Dv NULL 178.Dv NULL
228pointer is returned and 179and set
229.Va errno 180.Va errno
230is set to 181to
231.Er ENOMEM . 182.Er ENOMEM .
232.Pp 183.Pp
233The 184The
@@ -315,8 +266,8 @@ Code designed for some ancient platforms avoided calling
315with a 266with a
316.Dv NULL 267.Dv NULL
317.Fa ptr . 268.Fa ptr .
318Such hacks are no longer necessary in modern code. Instead of 269Such hacks are no longer necessary in modern code.
319this idiom: 270Instead of this idiom:
320.Bd -literal -offset indent 271.Bd -literal -offset indent
321if (p == NULL) 272if (p == NULL)
322 newp = malloc(newsize); 273 newp = malloc(newsize);
@@ -361,8 +312,8 @@ if ((p = malloc(size * num)) == NULL)
361 err(1, "malloc"); 312 err(1, "malloc");
362.Ed 313.Ed
363.Pp 314.Pp
364The above test is not sufficient in all cases. For example, multiplying 315The above test is not sufficient in all cases.
365ints requires a different set of checks: 316For example, multiplying ints requires a different set of checks:
366.Bd -literal -offset indent 317.Bd -literal -offset indent
367int size; 318int size;
368int num; 319int num;