Skip to content

Commit

Permalink
fix byte len calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
anatoly-kussul committed Jan 6, 2025
1 parent 3786020 commit 74867f4
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 3 deletions.
2 changes: 1 addition & 1 deletion encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func (e encoder) defaultEncode(num uint128) string { // compiler optimizes a lot
func (e encoder) encode(num uint128) string {
var r, ind uint64
i := int(e.alphabet.encLen - 1)
buf := make([]byte, int64(e.alphabet.encLen*e.alphabet.maxBytes))
buf := make([]byte, int64(e.alphabet.encLen)*int64(e.alphabet.maxBytes))
lastPlaced := len(buf)
l := uint64(e.alphabet.len)
d, n := maxPow(l)
Expand Down
3 changes: 1 addition & 2 deletions shortuuid.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,7 @@ func hashedUUID(space uuid.UUID, data string) (u uuid.UUID) {
h := sha1.New()
h.Write(space[:]) //nolint:errcheck
h.Write(unsafe.Slice(unsafe.StringData(data), len(data))) //nolint:errcheck
buf := make([]byte, 0, sha1.Size)
s := h.Sum(buf)
s := h.Sum(make([]byte, 0, sha1.Size))
copy(u[:], s)
u[6] = (u[6] & 0x0f) | uint8((5&0xf)<<4)
u[8] = (u[8] & 0x3f) | 0x80 // RFC 4122 variant
Expand Down

0 comments on commit 74867f4

Please sign in to comment.