Article View: comp.std.c
Article #5777Re: realloc
From: Unix Consultation Mailbox
Date: Wed, 29 Mar 1989 18:30
Date: Wed, 29 Mar 1989 18:30
24 lines
1770 bytes
1770 bytes
In article <10170@bloom-beacon.MIT.EDU> scs@adam.pika.mit.edu (Steve Summit) writes: >It is an apparently well- >kept secret that realloc is supposed to behave gracefully at >a slightly special-cased boundary point: when handed a NULL >pointer and a nonzero size, it acts essentially as a malloc. I'll say it's well-kept, neither the 4.2BSD nor SysV.2 manpages imply that calling realloc with first argument of 0 will do anything useful, let alone that it's *supposed* to. The SunOS 4.0.0 manpage even says that "[realloc will fail if] an invalid argument was specified. The value of ptr passed to [realloc] must be a pointer to a block previously allocated by malloc, calloc, realloc, valloc, or memalign." I'm afraid 0 doesn't qualify as a pointer to a legitimately-allocated block, so realloc *should* fail in this situation with errno == EINVAL. That's a far cry from "is supposed to ... [act] as a malloc." I suggest that you be more careful in the future about which effects of library functions are required and which are arbitrary and unreliable. (I wish all our programmers would do that too, it would keep me from having to do stupid things with null ptrs in my case-insensitive strcmp and other such garbage.) Phil Kos
Technical Details
Message-ID:
<2883@osiris.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!ukma!uflorida!haven!aplcen!osiris!consultReferences:
<10170@bloom-beacon.MIT.EDU>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!rutgers!ukma!uflorida!haven!aplcen!osiris!consult From: consult@osiris.UUCP (Unix Consultation Mailbox ) Newsgroups: comp.std.c,comp.lang.c Subject: Re: realloc Keywords: realloc NULL Message-ID: <2883@osiris.UUCP> Date: 29 Mar 89 18:30:20 GMT References: <10170@bloom-beacon.MIT.EDU> Reply-To: consult@osiris.UUCP (Unix Consultation Mailbox (Phil)) Organization: The Johns Hopkins Hospital, Information Systems Lines: 24