genbindings: fix indexing of zero-length byte arrays

This commit is contained in:
mappu 2025-01-24 18:51:00 +13:00
parent a80a93966d
commit c80c0ff441

View File

@ -333,7 +333,11 @@ func (gfs *goFileState) emitParameterGo2CABIForwarding(p CppParameter) (preamble
gfs.imports["unsafe"] = struct{}{} gfs.imports["unsafe"] = struct{}{}
preamble += nameprefix + "_alias := C.struct_miqt_string{}\n" preamble += nameprefix + "_alias := C.struct_miqt_string{}\n"
preamble += "if len(" + p.ParameterName + ") > 0 {\n"
preamble += nameprefix + "_alias.data = (*C.char)(unsafe.Pointer(&" + p.ParameterName + "[0]))\n" preamble += nameprefix + "_alias.data = (*C.char)(unsafe.Pointer(&" + p.ParameterName + "[0]))\n"
preamble += "} else {\n"
preamble += nameprefix + "_alias.data = (*C.char)(unsafe.Pointer(nil))\n"
preamble += "}\n"
preamble += nameprefix + "_alias.len = C.size_t(len(" + p.ParameterName + "))\n" preamble += nameprefix + "_alias.len = C.size_t(len(" + p.ParameterName + "))\n"
rvalue = nameprefix + "_alias" rvalue = nameprefix + "_alias"