From: SourceForge.net <no...@so...> - 2005-08-15 15:03:31
|
Patches item #1259431, was opened at 2005-08-15 02:03 Message generated for change (Comment added) made by dkf You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=310894&aid=1259431&group_id=10894 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: 40. Memory Allocation Group: None Status: Open Resolution: None Priority: 2 Submitted By: Mo DeJong (mdejong) Assigned to: Jeffrey Hobbs (hobbs) Summary: Check for 0 byte allocation in ckalloc Initial Comment: 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) { ---------------------------------------------------------------------- >Comment By: Donal K. Fellows (dkf) Date: 2005-08-15 16:03 Message: 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. ---------------------------------------------------------------------- Comment By: Joe Mistachkin (mistachkin) Date: 2005-08-15 02:33 Message: 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. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=310894&aid=1259431&group_id=10894 |