Don't wrap thead limits when using a negative int

Signed-off-by: Tony Holdstock-Brown <tony@docker.com>
This commit is contained in:
Tony Holdstock-Brown 2016-05-03 16:03:22 -07:00
parent d0352a7448
commit c9c62380ff

View file

@ -96,7 +96,12 @@ func fromParametersImpl(parameters map[string]interface{}) (*DriverParameters, e
case uint64: case uint64:
maxThreads = v maxThreads = v
case int, int32, int64: case int, int32, int64:
maxThreads = uint64(reflect.ValueOf(v).Convert(reflect.TypeOf(threads)).Int()) val := reflect.ValueOf(v).Convert(reflect.TypeOf(threads)).Int()
// If threads is negative casting to uint64 will wrap around and
// give you the hugest thread limit ever. Let's be sensible, here
if val > 0 {
maxThreads = uint64(val)
}
case uint, uint32: case uint, uint32:
maxThreads = reflect.ValueOf(v).Convert(reflect.TypeOf(threads)).Uint() maxThreads = reflect.ValueOf(v).Convert(reflect.TypeOf(threads)).Uint()
case nil: case nil: