tinycc-devel
[Top][All Lists]
Advanced

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

Re: [Tinycc-devel] zero length last member


From: Michael Matz
Subject: Re: [Tinycc-devel] zero length last member
Date: Wed, 24 Feb 2021 18:27:52 +0100 (CET)
User-agent: Alpine 2.21 (LSU 202 2017-01-01)

Hello,

On Wed, 24 Feb 2021, Yakov wrote:

Thanks for checking. I just tried again and I found that it only
crashes with `-run`. Actually I had `-run` misbehaving many times.
Just today strcpy() was SIGSEGV i.e.:.

int main() {
   char *c = malloc(6);
   strcpy(c, "hello");
}

That still leaves out much information. architecture and tcc version (or commit you used to compile tcc). Note that the above is a non-conforming program, you need a matching declaration of malloc and strcpy, so you need to include <stdlib.h> and <string.h>. Missing them at least malloc is assomed to return an 'int' which might have unintended consequences when assigned to the char pointer 'c'.


Ciao,
Michael.


вт, 23 февр. 2021 г. в 12:50, Elijah Stone <elronnd@elronnd.net>:

Are you running the latest version?  What architecture are you on?  Your
code compiles and runs without issue on my machine (amd64 linux, latest
git).

On Tue, 23 Feb 2021, Yakov wrote:

> https://gcc.gnu.org/onlinedocs/gcc/Zero-Length.html
>
> I have tried the last zero length member extension in tcc and
> compilation succeeded but the program crashes, is this a bug or a
> different implementation? Btw if you do not know this is a super
> useful extension.
>
> typedef struct {
>    int size;
>    int data[];
> } T;
>
> void main(){
>    T *t = malloc(500);
>    t->size = 2;
>    t->data[0] = 100;
>    t->data[1] = 200;
>    printf("%i %i %i\n", t->size, t->data[0], t->data[1]);
> }
>
> _______________________________________________
> Tinycc-devel mailing list
> Tinycc-devel@nongnu.org
> https://lists.nongnu.org/mailman/listinfo/tinycc-devel

_______________________________________________
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

_______________________________________________
Tinycc-devel mailing list
Tinycc-devel@nongnu.org
https://lists.nongnu.org/mailman/listinfo/tinycc-devel

reply via email to

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