libct/cg/fscommon: ParseKeyValue: stricter check

It makes sense to report an error if a key or a value is empty,
as we don't expect anything like this.

Reported-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
This commit is contained in:
Kir Kolyshkin
2025-01-06 13:37:52 -08:00
parent d83d533bba
commit ef983f5180
+2 -2
View File
@@ -60,8 +60,8 @@ func ParseUint(s string, base, bitSize int) (uint64, error) {
// "io_service_bytes 1234" will be returned as "io_service_bytes", 1234.
func ParseKeyValue(t string) (string, uint64, error) {
key, val, ok := strings.Cut(t, " ")
if !ok {
return "", 0, fmt.Errorf("line %q is not in key value format", t)
if !ok || key == "" || val == "" {
return "", 0, fmt.Errorf(`line %q is not in "key value" format`, t)
}
value, err := ParseUint(val, 10, 64)