aboutsummaryrefslogtreecommitdiffstats
path: root/prog/encoding.go
diff options
context:
space:
mode:
Diffstat (limited to 'prog/encoding.go')
-rw-r--r--prog/encoding.go20
1 files changed, 17 insertions, 3 deletions
diff --git a/prog/encoding.go b/prog/encoding.go
index 943dfe350..f288dbc93 100644
--- a/prog/encoding.go
+++ b/prog/encoding.go
@@ -506,10 +506,11 @@ func (p *parser) parseArgAddr(typ Type) (Arg, error) {
return arg, nil
}
-func (p *parser) parseArgString(typ Type) (Arg, error) {
- if _, ok := typ.(*BufferType); !ok {
+func (p *parser) parseArgString(t Type) (Arg, error) {
+ typ, ok := t.(*BufferType)
+ if !ok {
p.eatExcessive(true, "wrong string arg")
- return typ.DefaultArg(), nil
+ return t.DefaultArg(), nil
}
data, err := p.deserializeData()
if err != nil {
@@ -541,6 +542,19 @@ func (p *parser) parseArgString(typ Type) (Arg, error) {
data = append(data, make([]byte, diff)...)
}
data = data[:size]
+ if typ.Kind == BufferString && len(typ.Values) != 0 {
+ matched := false
+ for _, val := range typ.Values {
+ if string(data) == val {
+ matched = true
+ break
+ }
+ }
+ if !matched {
+ p.strictFailf("bad string value %q, expect %q", data, typ.Values)
+ data = []byte(typ.Values[0])
+ }
+ }
return MakeDataArg(typ, data), nil
}