diff options
author | Chris Fallin <cfallin@c1f.net> | 2015-02-02 13:38:05 -0800 |
---|---|---|
committer | Chris Fallin <cfallin@c1f.net> | 2015-02-02 13:38:05 -0800 |
commit | fb585045692c482b6946fff63f0cd8425c8c70b5 (patch) | |
tree | 5ea54a02a338f2123503f840280a6e037cd65954 /upb/table.c | |
parent | 51513c6e7f9df3f04fde0ff94bfe654f8dccaaa0 (diff) |
Support maps in JSON parsing and serialization.
This is a sync of our internal developing of JSON parsing and
serialization. It implements native understanding of MapEntry
submessages, so that map fields with (key, value) pairs are serialized
as JSON maps (objects) natively rather than as arrays of objects with
'key' and 'value' fields. The parser also now understands how to emit
handler calls corresponding to MapEntry objects when processing a map
field.
This sync also picks up a bugfix in `table.c` to handle an alloc-failed
case.
Diffstat (limited to 'upb/table.c')
-rw-r--r-- | upb/table.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/upb/table.c b/upb/table.c index aa99fe2..fc69125 100644 --- a/upb/table.c +++ b/upb/table.c @@ -40,12 +40,16 @@ char *upb_strdup(const char *s) { } char *upb_strdup2(const char *s, size_t len) { + // Prevent overflow errors. + if (len == SIZE_MAX) return NULL; // Always null-terminate, even if binary data; but don't rely on the input to // have a null-terminating byte since it may be a raw binary buffer. size_t n = len + 1; char *p = malloc(n); - if (p) memcpy(p, s, len); - p[len] = 0; + if (p) { + memcpy(p, s, len); + p[len] = 0; + } return p; } |