Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2024-05-25
12:54 • Closed ticket [219196ffff]: size_t != unsigned int plus 6 other changes artifact: 68e527b040 user: dkf
2013-08-21
09:59 • Ticket [219196ffff]: 9 changes artifact: 0f96bfcdaa user: dkf
2012-11-20
19:18 • Ticket [219196ffff]: 4 changes artifact: f0df76c44b user: dkf
2009-03-24
23:21 • Ticket [219196ffff]: 4 changes artifact: 4ed41ebdc6 user: dkf
2009-01-09
21:55 • Ticket [219196ffff]: 4 changes artifact: ce0293b067 user: dgp
2004-06-16
17:49 • Ticket [219196ffff]: 1 change artifact: d19cce9984 user: dkf
2003-02-10
20:47 • Ticket [219196ffff]: 5 changes artifact: 7cd9208296 user: dkf
2002-07-31
17:29 • Ticket [219196ffff]: 1 change artifact: 4ceedb1f87 user: dkf
2002-04-25
19:18 • Ticket [219196ffff]: 4 changes artifact: 18bce3ea2f user: dkf
2001-12-18
22:34 • Ticket [219196ffff]: 4 changes artifact: 785463f57b user: dkf
2001-12-14
18:22 • Ticket [219196ffff]: 4 changes artifact: ca2ab1a19d user: dkf
2001-09-08
06:28 • Ticket [219196ffff]: 1 change artifact: 363f0e5a66 user: andreas_kupries
2001-04-05
06:52 • Ticket [219196ffff]: 1 change artifact: 9c26ae8d8a user: dgp
2000-10-26
05:03 • New ticket [219196ffff]. artifact: 4d8d0ef312 user: nobody

size_t != unsigned int

Closed / Fixed219196ffffffffffffffffffffffffffffffffffCreated 26 years agoUpdated 3 years ago
Descriptionplain2000-10-26 05:03:25
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
dgp Ticket [219196ffff]: 1 change [History diff]2001-04-05 06:52:46
andreas_kupries Ticket [219196ffff]: 1 change [History diff]2001-09-08 06:28:52
dkfplain2001-12-14 18:22:41
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.
dkfplain2001-12-18 22:34:28
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...
dkfplain2002-04-25 19:18:06
Logged In: YES 
user_id=79902

See also Bug #443938
dkf Ticket [219196ffff]: 1 change [History diff]2002-07-31 17:29:35
dkfplain2003-02-10 20:47:49
Logged In: YES 
user_id=79902

Some (all?) of these problems should be addressed as part 
of TIP#115
dkf Ticket [219196ffff]: 1 change [History diff]2004-06-16 17:49:26
dgpplain2009-01-09 21:55:48
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.
dkfplain2009-03-24 23:21:31
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.
dkfplain2012-11-20 19:18:50
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
dkfwiki2013-08-21 09:59:49

Formally, this isn't part of any particular subsystem; it's a cross-cutting issue.

dkfmarkdown2024-05-25 12:54:35

Fixed in 9.0, at least to the standard required by this issue.

Log in (anonymous is fine) to add a comment.