summaryrefslogtreecommitdiff
path: root/upb
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2015-06-22 15:37:59 -0700
committerJoshua Haberman <jhaberman@gmail.com>2015-06-22 15:37:59 -0700
commitff8b042ad310f105249eeab761427669d6fe9766 (patch)
treedaeed7a7201ca0440a0b34f66ee0525369ccf113 /upb
parentd264438d15a8f5a6b539ce38f8ea125ab5f1dd98 (diff)
parentc3e9a57a6fff08640f3ad05e8df971d5ddb37d51 (diff)
Merge pull request #30 from haberman/encoderfix
Fixed some bad bugs in upb_env.
Diffstat (limited to 'upb')
-rw-r--r--upb/bindings/stdc++/string.h6
-rw-r--r--upb/descriptor/descriptor.pbbin0 -> 4137 bytes
-rw-r--r--upb/env.c10
-rw-r--r--upb/pb/encoder.h2
4 files changed, 14 insertions, 4 deletions
diff --git a/upb/bindings/stdc++/string.h b/upb/bindings/stdc++/string.h
index 5137486..20a0876 100644
--- a/upb/bindings/stdc++/string.h
+++ b/upb/bindings/stdc++/string.h
@@ -23,6 +23,9 @@ class FillStringHandler {
// TODO(haberman): add UpbBind/UpbMakeHandler support to BytesHandler so these
// can be prettier callbacks.
static void* StartString(void *c, const void *hd, size_t size) {
+ UPB_UNUSED(hd);
+ UPB_UNUSED(size);
+
T* str = static_cast<T*>(c);
str->clear();
return c;
@@ -30,6 +33,9 @@ class FillStringHandler {
static size_t StringBuf(void* c, const void* hd, const char* buf, size_t n,
const BufferHandle* h) {
+ UPB_UNUSED(hd);
+ UPB_UNUSED(h);
+
T* str = static_cast<T*>(c);
try {
str->append(buf, n);
diff --git a/upb/descriptor/descriptor.pb b/upb/descriptor/descriptor.pb
new file mode 100644
index 0000000..bcf3473
--- /dev/null
+++ b/upb/descriptor/descriptor.pb
Binary files differ
diff --git a/upb/env.c b/upb/env.c
index cc7a951..c42560a 100644
--- a/upb/env.c
+++ b/upb/env.c
@@ -68,6 +68,7 @@ static void *default_alloc(void *_ud, void *ptr, size_t oldsize, size_t size) {
* updated to its new location. */
if (block->next) block->next->prev = block;
if (block->prev) block->prev->next = block;
+ if (ud->head == from) ud->head = block;
}
} else {
/* Insert at head of linked list. */
@@ -96,7 +97,7 @@ static void default_alloc_cleanup(void *_ud) {
static bool default_err(void *ud, const upb_status *status) {
UPB_UNUSED(ud);
- fprintf(stderr, "upb error: %s\n", upb_status_errmsg(status));
+ UPB_UNUSED(status);
return false;
}
@@ -217,7 +218,6 @@ static size_t align_up(size_t size) {
UPB_FORCEINLINE static void *seeded_alloc(void *ud, void *ptr, size_t oldsize,
size_t size) {
upb_seededalloc *a = ud;
- UPB_UNUSED(ptr);
size = align_up(size);
@@ -235,7 +235,11 @@ UPB_FORCEINLINE static void *seeded_alloc(void *ud, void *ptr, size_t oldsize,
/* Is `ptr` part of the user-provided initial block? Don't pass it to the
* default allocator if so; otherwise, it may try to realloc() the block. */
if (chptr >= a->mem_base && chptr < a->mem_limit) {
- return a->alloc(a->alloc_ud, NULL, 0, size);
+ void *ret;
+ assert(chptr + oldsize <= a->mem_limit);
+ ret = a->alloc(a->alloc_ud, NULL, 0, size);
+ if (ret) memcpy(ret, ptr, oldsize);
+ return ret;
} else {
return a->alloc(a->alloc_ud, ptr, oldsize, size);
}
diff --git a/upb/pb/encoder.h b/upb/pb/encoder.h
index 167d33f..cb5c79f 100644
--- a/upb/pb/encoder.h
+++ b/upb/pb/encoder.h
@@ -56,7 +56,7 @@ class upb::pb::Encoder {
static const size_t kSize = UPB_PB_ENCODER_SIZE;
private:
- UPB_DISALLOW_POD_OPS(Encoder, upb::pb::Encoder);
+ UPB_DISALLOW_POD_OPS(Encoder, upb::pb::Encoder)
};
#endif
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback