Weird behavior C.GoString

Hi,

I am trying to link C++ shared lib to my Go program.
When I convert a C string (* char) to Go string using C.GoString it adds an extra char, in a not deterministic way.
I print the bytes of my string inside C++ shared lib and it’s correct, with \0 on the end.

//Shared lib code
for(int j = 0; j < 23; j++) {
  std::cout << std::hex <<   (int)extractor_result->error_message[j] << " " ;
}
//Go Code
fmt.Printf("%X", C.GoString(extractorResult.error_message))

Shared lib always prints:

6d 69 73 6d 61 74 63 68 65 64 20 70 61 72 65 6e 74 68 65 73 69 73 0

Golang:
printf prints:

6D69736D61746368656420706172656E74686573697308
or
6D69736D61746368656420706172656E74686573697317
or
6D69736D61746368656420706172656E74686573697307
or
6D69736D61746368656420706172656E74686573697303
and so on.

Any tips about this issue?

Thanks

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.