Correct MSIZE args

This commit is contained in:
lash 2023-04-03 09:52:58 +01:00
parent 1c11e5881a
commit 83fe049b15
Signed by untrusted user who does not match committer: lash
GPG Key ID: 21D2E7BB88C2A746
4 changed files with 12 additions and 10 deletions

View File

@ -84,12 +84,12 @@ func ToString(b []byte) (string, error) {
return "", err
}
case MSIZE:
r, bb, err := ParseMSize(b)
r, v, bb, err := ParseMSize(b)
b = bb
if err != nil {
return "", err
}
s = fmt.Sprintf("%s %v", s, r)
s = fmt.Sprintf("%s %v %v", s, r, v)
case MOUT:
r, v, bb, err := ParseMOut(b)
b = bb

View File

@ -121,12 +121,12 @@ func TestToString(t *testing.T) {
t.Fatalf("expected:\n\t%v\ngot:\n\t%v", expect, r)
}
b = NewLine(nil, MSIZE, nil, nil, []uint8{0x42})
b = NewLine(nil, MSIZE, nil, nil, []uint8{0x42, 0x2a})
r, err = ToString(b)
if err != nil {
t.Fatal(err)
}
expect = "MSIZE 66\n"
expect = "MSIZE 66 42\n"
if r != expect {
t.Fatalf("expected:\n\t%v\ngot:\n\t%v", expect, r)
}

View File

@ -199,7 +199,8 @@ func RunHalt(b []byte, st *state.State, rs resource.Resource, ctx context.Contex
// RunMSize
func RunMSize(b []byte, st *state.State, rs resource.Resource, ctx context.Context) ([]byte, error) {
log.Printf("WARNING MSIZE not yet implemented")
return b, nil
_, _, b, err := ParseMSize(b)
return b, err
}
// RunMSize

View File

@ -55,13 +55,14 @@ func ParseMNext(b []byte) (string, string, []byte, error) {
return parseTwoSym(b)
}
func ParseMSize(b []byte) (uint32, []byte, error) {
if len(b) < 1 {
return 0, b, fmt.Errorf("zero-length argument")
func ParseMSize(b []byte) (uint32, uint32, []byte, error) {
if len(b) < 2 {
return 0, 0, b, fmt.Errorf("argument too short")
}
r := uint32(b[0])
b = b[1:]
return r, b, nil
rr := uint32(b[1])
b = b[2:]
return r, rr, b, nil
}
func ParseMOut(b []byte) (string, string, []byte, error) {