I am not an expert in TCC, but does this mean that my patch is OK ? And will it be incorporated in the next TCC release ? By the way, we use TCC 0.9.21 to generate bytecode for our virtual machine and TCC 0.9.21 has the same bug.
Alex. Regards. -----Ursprüngliche Nachricht----- Von: [email protected] [mailto:[email protected]] Im Auftrag von grischka Gesendet: Montag, 2. Februar 2009 15:03 An: [email protected] Betreff: Re: AW: [Tinycc-devel] Memory allocation and initialization of arrayswithdimension % 2 = 0 Alexander Egorenkov wrote: > > Here is the correct patch. > Thanks. If you happen to have GIT around please feel free to push your patch on our "mob" branch: git push ssh://[email protected]/srv/git/tinycc.git mypatch:mob --- grischka > --------------------------------------------------------------------------- > --- 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: [email protected] > [mailto:[email protected]] > Im Auftrag von Alexander Egorenkov > Gesendet: Montag, 2. Februar 2009 12:21 > An: [email protected] > 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 > [email protected] > http://lists.nongnu.org/mailman/listinfo/tinycc-devel > > > _______________________________________________ > Tinycc-devel mailing list > [email protected] > http://lists.nongnu.org/mailman/listinfo/tinycc-devel > _______________________________________________ Tinycc-devel mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/tinycc-devel _______________________________________________ Tinycc-devel mailing list [email protected] http://lists.nongnu.org/mailman/listinfo/tinycc-devel
