aboutsummaryrefslogtreecommitdiffhomepage
path: root/interp
diff options
context:
space:
mode:
authorAyke van Laethem <[email protected]>2022-09-15 16:18:15 +0200
committerRon Evans <[email protected]>2022-09-15 19:07:04 +0200
commit9e4e182615cd80303c564f95020e0c3bd10af64a (patch)
tree74672ad0a55bfb54c998a7500ef0bfc18627dd0f /interp
parent5f96d2b7843ceebeedd91acae0985f3bcb8a7516 (diff)
downloadtinygo-9e4e182615cd80303c564f95020e0c3bd10af64a.tar.gz
tinygo-9e4e182615cd80303c564f95020e0c3bd10af64a.zip
interp: fix reading from external global
This fixes https://github.com/tinygo-org/tinygo/issues/3020.
Diffstat (limited to 'interp')
-rw-r--r--interp/interpreter.go5
1 files changed, 5 insertions, 0 deletions
diff --git a/interp/interpreter.go b/interp/interpreter.go
index 95c99c842..7cee14bf4 100644
--- a/interp/interpreter.go
+++ b/interp/interpreter.go
@@ -369,6 +369,11 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent
nBytes := uint32(operands[3].Uint())
dstObj := mem.getWritable(dst.index())
dstBuf := dstObj.buffer.asRawValue(r)
+ if mem.get(src.index()).buffer == nil {
+ // Looks like the source buffer is not defined.
+ // This can happen with //extern or //go:embed.
+ return nil, mem, r.errorAt(inst, errUnsupportedRuntimeInst)
+ }
srcBuf := mem.get(src.index()).buffer.asRawValue(r)
copy(dstBuf.buf[dst.offset():dst.offset()+nBytes], srcBuf.buf[src.offset():])
dstObj.buffer = dstBuf