diff options
author | Josh Haberman <jhaberman@gmail.com> | 2016-02-17 12:37:32 -0800 |
---|---|---|
committer | Josh Haberman <jhaberman@gmail.com> | 2016-02-17 12:37:32 -0800 |
commit | 41506406506332675016916280693a8d94e1b3ac (patch) | |
tree | ea224e80be970cf03a705cd40aadd0f2f83ef2b7 | |
parent | 458da2563fa674bbcfd32ade2254b3915f751491 (diff) |
Added assertions for getjsonname() return.
-rw-r--r-- | upb/json/parser.rl | 4 | ||||
-rw-r--r-- | upb/json/printer.c | 4 |
2 files changed, 6 insertions, 2 deletions
diff --git a/upb/json/parser.rl b/upb/json/parser.rl index 4ccca6c..fbc2d88 100644 --- a/upb/json/parser.rl +++ b/upb/json/parser.rl @@ -1364,9 +1364,11 @@ static void add_jsonname_table(upb_json_parsermethod *m, const upb_msgdef* md) { const upb_fielddef *f = upb_msg_iter_field(&i); size_t field_len = upb_fielddef_getjsonname(f, buf, len); if (field_len > len) { + size_t len2; buf = realloc(buf, field_len); len = field_len; - upb_fielddef_getjsonname(f, buf, len); + len2 = upb_fielddef_getjsonname(f, buf, len); + UPB_ASSERT_VAR(len2, len == len2); } upb_strtable_insert(t, buf, upb_value_constptr(f)); diff --git a/upb/json/printer.c b/upb/json/printer.c index c3d9bb4..0db7b80 100644 --- a/upb/json/printer.c +++ b/upb/json/printer.c @@ -47,9 +47,11 @@ void freestrpc(void *ptr) { strpc *newstrpc(upb_handlers *h, const upb_fielddef *f) { /* TODO(haberman): handle malloc failure. */ strpc *ret = malloc(sizeof(*ret)); + size_t len; ret->len = upb_fielddef_getjsonname(f, NULL, 0); ret->ptr = malloc(ret->len); - upb_fielddef_getjsonname(f, ret->ptr, ret->len); + len = upb_fielddef_getjsonname(f, ret->ptr, ret->len); + UPB_ASSERT_VAR(len, len == ret->len); ret->len--; /* NULL */ upb_handlers_addcleanup(h, ret, freestrpc); |