Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Fixed #1080 rules for int/floats crash plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
candysmurf committed Jul 16, 2016
1 parent 94820fb commit 189f94c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
17 changes: 8 additions & 9 deletions control/plugin/cpolicy/float.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,22 @@ func (f *FloatRule) GobDecode(buf []byte) error {
return nil
}

// NewFloatRule Returns a new float-typed rule. Arguments are key(string), required(bool), default(float64), min(float64), max(float64)
// NewFloatRule returns a new float-typed rule. Arguments are key(string), required(bool), default(float64)
func NewFloatRule(key string, req bool, opts ...float64) (*FloatRule, error) {
// Return error if key is empty
if key == "" {
return nil, EmptyKeyError
}

options := make([]*float64, 1)
for i, o := range opts {
options[i] = &o
}

return &FloatRule{
f := &FloatRule{
key: key,
required: req,
default_: options[0],
}, nil
}

if len(opts) > 0 {
f.default_ = &opts[0]
}
return f, nil
}

// Key Returns the key
Expand Down
17 changes: 8 additions & 9 deletions control/plugin/cpolicy/integer.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,22 @@ type IntRule struct {
maximum *int
}

// Returns a new int-typed rule. Arguments are key(string), required(bool), default(int), min(int), max(int)
// NewIntegerRule returns a new int-typed rule. Arguments are key(string), required(bool), default(int)
func NewIntegerRule(key string, req bool, opts ...int) (*IntRule, error) {
// Return error if key is empty
if key == "" {
return nil, EmptyKeyError
}

options := make([]*int, 1)
for i, o := range opts {
options[i] = &o
}

return &IntRule{
i := &IntRule{
key: key,
required: req,
default_: options[0],
}, nil
}

if len(opts) > 0 {
i.default_ = &opts[0]
}
return i, nil
}

func (i *IntRule) Type() string {
Expand Down

0 comments on commit 189f94c

Please sign in to comment.