tinycc-devel
[Top][All Lists]
Advanced

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

[Tinycc-devel] Avoid allocating a VLA of size zero


From: Pascal Cuoq
Subject: [Tinycc-devel] Avoid allocating a VLA of size zero
Date: Wed, 12 Jun 2019 20:39:43 +0000

Hello,

Arrays of size zero are not part of standard C, even when they are Variable Length Arrays (https://port70.net/~nsz/c/c11/n1570.html#6.7.6.2p5 ). GCC accepts arrays of size 0 as an extension, but since TCC's small size and being implemented in C in the first place may lead it to be compiled with any C compiler, you may consider it desirable to make sure it's written in portable C when reasonable. This is orthogonal to having TCC accepts GCC extensions, perhaps including this one. What I'm saying is, it can be considered better to have TCC being written in portable C for when it's not compiled with GCC or TCC.


In non-TCC_TARGET_PE mode, the function gfunc_call in the file x86_64-gen.c creates a VLA of size 0 when it is called with nb_args == 0:

void gfunc_call(int nb_args)
{
    ...
    char _onstack[nb_args], *_onstack_ = _onstack;

Assuming you agree it would be preferable not to, this can be fixed in several ways. The change below, for which a patch is attached, may be the one with the least impact:

void gfunc_call(int nb_args)
{
    ....
    int _onstack_size_ = nb_args == 0 ? 1 : nb_args;
    char _onstack[onstack_size], *_onstack_ = _onstack;

Best regards,

Pascal

Attachment: nb_args_zero.patch
Description: nb_args_zero.patch


reply via email to

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