From 1177b089f5285aadf8eab72bcbbdce553ff03e36 Mon Sep 17 00:00:00 2001 From: Ian Lance Taylor Date: Thu, 12 Jul 2018 11:57:05 -0700 Subject: [PATCH] cmd/cgo: add note about bug writing C pointers to uninitialized C memory Describe the problem as a bug, since it is not implied by the rest of the pointer passing rules, and it may be possible to fix it. Updates #19928 Change-Id: I2d336e7336b2a215c0b8cf909a203201ef1b054e Reviewed-on: https://go-review.googlesource.com/123658 Reviewed-by: Austin Clements --- src/cmd/cgo/doc.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/cmd/cgo/doc.go b/src/cmd/cgo/doc.go index 4bd82ebd12..980906b921 100644 --- a/src/cmd/cgo/doc.go +++ b/src/cmd/cgo/doc.go @@ -377,6 +377,14 @@ and of course there is nothing stopping the C code from doing anything it likes. However, programs that break these rules are likely to fail in unexpected and unpredictable ways. +Note: the current implementation has a bug. While Go code is permitted +to write nil or a C pointer (but not a Go pointer) to C memory, the +current implementation may sometimes cause a runtime error if the +contents of the C memory appear to be a Go pointer. Therefore, avoid +passing uninitialized C memory to Go code if the Go code is going to +store pointer values in it. Zero out the memory in C before passing it +to Go. + Special cases A few special C types which would normally be represented by a pointer -- 2.48.1