Browse Source

Change realloc(foo,0) to behave like malloc(0). Both now return a pointer

to an object of size zero. This will allow testing on reallocs return value
to determine if the operation was successful or not.
OPENBSD_2_2
pefo 27 years ago
parent
commit
1350af0652
2 changed files with 8 additions and 8 deletions
  1. +7
    -4
      src/lib/libc/stdlib/malloc.3
  2. +1
    -4
      src/lib/libc/stdlib/malloc.c

+ 7
- 4
src/lib/libc/stdlib/malloc.3 View File

@ -33,7 +33,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE. .\" SUCH DAMAGE.
.\" .\"
.\" $OpenBSD: malloc.3,v 1.6 1997/05/31 08:55:05 tholo Exp $
.\" $OpenBSD: malloc.3,v 1.7 1997/08/23 10:43:24 pefo Exp $
.\" .\"
.Dd August 27, 1996 .Dd August 27, 1996
.Dt MALLOC 3 .Dt MALLOC 3
@ -77,6 +77,8 @@ coercion) for storage of any type of object. If the space is of
.Em pagesize .Em pagesize
or larger, the memory returned will be page-aligned. or larger, the memory returned will be page-aligned.
.Pp .Pp
Allocation of a zero size object returns a pointer to a zero size object.
.Pp
The The
.Fn free .Fn free
function causes the space pointed to by function causes the space pointed to by
@ -120,7 +122,8 @@ If
.Fa size .Fa size
is zero and is zero and
.Fa ptr .Fa ptr
is not a null pointer, the object it points to is freed.
is not a null pointer, the object it points to is freed and a new zero size
object is returned.
.Pp .Pp
Malloc will first look for a symbolic link called Malloc will first look for a symbolic link called
.Pa /etc/malloc.conf .Pa /etc/malloc.conf
@ -211,8 +214,8 @@ function returns no value.
.Pp .Pp
The The
.Fn realloc .Fn realloc
function returns either a null pointer or a pointer
to the possibly moved allocated space.
function a pointer to the possibly moved allocated space;
otherwise a null pointer is returned.
.Sh MESSAGES .Sh MESSAGES
If If
.Fn malloc , .Fn malloc ,


+ 1
- 4
src/lib/libc/stdlib/malloc.c View File

@ -8,7 +8,7 @@
*/ */
#if defined(LIBC_SCCS) && !defined(lint) #if defined(LIBC_SCCS) && !defined(lint)
static char rcsid[] = "$OpenBSD: malloc.c,v 1.28 1997/08/22 17:06:59 deraadt Exp $";
static char rcsid[] = "$OpenBSD: malloc.c,v 1.29 1997/08/23 10:43:25 pefo Exp $";
#endif /* LIBC_SCCS and not lint */ #endif /* LIBC_SCCS and not lint */
/* /*
@ -1234,9 +1234,6 @@ realloc(void *ptr, size_t size)
} }
if (!ptr) { if (!ptr) {
r = imalloc(size); r = imalloc(size);
} else if (ptr && !size) {
ifree(ptr);
r = 0;
} else { } else {
r = irealloc(ptr, size); r = irealloc(ptr, size);
} }


Loading…
Cancel
Save