diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2023-10-15 11:23:34 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-15 11:23:34 +0100 |
| commit | c9c7aa2e90267c9397d640c92cf3c44358badcbd (patch) | |
| tree | 088465d5b9d9010f354da3017243cd456ea8a98a /core/encoding | |
| parent | 2783461e6954b8d2f10e8a9019eef009bd2f1169 (diff) | |
| parent | 931e0d4687da09bfa17f02b80dfef20ad95d4d6e (diff) | |
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
Diffstat (limited to 'core/encoding')
| -rw-r--r-- | core/encoding/json/parser.odin | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/core/encoding/json/parser.odin b/core/encoding/json/parser.odin index bc381efee..6faaf3f32 100644 --- a/core/encoding/json/parser.odin +++ b/core/encoding/json/parser.odin @@ -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 } |