The struct wrappers generated by the FFI generate code where arrays of size 0 are allocated (?)
I have a guess at what the problem is and how to fix this, but I have not worked in this area of the compiler before. @sbs can you confirm this makes sense? Then I will implement the fix.
Bug
(From Stdlib Vector3f)
In the function SACf_Vector3f__wrap__struct_Vector3f__sa_S__sa_S__sa_S, we generate code that allocates an AKS of size 0:
SAC_ND_ALLOC_BEGIN((SACp_emal_5145__ggtc_943, (AKS, (NHD, (NUQ, (INT, (GLO, (NON, (NOT, (OTH, ))))))))), 1, 1, SACarg *)
and the compiler rightfully complains that malloc(0) is implementation-defined behaviour. If it is intended that this array has size 0, we should set it to NULL.
Proposed fix
We can insert a check (SAC_ND_A_SIZE (var_NT) == NULL) as in the AKS case, the C-compiler knows statically that this is 0 and will optimize the check away.
I think this variable comes from generate_generic_type_conversions.c:
/* Here, we build the standard variant:
*
*external
* SACarg(---) <ns>::wrap_<name> (<ns>::<name>[*] arg);
* #pragma linkname "SACARGwrap_<ns>__<name>"
* #pragma linksign [1,2]
*/
argtype = TYmakeAUD (TYcopyType (TYgetScalar (type)));
rettype = TYmakeAKS (TYmakeSacargSimpleType (UT_NOT_DEFINED),
SHmakeShape (0));
which does suggest it is intended.