Added assertions for getjsonname() return.

pull/13171/head
Josh Haberman 9 years ago
parent 458da2563f
commit 4150640650
  1. 4
      upb/json/parser.rl
  2. 4
      upb/json/printer.c

@ -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));

@ -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);

Loading…
Cancel
Save