Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2011-01-25
22:57 • Ticket [3129448fff] possible over-allocation on 64-bit platforms status stil... artifact: f297ba27d4 user: nijtmans
2010-12-11
04:56 • Add attachment 3129448_2.patch to ticket [3129448fff] artifact: fda86e9eb3 user: nijtmans
04:56 • Ticket [3129448fff] possible over-allocation on 64-bit platforms status stil... artifact: 212d4305c2 user: nijtmans
04:55 • Ticket [3129448fff]: 4 changes artifact: 0f1567927d user: nijtmans
2010-12-06
23:12 • Ticket [3129448fff]: 4 changes artifact: 43326406b2 user: nijtmans
21:54 • Ticket [3129448fff]: 4 changes artifact: d2890a1eef user: dgp
21:49 • Ticket [3129448fff]: 4 changes artifact: 22b33f2ebf user: dgp
16:02 • Closed ticket [3129448fff]. artifact: 931f755607 user: nijtmans
15:46 • Ticket [3129448fff]: 4 changes artifact: 0f24ce7e18 user: nijtmans
15:46 • Add attachment 3129448.patch to ticket [3129448fff] artifact: 4b3c9ac2e6 user: nijtmans
15:45 • Ticket [3129448fff] possible over-allocation on 64-bit platforms status stil... artifact: 74d0d1fb27 user: nijtmans
08:44 • New ticket [3129448fff]. artifact: 8ef3114b57 user: nijtmans

possible over-allocation on 64-bit platforms

Closed / Fixed3129448fffffffffffffffffffffffffffffffffCreated 16 years agoUpdated 16 years ago
Descriptionplain2010-12-06 08:44:52
Inspired by bug #3127687, noted that on 64-bit
platforms, where sizeof(integer) == 8, some structures
are over-allocated because sizeof() might count
additional padding bytes. That's no big deal, except
that it is strange anyway to use [4] as the number
of bytes in the structure.

Solution: use the TclOffset macro to calculate the
right size, in stead of substracting two sizeof()'s. That
will correctly take padding bytes into account.

patch attached
nijtmans Ticket [3129448fff]: 1 change [History diff]2010-12-06 15:45:26
nijtmansplain2010-12-06 15:46:41
File Added - 395354: 3129448.patch
nijtmansplain2010-12-06 16:02:31
allow_comments - 1

Fixed in HEAD

don't bother for Tcl 8.5 and lower
dgpplain2010-12-06 21:49:51
what does "integer" mean in this report?  int ? long int ?
dgpplain2010-12-06 21:54:28
Hmmm... the actual patch applies doesn't
appear to have anything to do with integers,
but with pointer sizes and alignment matters.

Is there a platform on which the effectiveness
of the patch is actually tested?
nijtmansplain2010-12-06 23:12:12
Here is a small test program (try it on any UNIX machine) which shows the
dirrerence between substracting two sizes or determining the offset.

This program prints:
    12 8

Here I used a long long as data type in stead of an int. It will occur
on any machine where sizeof(int) = 8.

=====================================================
#include <stdio.h>
#define TclOffset(type, field) \
((int) ((char *) &((type *) 0)->field))
typedef struct {
long long dummy;
char buf[4];
} mytype;
void main() {
mytype x;
int answer1 = sizeof(x) - sizeof(x.buf);
int answer2 = (unsigned)TclOffset(mytype, buf);
printf("%d %d\n", answer1, answer2);
}
nijtmansplain2010-12-11 04:55:55
Part 2, a few more places where the same pattern was used. Patch attached.
nijtmansplain2010-12-11 04:56:25
File Added - 395809: 3129448_2.patch
nijtmansplain2011-01-25 22:57:50
backported strcpy->memcpy changes to 8.5 and 8.4 as well, not any other struct change
Log in (anonymous is fine) to add a comment.

Attachments: