Skip to content

Commit

Permalink
Merge pull request #16 from jerome-laforge/master
Browse files Browse the repository at this point in the history
Set slice's max for option's data.
  • Loading branch information
mdlayher committed Oct 6, 2016
2 parents 74e4e92 + 5c2e460 commit 6231dda
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
9 changes: 9 additions & 0 deletions iaaddr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,14 @@ func TestIAAddrUnmarshalBinary(t *testing.T) {
t.Fatalf("[%02d] test %q, unexpected IAAddr bytes for parseIAAddr:\n- want: %v\n- got: %v",
i, tt.desc, want, got)
}

for _, v := range iaaddr.Options {
for ii := range v {
if want, got := len(v[ii]), cap(v[ii]); want != got {
t.Fatalf("[%02d] test %q, unexpected capacity option data:\n- want: %v\n- got: %v",
i, tt.desc, want, got)
}
}
}
}
}
2 changes: 2 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,8 @@ func parseOptions(b []byte) (Options, error) {

// N bytes: option data
o.Data = buf.Next(length)
// Set slice's max for option's data
o.Data = o.Data[:len(o.Data):len(o.Data)]

// If option data has less bytes than indicated by length,
// return an error
Expand Down
9 changes: 9 additions & 0 deletions options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2266,5 +2266,14 @@ func Test_parseOptions(t *testing.T) {
t.Fatalf("[%02d] test %q, unexpected Options map for parseOptions(%v):\n- want: %v\n- got: %v",
i, tt.desc, tt.buf, want, got)
}

for k, v := range tt.options {
for ii := range v {
if want, got := cap(v[ii]), cap(options[k][ii]); want != got {
t.Fatalf("[%02d] test %q, unexpected capacity option data:\n- want: %v\n- got: %v",
i, tt.desc, want, got)
}
}
}
}
}

0 comments on commit 6231dda

Please sign in to comment.