GeertJohan / GeertJohan/cgo.wchar

Panic when running 'go test' on cc4deff

Open
#2 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
14
Forks
9
PR merge metrics
No merged PRs in 30d

Description

Hi

Running 'go test' on masters tip presents me with the following error:

http://sillymon.ch/data/gotesterror.txt

I am running Go tip at

go version devel +6e10ddc0bbc2 Tue May 13 12:17:49 2014 -0700 + linux/amd64

The panic seems to occur in the Go runtime at runtime/mcentral.c because of an empty memory list (the cause seems to be the `runeCString := C.CString(string(r))` line in convert.go:184). Can you see anything obviously wrong?

Interestingly enough, after applying the following patch

```
diff --git a/convert.go b/convert.go
index e669ba9..97e9974 100644
--- a/convert.go
+++ b/convert.go
@@ -173,7 +173,7 @@ func convertGoRuneToWchar(r rune) (output Wchar, err error) {

// bufferSizes for C
bytesLeftInCSize := C.size_t(4)
- bytesLeftOutCSize := C.size_t(4 * 4)
+ bytesLeftOutCSize := C.size_t(4)
// TODO/FIXME: the last 4 bytes as indicated by bytesLeftOutCSize wont be used...
// iconv assumes each given char to be one wchar.
// in this case we know that the given 4 chars will actually be one unicode-point and therefore will result in one wchar.
```

the tests run (no panic occurs) but iconv(3) sets errno to E2BIG which indicates that the output buffer is too small. This seems odd to me because according to the iconv(3) man page both sizes are in bytes and since a Golang rune is encoded in UTF-8 (and will only contain one Unicode code point) both sizes should never have to be bigger than 4 bytes when converting one rune. I hit this 'go test' issue when I was trying to correct the output buffer size issue.

I also do not know why changing the value of the bytesLeftOutCSize function parameter would result in the C.CString copy suddenly working... any ideas?

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the failure with `go test` at the referenced revision, then inspect `convert.go:184` and the surrounding `convertGoRuneToWchar` code alongside the reported `runtime/mcentral.c` panic. Check the `iconv(3)` buffer-size behavior and determine why the `C.CString` call is affected; done means the panic is explained and tests complete without incorrect buffer sizing or an unexpected E2BIG error.

Written by the indexing model from the issue text.

Assessment

Tech stack
c, go
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.