Skip to content

Commit 1177b08

Browse files
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 <[email protected]>
1 parent b323709 commit 1177b08

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/cmd/cgo/doc.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,14 @@ and of course there is nothing stopping the C code from doing anything
377377
it likes. However, programs that break these rules are likely to fail
378378
in unexpected and unpredictable ways.
379379
380+
Note: the current implementation has a bug. While Go code is permitted
381+
to write nil or a C pointer (but not a Go pointer) to C memory, the
382+
current implementation may sometimes cause a runtime error if the
383+
contents of the C memory appear to be a Go pointer. Therefore, avoid
384+
passing uninitialized C memory to Go code if the Go code is going to
385+
store pointer values in it. Zero out the memory in C before passing it
386+
to Go.
387+
380388
Special cases
381389
382390
A few special C types which would normally be represented by a pointer

0 commit comments

Comments
 (0)