summaryrefslogtreecommitdiff
path: root/upb
diff options
context:
space:
mode:
authorJosh Haberman <jhaberman@gmail.com>2019-01-24 15:53:36 -0800
committerJosh Haberman <jhaberman@gmail.com>2019-01-24 15:53:36 -0800
commit2719bcff0d1972994e98433b830a921e2ded5fc4 (patch)
treec99588297758815d798cd2e7db5dc5d98796ed12 /upb
parentca5f951137a121e55ca21ee162afd1be596775ba (diff)
Fixes for Google-internal tests.
Diffstat (limited to 'upb')
-rw-r--r--upb/def.c22
-rw-r--r--upb/def.h6
2 files changed, 27 insertions, 1 deletions
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_; }
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback