From 0a8b266c7169dba1da9a4f316c4c54db2c1481c9 Mon Sep 17 00:00:00 2001 From: Rickard Andersson Date: Mon, 2 Oct 2023 11:50:16 +0300 Subject: [PATCH] fix(json): return `.Out_Of_Memory` when out of memory on parse Previously this would silently simply not do anything and the object would be empty/incomplete when parsed instead. --- core/encoding/json/parser.odin | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/encoding/json/parser.odin b/core/encoding/json/parser.odin index bc381efee..a57f6bebd 100644 --- a/core/encoding/json/parser.odin +++ b/core/encoding/json/parser.odin @@ -263,6 +263,12 @@ parse_object_body :: proc(p: ^Parser, end_token: Token_Kind) -> (obj: Object, er return } + if len(obj) == cap(obj) { + reserve_error := reserve(&obj, max(1, cap(obj) * 2)) + if reserve_error != nil { + return nil, .Out_Of_Memory + } + } obj[key] = elem if parse_comma(p) {