From c80c0ff4418562ca92558ce2456f574f5a658411 Mon Sep 17 00:00:00 2001 From: mappu Date: Fri, 24 Jan 2025 18:51:00 +1300 Subject: [PATCH] genbindings: fix indexing of zero-length byte arrays --- cmd/genbindings/emitgo.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cmd/genbindings/emitgo.go b/cmd/genbindings/emitgo.go index 18f6b4e8..f16421af 100644 --- a/cmd/genbindings/emitgo.go +++ b/cmd/genbindings/emitgo.go @@ -333,7 +333,11 @@ func (gfs *goFileState) emitParameterGo2CABIForwarding(p CppParameter) (preamble gfs.imports["unsafe"] = struct{}{} 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 += "} 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" rvalue = nameprefix + "_alias"