Skip to content

Commit

Permalink
Changed order of actions in ObjectIDFromHex func (mongodb#637)
Browse files Browse the repository at this point in the history
  • Loading branch information
Don2Quixote authored and Mohammad Fahim Abrar committed Mar 17, 2022
1 parent fc179ac commit 9e82d55
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions bson/primitive/objectid.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,15 @@ func (id ObjectID) IsZero() bool {
// ObjectIDFromHex creates a new ObjectID from a hex string. It returns an error if the hex string is not a
// valid ObjectID.
func ObjectIDFromHex(s string) (ObjectID, error) {
if len(s) != 24 {
return NilObjectID, ErrInvalidHex
}

b, err := hex.DecodeString(s)
if err != nil {
return NilObjectID, err
}

if len(b) != 12 {
return NilObjectID, ErrInvalidHex
}

var oid [12]byte
copy(oid[:], b[:])

Expand Down

0 comments on commit 9e82d55

Please sign in to comment.