[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Tinycc-devel] Memory allocation and initialization of arrays with dimen
From: |
Alexander Egorenkov |
Subject: |
[Tinycc-devel] Memory allocation and initialization of arrays with dimension % 2 = 0 |
Date: |
Mon, 2 Feb 2009 12:21:01 +0100 |
Hi TCC developers,
i think, found a bug with memory allocation and initialization of arrays
with dimensions 2, 4, 6 etc.
Example (x86, linux, tinycc 0.9.24):
----------------------------------------------------
#include <stdio.h>
int main(int argc, char **argv)
{
int a[] = { 1, 2, 3, 4 };
int b[][] = { { 5, 6 }, { 7 , 8 } };
printf("%d %d %d %d\n", a[0], a[1], a[2], a[3]);
return 0;
}
----------------------------------------------------
Output:
----------------------------------------------------
5 6 7 4
----------------------------------------------------
The problem is in the function tcc.c:type_size.
I could solve the problem by appling the following patch:
----------------------------------------------------
--- tcc.c.old Mon Feb 2 11:18:15 2009
+++ tcc.c.new Mon Feb 2 11:19:00 2009
@@ -6130,8 +6130,15 @@
return s->c;
} else if (bt == VT_PTR) {
if (type->t & VT_ARRAY) {
+ int ts;
+
s = type->ref;
- return type_size(&s->type, a) * s->c;
+ ts = type_size(&s->type, a) * s->c;
+
+ if (ts < 0 && s->c < 0)
+ ts = -ts;
+
+ return ts * s->c;
} else {
*a = PTR_SIZE;
return PTR_SIZE;
----------------------------------------------------
Alex.
Regards.
- [Tinycc-devel] Memory allocation and initialization of arrays with dimension % 2 = 0,
Alexander Egorenkov <=