tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

AW: [Tinycc-devel] Memory allocation and initialization of arrays withdi


From: Alexander Egorenkov
Subject: AW: [Tinycc-devel] Memory allocation and initialization of arrays withdimension % 2 = 0
Date: Mon, 2 Feb 2009 12:23:55 +0100

Sorry, i did a mistake.

Here is the correct patch.

---------------------------------------------------------------------------
--- tcc.c.old   Mon Feb  2 11:18:15 2009
+++ tcc.c.new   Mon Feb  2 11:22:31 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);
+
+            if (ts < 0 && s->c < 0)
+                ts = -ts;
+
+            return ts * s->c;
         } else {
             *a = PTR_SIZE;
             return PTR_SIZE;
-----------------------------------------------------------------------------

Alex.

Regards.

-----Urspr√ľngliche Nachricht-----
Von: address@hidden [mailto:address@hidden Im Auftrag von Alexander Egorenkov
Gesendet: Montag, 2. Februar 2009 12:21
An: address@hidden
Betreff: [Tinycc-devel] Memory allocation and initialization of arrays 
withdimension % 2 = 0


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 mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/tinycc-devel




reply via email to

[Prev in Thread] Current Thread [Next in Thread]