From 2719bcff0d1972994e98433b830a921e2ded5fc4 Mon Sep 17 00:00:00 2001 From: Josh Haberman Date: Thu, 24 Jan 2019 15:53:36 -0800 Subject: Fixes for Google-internal tests. --- upb/def.c | 22 ++++++++++++++++++++++ upb/def.h | 6 +++++- 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'upb') diff --git a/upb/def.c b/upb/def.c index 38ef9fa..4d4fea9 100644 --- a/upb/def.c +++ b/upb/def.c @@ -958,6 +958,28 @@ static bool create_oneofdef( static bool parse_default(const symtab_addctx *ctx, const char *str, size_t len, upb_fielddef *f) { char *end; + char nullz[64]; + errno = 0; + + switch (upb_fielddef_type(f)) { + case UPB_TYPE_INT32: + case UPB_TYPE_INT64: + case UPB_TYPE_UINT32: + case UPB_TYPE_UINT64: + case UPB_TYPE_DOUBLE: + case UPB_TYPE_FLOAT: + /* Standard C number parsing functions expect null-terminated strings. */ + if (len >= sizeof(nullz) - 1) { + return false; + } + memcpy(nullz, str, len); + nullz[len] = '\0'; + str = nullz; + break; + default: + break; + } + switch (upb_fielddef_type(f)) { case UPB_TYPE_INT32: { long val = strtol(str, &end, 0); diff --git a/upb/def.h b/upb/def.h index 9a722f3..f2b7032 100644 --- a/upb/def.h +++ b/upb/def.h @@ -134,6 +134,7 @@ uint32_t upb_fielddef_selectorbase(const upb_fielddef *f); * an extension. */ class upb::FieldDefPtr { public: + FieldDefPtr() : ptr_(nullptr) {} explicit FieldDefPtr(const upb_fielddef *ptr) : ptr_(ptr) {} const upb_fielddef* ptr() const { return ptr_; } @@ -302,6 +303,7 @@ bool upb_oneof_iter_isequal(const upb_oneof_iter *iter1, /* Class that represents a oneof. */ class upb::OneofDefPtr { public: + OneofDefPtr() : ptr_(nullptr) {} explicit OneofDefPtr(const upb_oneofdef *ptr) : ptr_(ptr) {} const upb_oneofdef* ptr() const { return ptr_; } @@ -482,7 +484,8 @@ bool upb_msg_oneof_iter_isequal(const upb_msg_oneof_iter *iter1, /* Structure that describes a single .proto message type. */ class upb::MessageDefPtr { public: - MessageDefPtr(const upb_msgdef *ptr) : ptr_(ptr) {} + MessageDefPtr() : ptr_(nullptr) {} + explicit MessageDefPtr(const upb_msgdef *ptr) : ptr_(ptr) {} const upb_msgdef *ptr() const { return ptr_; } explicit operator bool() const { return ptr_ != nullptr; } @@ -689,6 +692,7 @@ int32_t upb_enum_iter_number(upb_enum_iter *iter); class upb::EnumDefPtr { public: + EnumDefPtr() : ptr_(nullptr) {} explicit EnumDefPtr(const upb_enumdef* ptr) : ptr_(ptr) {} const upb_enumdef* ptr() const { return ptr_; } -- cgit v1.2.3