Fix malformed uname string (#2727)

* Fix malformed uname string

* Make fix better

* Reformat code for simplicity
This commit is contained in:
Shashank Varanasi 2017-05-16 22:14:11 +05:30 committed by Fabian Reinartz
parent 713fef292a
commit dea60bb553
3 changed files with 15 additions and 8 deletions

View File

@ -25,6 +25,7 @@ func Uname() string {
if err != nil {
log.Fatal("Error!")
}
str := "(" + charsToString(buf.Sysname[:])
str += " " + charsToString(buf.Release[:])
str += " " + charsToString(buf.Version[:])

View File

@ -17,9 +17,12 @@
package main
func charsToString(ca []int8) string {
s := make([]byte, len(ca))
for i, c := range ca {
s[i] = byte(c)
s := make([]byte, 0, len(ca))
for _, c := range ca {
if byte(c) == 0 {
break
}
s = append(s, byte(c))
}
return string(s[0:len(ca)])
return string(s)
}

View File

@ -17,9 +17,12 @@
package main
func charsToString(ca []uint8) string {
s := make([]byte, len(ca))
for i, c := range ca {
s[i] = byte(c)
s := make([]byte, 0, len(ca))
for _, c := range ca {
if byte(c) == 0 {
break
}
s = append(s, byte(c))
}
return string(s[0:len(ca)])
return string(s)
}