OriginalBugID: 2715 Bug
Version: 8.2
SubmitDate: '1999-09-10'
LastModified: '2000-04-03'
Severity: SER
Status: Assigned
Submitter: techsupp
ChangedBy: hobbs
OS: Digital Unix
OSVersion: 4.0f
Machine: Other
FixedDate: '2000-10-25'
ClosedDate: '2000-10-25'
Name: Wolfgang S. Kechel
ReproducibleScript:
Many warnings and inconsistencies when compiling tcl8.2 with gcc-2.95
under Compaq True Unix 4.0f (no threads).
The problems are all related to 64/32 bit problems when allocating
memory.
All allocation problems should use long int for the size parameter.
Additionally, stdio.h should be included in some different lines in some
headers
to make gcc-2.95 happy with varargs. Here is a summary of changes:
generic/tclInt.h: move <tt>include <stdio.h></tt> behind the include
command for tcl.h (some 5 lines down).
generic/tcl.h: move <tt>include <stdio.h></tt> behind the include
command for stdarg.h/varargs.h to avoid compilation warnings on some
platforms
(namely Compaq True Unix 4.0f with gcc-2.95).
generic/tclCkalloc.c and generic/tclDecls.h: Change the
prototype/signature for Tcl_Alloc and Tcl_Realloc to use <tt>unsigned
long</tt> instead of <tt>unsigned int</tt>.
generic/tclalloc.c and generic/tclIntDecls.h: Change the
prototype/signature for TclpAlloc and TclpRealloc to use <tt>unsigned
long</tt> instead of <tt>unsigned int</tt>.
generic/tclAlloc.c, generic/tclInt.h: Change the if that checks aginat a
returned NULL pointer to check against a malloced size of 0 as well and
signal an error only when a NULL pointer is returned for a block of
memory that is of non-zero size:<br> <tt>if (result == NULL &&
size)</tt><br>This is around line 800 in the file.
DesiredBehavior:
Should compile with gcc-2.95 and -Wall -Wconversion without
warnings.
Patch:
diff tclInt.h /dv10/wke/g40/tcl8.2.0/generic
30,31d29
< #include <stdio.h>
<
35a34,35
> #include <stdio.h>
>
1697c1697
< EXTERN char * TclpAlloc _ANSI_ARGS_((unsigned int size));
---
> EXTERN char * TclpAlloc _ANSI_ARGS_((unsigned long size));
1742c1742
< unsigned int size));
---
> unsigned long size));
118% diff tcl.h /dv10/wke/g40/tcl8.2.0/generic
177,180d176
< #ifndef BUFSIZ
< #include <stdio.h>
< #endif
<
208a205,208
> #endif
>
> #ifndef BUFSIZ
> #include <stdio.h>
119% diff tclCkalloc.c /dv10/wke/g40/tcl8.2.0/generic
566c566,567
< unsigned int size;
---
> /* unsigned int size;*/
> unsigned long size; /* changed by wke */
581c582,583
< unsigned int size;
---
> /* unsigned int size;*/
> unsigned long size; /* changed by wke */
797c799,800
< unsigned int size;
---
> /* unsigned int size;*/
> unsigned long size; /* changed by wke */
802c805
< if (result == NULL)
---
> if (result == NULL && size)
839c842,843
< unsigned int size;
---
> /* unsigned int size;*/
> unsigned long size; /* changed by wke */
120% diff tclAlloc.c /dv10/wke/g40/tcl8.2.0/generic
246c246
< unsigned int nbytes; /* Number of bytes to allocate. */
---
> unsigned long nbytes; /* Number of bytes to allocate. */
492c492
< unsigned int nbytes; /* New size of memory. */
---
> unsigned long nbytes; /* New size of memory. */
664c664
< unsigned int nbytes; /* Number of bytes to allocate. */
---
> unsigned long nbytes; /* Number of bytes to allocate. */
712c712
< unsigned int nbytes; /* New size of memory. */
---
> unsigned long nbytes; /* New size of memory. */
121%
PatchFiles:
tclInt.h,tcl.h,tclCkalloc.c,tclAlloc.c
The problem with alloc'ing 0 bytes was fixed in 8.2.1. The other
changes can't be made as provided, as they only apply to a small
subset of platforms. We may need to parameterize this.
-- 10/19/1999 hobbs
This should really be using size_t's. This may be a problem for
non-ansi compilers if we change the headers in this way.
-- 04/03/2000 hobbs
Logged In: YES
user_id=79902
Not the time to sort this out properly, but SunOS4.1.4
system headers (*definitely* not ANSI, not with those ioctl
definitions!) define both size_t and caddr_t if you include
sys/types.h.
Logged In: YES
user_id=79902
Configure includes a helpful macro, AC_TYPE_SIZE_T, that
should solve this. Only problem then is to go through all
the places that should use it; experience suggests that it
is best to limit this to just the primary memory allocation
macros to prevent massive cross-contamination trouble...
Logged In: YES
user_id=79902
See also Bug #443938
Logged In: YES
user_id=79902
Some (all?) of these problems should be addressed as part
of TIP#115
Issue is cropping up again in
Tcl Bug 2494093.
Since we can't fix the API, seems
there needs to be an audit of
all the memory allocation callers
to check whether they permit
too large requests to be attempted
that get silently overflowed as
part of type casting.
I won't take any action on this until 9.0 because it is extremely disruptive to both APIs and ABIs on 64-bit platforms.
Fix in progress on novem-64bit-sizes branch; has a *heavy* impact on the C interface. https://core.tcl.tk/tcl/timeline?r=novem-64bit-sizes