cmd/cgo: cgo allows creating values of incomplete struct/union type #40507
Labels
compiler/runtime
Issues related to the Go compiler and/or runtime.
NeedsDecision
Feedback is required from experts, contributors, and/or the community before a change can be made.
Milestone
This program builds, but fails at runtime:
This is because cgo defines incomplete struct/union types like
C.struct_s
andC.union_u
asstruct{}
, rather than giving an error. So thenew(C.struct_s)
andnew(C.union_u)
end up both allocating as zero-size objects.I think this program shouldn't build at all.
One reasonable fix would be to disallow incomplete
C.struct_*
orC.union_*
references outside of a pointer type. This might have false positives for things like:A more invasive but more robust fix would be a
//go:cgo_incomplete
directive that tells the compiler it shouldn't allow values of that type./cc @ianlancetaylor
(Noted while working on fix for #40494.)
The text was updated successfully, but these errors were encountered: