mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-11 14:33:41 +00:00
src/runtime: handle nil map write panics
This commit is contained in:
@@ -406,7 +406,9 @@ func hashmapNext(m *hashmap, it *hashmapIterator, key, value unsafe.Pointer) boo
|
|||||||
|
|
||||||
// Hashmap with plain binary data keys (not containing strings etc.).
|
// Hashmap with plain binary data keys (not containing strings etc.).
|
||||||
func hashmapBinarySet(m *hashmap, key, value unsafe.Pointer) {
|
func hashmapBinarySet(m *hashmap, key, value unsafe.Pointer) {
|
||||||
// TODO: detect nil map here and throw a better panic message?
|
if m == nil {
|
||||||
|
nilMapPanic()
|
||||||
|
}
|
||||||
hash := hash32(key, uintptr(m.keySize), m.seed)
|
hash := hash32(key, uintptr(m.keySize), m.seed)
|
||||||
hashmapSet(m, key, value, hash)
|
hashmapSet(m, key, value, hash)
|
||||||
}
|
}
|
||||||
@@ -445,6 +447,9 @@ func hashmapStringPtrHash(sptr unsafe.Pointer, size uintptr, seed uintptr) uint3
|
|||||||
}
|
}
|
||||||
|
|
||||||
func hashmapStringSet(m *hashmap, key string, value unsafe.Pointer) {
|
func hashmapStringSet(m *hashmap, key string, value unsafe.Pointer) {
|
||||||
|
if m == nil {
|
||||||
|
nilMapPanic()
|
||||||
|
}
|
||||||
hash := hashmapStringHash(key, m.seed)
|
hash := hashmapStringHash(key, m.seed)
|
||||||
hashmapSet(m, unsafe.Pointer(&key), value, hash)
|
hashmapSet(m, unsafe.Pointer(&key), value, hash)
|
||||||
}
|
}
|
||||||
@@ -561,6 +566,9 @@ func hashmapInterfaceEqual(x, y unsafe.Pointer, n uintptr) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func hashmapInterfaceSet(m *hashmap, key interface{}, value unsafe.Pointer) {
|
func hashmapInterfaceSet(m *hashmap, key interface{}, value unsafe.Pointer) {
|
||||||
|
if m == nil {
|
||||||
|
nilMapPanic()
|
||||||
|
}
|
||||||
hash := hashmapInterfaceHash(key, m.seed)
|
hash := hashmapInterfaceHash(key, m.seed)
|
||||||
hashmapSet(m, unsafe.Pointer(&key), value, hash)
|
hashmapSet(m, unsafe.Pointer(&key), value, hash)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,6 +32,11 @@ func nilPanic() {
|
|||||||
runtimePanic("nil pointer dereference")
|
runtimePanic("nil pointer dereference")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Panic when trying to add an entry to a nil map
|
||||||
|
func nilMapPanic() {
|
||||||
|
runtimePanic("assignment to entry in nil map")
|
||||||
|
}
|
||||||
|
|
||||||
// Panic when trying to acces an array or slice out of bounds.
|
// Panic when trying to acces an array or slice out of bounds.
|
||||||
func lookupPanic() {
|
func lookupPanic() {
|
||||||
runtimePanic("index out of range")
|
runtimePanic("index out of range")
|
||||||
|
|||||||
Reference in New Issue
Block a user