Transaction: Fix bounds error getting data address in empty seq

In the unusual case where log data is zero-length, `data[0].addr` is invalid
and Nim thoughtfully raises `IndexOutOfBounds`, a `Defect` so it's not even
in `CatchableError`.

This is done in the EVMC host services to handle `LOG*` ops, and it made one
of the EVM tests silently fail with no error message.  The fix is obvious.

Signed-off-by: Jamie Lokier <jamie@shareable.org>
This commit is contained in:
Jamie Lokier 2021-05-24 09:53:53 +01:00
parent a5dc0bd283
commit b734240291
No known key found for this signature in database
GPG Key ID: CBC25C68435C30A2
1 changed files with 4 additions and 2 deletions

View File

@ -212,8 +212,10 @@ proc emitLog(host: TransactionHost, address: HostAddress,
for i in 0 ..< count:
log.topics[i] = topicsArray[i]
log.data = newSeq[byte](data_size.int)
copyMem(log.data[0].addr, data, data_size.int)
if (data_size > 0):
log.data = newSeq[byte](data_size.int)
copyMem(log.data[0].addr, data, data_size.int)
log.address = address
host.logEntries.add(log)