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
1 changed files with 7 additions and 3 deletions

View File

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