skip null bytes at the end of strings

Signed-off-by: ston1th <ston1th@giftfish.de>
This commit is contained in:
ston1th 2020-09-01 14:09:41 +02:00
parent 26bd6bf99d
commit bdba65df16

View File

@ -20,11 +20,15 @@ import (
) )
func int8ToString(a []int8) string { func int8ToString(a []int8) string {
b := make([]byte, len(a)) buf := make([]byte, len(a))
for i, v := range a { for i, v := range a {
b[i] = byte(v) if byte(v) == 0 {
buf = buf[:i]
break
} }
return string(b) buf[i] = byte(v)
}
return string(buf)
} }
// unix._C_int // unix._C_int