Skip to content

Commit 5b0466a

Browse files
committed
fix(machine): ensure the pointer is valid even when cLen is zero
1 parent 9ba0eea commit 5b0466a

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

pkg/emulator/machine.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,13 @@ func (m *Machine) ReceiveCmioRequest() (uint8, uint16, []byte, error) {
333333
if err != nil {
334334
return
335335
}
336+
337+
// guard against empty `data`
338+
if cLen == 0 {
339+
cLen = 1
340+
}
336341
data = make([]byte, cLen)
342+
337343
err = newError(C.cm_receive_cmio_request(
338344
m.ptr,
339345
&cCmd,
@@ -346,7 +352,7 @@ func (m *Machine) ReceiveCmioRequest() (uint8, uint16, []byte, error) {
346352
if err != nil {
347353
return 0, 0, nil, err
348354
}
349-
return uint8(cCmd), uint16(cReason), data, nil
355+
return uint8(cCmd), uint16(cReason), data[:cLen], nil
350356
}
351357

352358
// run

0 commit comments

Comments
 (0)