mirror of
https://github.com/prometheus/prometheus
synced 2025-01-13 02:14:08 +00:00
Fix malformed uname string (#2727)
* Fix malformed uname string * Make fix better * Reformat code for simplicity
This commit is contained in:
parent
713fef292a
commit
dea60bb553
@ -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[:])
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user