Skip to content

Commit

Permalink
cleanup: include size of go types in var size calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
zshipko committed Mar 6, 2024
1 parent 7e497b3 commit b7f2321
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion host.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"io"
"net/http"
"net/url"
"unsafe"

// TODO: is there a better package for this?
"github.com/gobwas/glob"
Expand Down Expand Up @@ -433,10 +434,11 @@ func varSet(ctx context.Context, m api.Module, nameOffset uint64, valueOffset ui
}

// Calculate size including current key/value
size := len(name) + len(value)
size := int(unsafe.Sizeof([]byte{})+unsafe.Sizeof("")) + len(name) + len(value)
for k, v := range plugin.Var {
size += len(k)
size += len(v)
size += int(unsafe.Sizeof([]byte{}) + unsafe.Sizeof(""))
}

if size >= int(plugin.MaxVarBytes) && valueOffset != 0 {
Expand Down

0 comments on commit b7f2321

Please sign in to comment.