Alerting: Use unsafe.Slice for hashing a string during rule fingerprint calculation (#71000)

This commit is contained in:
Yuri Tseretyan 2023-06-30 14:58:23 -04:00 committed by GitHub
parent 0817ee00f9
commit ada325de2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -263,12 +263,8 @@ func (r ruleWithFolder) Fingerprint() fingerprint {
writeBytes(nil)
return
}
// TODO fix it when upgraded to in GO1.20 to
/*
writeBytes(unsafe.Slice(unsafe.StringData(s), len(s))) //nolint:gosec
*/
// avoid allocation when converting string to byte slice
writeBytes(*(*[]byte)(unsafe.Pointer(&s))) //nolint:gosec
writeBytes(unsafe.Slice(unsafe.StringData(s), len(s)))
}
// this temp slice is used to convert ints to bytes.
tmp := make([]byte, 8)