mirror of
https://github.com/containers/podman.git
synced 2026-07-10 23:35:04 -04:00
Merge pull request #29036 from grey3228/fix/convert_number_typo
systemd: fix negative number conversion
This commit is contained in:
@@ -661,7 +661,7 @@ func convertNumber(v string) (int64, error) {
|
||||
v = v[1:]
|
||||
} else if strings.HasPrefix(v, "-") {
|
||||
v = v[1:]
|
||||
mult = int64(-11)
|
||||
mult = int64(-1)
|
||||
}
|
||||
|
||||
switch {
|
||||
|
||||
@@ -371,6 +371,32 @@ func TestLookupQuoteStripping(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestLookupIntParsesSignedNumbers(t *testing.T) {
|
||||
unit := NewUnitFile()
|
||||
unit.Add("Service", "Positive", "42")
|
||||
unit.Add("Service", "ExplicitPositive", "+42")
|
||||
unit.Add("Service", "Negative", "-42")
|
||||
unit.Add("Service", "Hex", "0x2a")
|
||||
unit.Add("Service", "Octal", "052")
|
||||
|
||||
tests := []struct {
|
||||
key string
|
||||
expected int64
|
||||
}{
|
||||
{"Positive", 42},
|
||||
{"ExplicitPositive", 42},
|
||||
{"Negative", -42},
|
||||
{"Hex", 42},
|
||||
{"Octal", 42},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.key, func(t *testing.T) {
|
||||
assert.Equal(t, tt.expected, unit.LookupInt("Service", tt.key, 0))
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func FuzzParser(f *testing.F) {
|
||||
for _, sample := range samples {
|
||||
f.Add([]byte(sample))
|
||||
|
||||
Reference in New Issue
Block a user