summaryrefslogtreecommitdiff
path: root/upb
diff options
context:
space:
mode:
authorJosh Haberman <jhaberman@gmail.com>2015-10-21 14:46:42 -0700
committerJosh Haberman <jhaberman@gmail.com>2015-10-21 14:46:42 -0700
commitc1bc256d4e57863d8e4d1f30b8e5ca2bb0e61896 (patch)
tree098a899c808717b2bc1260b2793f4027ec29cda7 /upb
parentba4b6f5c848dd330e60d7ce8f3c2f869638092c7 (diff)
Addressed PR comments.
Diffstat (limited to 'upb')
-rw-r--r--upb/descriptor/reader.c20
1 files changed, 16 insertions, 4 deletions
diff --git a/upb/descriptor/reader.c b/upb/descriptor/reader.c
index 1d6ed94..75d2b50 100644
--- a/upb/descriptor/reader.c
+++ b/upb/descriptor/reader.c
@@ -15,6 +15,11 @@
#include "upb/sink.h"
#include "upb/descriptor/descriptor.upb.h"
+/* Compares a NULL-terminated string with a non-NULL-terminated string. */
+static bool upb_streq(const char *str, const char *buf, size_t n) {
+ return strlen(str) == n && memcmp(str, buf, n) == 0;
+}
+
/* upb_deflist is an internal-only dynamic array for storing a growing list of
* upb_defs. */
typedef struct {
@@ -210,14 +215,16 @@ static size_t file_onpackage(void *closure, const void *hd, const char *buf,
}
static size_t file_onsyntax(void *closure, const void *hd, const char *buf,
- size_t n, const upb_bufhandle *handle) {
+ size_t n, const upb_bufhandle *handle) {
upb_descreader *r = closure;
UPB_UNUSED(hd);
UPB_UNUSED(handle);
/* XXX: see comment at the top of the file. */
- if (n == strlen("proto3") && memcmp(buf, "proto3", strlen("proto3")) == 0) {
+ if (upb_streq("proto2", buf, n)) {
+ /* Technically we could verify that proto3 hadn't previously been seen. */
+ } else if (upb_streq("proto3", buf, n)) {
uint32_t i;
- /* Cover messages created previously. */
+ /* Update messages created before the syntax was read. */
for (i = r->file_start; i < r->defs.len; i++) {
upb_msgdef *m = upb_dyncast_msgdef_mutable(r->defs.defs[i]);
if (m) {
@@ -225,9 +232,14 @@ static size_t file_onsyntax(void *closure, const void *hd, const char *buf,
}
}
- /* Cover messages created subsequently. */
+ /* Set a flag for any future messages that will be created. */
r->primitives_have_presence = false;
+ } else {
+ /* Error: neither proto3 nor proto3.
+ * TODO(haberman): there should be a status object we can report this to. */
+ return 0;
}
+
return n;
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback