Skip to content

Commit

Permalink
Merge pull request #4 from orijtech/unsafe-conversions
Browse files Browse the repository at this point in the history
Decode: use unsafe []byte->string conversion for discarded value
  • Loading branch information
madflojo authored Dec 2, 2021
2 parents 3a0b64d + 7453e32 commit 6499601
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion mli.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ import (
"encoding/hex"
"fmt"
"strconv"
"unsafe"
)

// empty is used as a quick return during errors
Expand Down Expand Up @@ -238,7 +239,7 @@ func Decode(key string, b *[]byte) (int, error) {
}

// Convert to integer from ASCII
n, err := strconv.Atoi(string(*b))
n, err := strconv.Atoi(unsafeByteToStr(*b))
if err != nil {
return 0, fmt.Errorf("unable to convert string values to integer - %s", err)
}
Expand All @@ -249,6 +250,10 @@ func Decode(key string, b *[]byte) (int, error) {
}
}

func unsafeByteToStr(b []byte) string {
return *(*string)(unsafe.Pointer(&b))
}

// Encode will accept a message length type and message length value desired. Encode will return a byte slice which
// contains a MLI formatted for in the desired message length type.
//
Expand Down

0 comments on commit 6499601

Please sign in to comment.