Artifacts Associated With Ticket 1259431fffffffffffffffffffffffffffffffff
Ticket change [1fccfc45e9] (rid 91207) by mdejong on 2005-08-15 01:03:29:
- assignee initialized to: "hobbs"
- cmimetype initialized to: "text/plain"
- comment initialized to:
I ran into a little problem where a bug in code to call ckalloc ended up trying to allocate 0 bytes. That crashed in the Win32 malloc when compiled with Mingw. I can't see any reason to allow a zero byte allocation, and it seems like adding a test like the following could not hurt. Any objections? --- generic/tclCkalloc.c 19 Jan 2003 07:21:18 -0000 1.19 +++ generic/tclCkalloc.c 15 Aug 2005 00:59:24 -0000 @@ -373,6 +373,10 @@ if (validate_memory) Tcl_ValidateAllMemory (file, line); + if (size == 0) { + panic("attempt to ckalloc 0 bytes, %s line %d", size, file, line); + } + result = (struct mem_header *) TclpAlloc((unsigned)size + sizeof(struct mem_header) + HIGH_GUARD_SIZE); if (result == NULL) { - foundin initialized to: "None"
- priority initialized to: "2"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "mdejong"
- subsystem initialized to: "41. Memory Allocation"
- title initialized to: "Check for 0 byte allocation in ckalloc"
- type initialized to: "Patch"
Ticket change [1ffb3fea7b] (rid 91234) by mdejong on 2005-08-15 08:03:29:
- icomment:
File Added - 145666: ckalloc.patch
- login: "mdejong"
- mimetype: "text/plain"
- username: "mdejong"
- icomment:
Add attachment "ckalloc.patch" [315aa588d8] (rid 93414) by mdejong on 2005-08-15 08:03:29.
Ticket change [3e8e8d281a] (rid 121290) by mistachkin on 2005-08-15 08:33:55:
- icomment:
Logged In: YES user_id=113501 I don't think we should take this patch, it breaks compatibility with malloc(), which is technically allowed to allocate a "zero byte item" and return it. The ANSI C standard states that this is "implementation defined"; however, we should probably just treat it as a one byte request.
- login: "mistachkin"
- mimetype: "text/plain"
- username: "mistachkin"
- icomment:
Ticket change [ad11bedadc] (rid 101407) by dkf on 2005-08-15 22:03:30:
- icomment:
Logged In: YES user_id=79902 The core currently checks (in Tcl_Alloc()) to see whether a NULL low-level alloc result is coming from asking for zero bytes; if so, it *doesn't* panic. This indicates that panic-ing on zero-alloc is probably wrong.
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [cf1e89c3d3] (rid 112910) by hobbs on 2005-08-16 00:19:21:
- priority changed to: "4"
Ticket change [60f3b9d7e1] (rid 92158) by hobbs on 2005-08-16 00:19:22:
- icomment:
Logged In: YES user_id=72656 We certainly shouldn't panic on 0 alloc requests - that is perfectly valid in the C standard. I see where Mo is requesting the patch we do seem to have a latent bug in that we shouldn't panic on (result == NULL) unless (size != 0), as AIX and some other systems do return NULL for 0-byte allocs. If a crash occured in the mingw compile, than I would backtrack to the sources making the alloc, as ckalloc(0)/malloc(0) is valid C. We did have to correct code in tkImg*.c once regarding this (0 size image allocs) because we simply weren't handling the case of such requests - which was a bug in the image code, not in ckalloc(0) per se.
- login: "hobbs"
- mimetype: "text/plain"
- username: "hobbs"
- icomment:
Ticket change [14ef48dae1] (rid 124477) by hobbs on 2005-10-05 07:01:18:
- icomment:
Logged In: YES user_id=72656 OK, this is the DB routines, and result == NULL panic is OK because we add guard bytes. IOW, if we don't get mem, we don't have any to get ....
- login: "hobbs"
- mimetype: "text/plain"
- resolution changed to: "Wont Fix"
- status changed to: "Pending"
- username: "hobbs"
- icomment:
Ticket change [3c066bd949] (rid 120847) by hobbs on 2005-10-05 07:01:19:
- closedate changed to: "2005-10-05T00:01:19"
- closer changed to: "hobbs"
Ticket change [f43188c42e] (rid 129867) by sf-robot on 2005-10-19 09:20:53:
- closedate changed to: "2005-10-19T02:20:53"
- closer changed to: "sf-robot"
- icomment:
Logged In: YES user_id=1312539 This Tracker item was closed automatically by the system. It was previously set to a Pending status, and the original submitter did not respond within 14 days (the time period specified by the administrator of this Tracker).
- login: "sf-robot"
- mimetype: "text/plain"
- status changed to: "Closed"
- username: "sf-robot"