Re: SWIG: Bug with 'C' arrays of zero size ?

William S Fulton <[email protected]>
Newsgroups gmane.comp.programming.swig
Message-ID <CANGqftBr10vhDNtFeSUqkVrAoKUW_HLL+BavPD3NLCQrVcuqKw@mail.gmail.com>
On Fri, 12 Jun 2020 at 09:37, Terry Barnaby <[email protected]> wrote:

> Hi,
>
> If you have a data structure like the following all is well:
>
> struct DataBlock {
>      Header    header;
>      char        data[4];    ///< The packet data
> };
>
> However if you have a data structure that has a zero length array like
> the following, SWIG considers the "char data[]" as a pointed to data and
> tries to delete[] and allocate memory for it.
>
> struct DataBlock {
>     Header    header;
>      char        data[];    ///< The packet data
> };
>
> I think this is a bug ?
>
>
Hi Terry

This is a pointer to an undetermined array of char characters. By default
SWIG chooses to wrap this a pointer to a NULL terminated array of
characters, that is, a string. There is no bug here!

You can use typemaps to change the behaviour to whatever you want.

William


On Fri, 12 Jun 2020 at 09:37, Terry Barnaby <[email protected]> wrote:

> Hi,
>
> If you have a data structure like the following all is well:
>
> struct DataBlock {
>      Header    header;
>      char        data[4];    ///< The packet data
> };
>
> However if you have a data structure that has a zero length array like
> the following, SWIG considers the "char data[]" as a pointed to data and
> tries to delete[] and allocate memory for it.
>
> struct DataBlock {
>     Header    header;
>      char        data[];    ///< The packet data
> };
>
> I think this is a bug ?
>
> Terry
>
>
>
> _______________________________________________
> Swig-user mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/swig-user
>

_______________________________________________
Swig-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/swig-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.