Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2001-04-19
03:24 • Ticket [218924ffff] malloc(0) == NULL on AIX is not an error status still Cl... artifact: 01fcf4fcbe user: dgp
2000-10-26
08:31 • Closed ticket [218924ffff]. artifact: 6a985fe54f user: welch
01:07 • New ticket [218924ffff]. artifact: 595ab49951 user: nobody

malloc(0) == NULL on AIX is not an error

Closed / Fixed218924ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 26 years ago
Descriptionplain2000-10-26 01:07:57
OriginalBugID: 2795 Bug
Version: 8.2
SubmitDate: '1999-09-16'
LastModified: '1999-09-18'
Severity: MED
Status: Released
Submitter: techsupp
ChangedBy: hobbs
RelatedBugIDs: 2518
OS: AIX
OSVersion: 4.3.2
Machine: RS6000
FixedDate: '1999-09-18'
FixedInVersion: 8.2.1
ClosedDate: '2000-10-25'


Name:

Nick Kisseberth



Comments:

Tcl_Alloc(0) should either always return NULL when asked for 0 bytes

    or should always return a unique pointer. It shouldn't maintain the

    "implementation defined" definition ANSI gives malloc(0). So for AIX

    it could just convert a request for 0 bytes to a request for 1 byte.

    I prefer Tcl_Alloc(0) to return NULL, but I suspect I'll be in the 

    minority.



ObservedBehavior:

Tcl doesn't like malloc(0) returning NULL. This is valid ANSI C

    behavior (malloc(0) is implementation defined, must return NULL or

    unique pointer). Tcl_Alloc will panic because of this.



DesiredBehavior:

malloc(0)==NULL should be permitted



Patch:

*** tcl8.2.0/generic/tclCkalloc.c       Tue Aug 10 11:09:45 1999

--- tcl8.2.0-AIX/generic/tclCkalloc.c   Thu Sep  9 11:46:12 1999

***************

*** 799,805 ****

          char *result;

  

          result = TclpAlloc(size);

!         if (result == NULL) 

                  panic("unable to alloc %d bytes", size);

          return result;

  }

--- 799,805 ----

          char *result;

  

          result = TclpAlloc(size);

!         if ((result == NULL) && (size != 0))

                  panic("unable to alloc %d bytes", size);

          return result;

  }



PatchFiles:

generic/tclCkalloc.c





A more complete patch in the above style is included for 8.2.1. 
-- 09/18/1999 hobbs
welch Closed ticket [218924ffff]. [History diff]2000-10-26 08:31:17
dgp Ticket [218924ffff]: 3 changes [History diff]2001-04-19 03:24:06
Log in (anonymous is fine) to add a comment.