Merge pull request #2838 from GoNZooo/gonz.return-out-of-memory-in-json-parse

fix(json): return `.Out_Of_Memory` when out of memory on parse
This commit is contained in:
gingerBill
2023-10-15 11:23:34 +01:00
committed by GitHub
2 changed files with 55 additions and 2 deletions
+11 -2
View File
@@ -263,8 +263,17 @@ parse_object_body :: proc(p: ^Parser, end_token: Token_Kind) -> (obj: Object, er
return
}
obj[key] = elem
// 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
}