aboutsummaryrefslogtreecommitdiff
path: root/core/encoding/json
diff options
context:
space:
mode:
authorRickard Andersson <gonz@severnatazvezda.com>2023-10-02 15:10:12 +0300
committerRickard Andersson <gonz@severnatazvezda.com>2023-10-02 15:10:12 +0300
commitcfa3765d50347647606be9468da549ce54347018 (patch)
tree0e7f4ad1f07eabfdb664ceccf6fb75b199876998 /core/encoding/json
parent11e884aec511d21798f7ecebec5c658a82ff590d (diff)
fix: guard against empty key value in `parse_object_body`
Diffstat (limited to 'core/encoding/json')
-rw-r--r--core/encoding/json/parser.odin16
1 files changed, 10 insertions, 6 deletions
diff --git a/core/encoding/json/parser.odin b/core/encoding/json/parser.odin
index aa44d19e6..b40b92486 100644
--- a/core/encoding/json/parser.odin
+++ b/core/encoding/json/parser.odin
@@ -264,13 +264,17 @@ parse_object_body :: proc(p: ^Parser, end_token: Token_Kind) -> (obj: Object, er
return
}
- insert_success := runtime.map_insert(&obj, key, elem)
- // NOTE(gonz): we'd rather check specifically for an allocation error here but
- // `map_insert` doesn't differentiate; we can only check for `nil`
- if insert_success == nil {
- return nil, .Out_Of_Memory
+ // NOTE(gonz): There are code paths for which this traversal ends up
+ // inserting empty key/values into the object and for those we do not
+ // want to allocate anything
+ if key != "" {
+ reserve_error := reserve(&obj, len(obj) + 1)
+ if reserve_error == mem.Allocator_Error.Out_Of_Memory {
+ return nil, .Out_Of_Memory
+ }
+ obj[key] = elem
}
-
+
if parse_comma(p) {
break
}