From b697882fb272c2f3408f5c821a88aaf3e3db6f52 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 18 Jul 2017 01:04:48 +0200 Subject: [PATCH] Fixed varint length when buffer is reallocated. --- tests/conformance_upb_failures.txt | 6 ------ upb/encode.c | 4 ++-- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/tests/conformance_upb_failures.txt b/tests/conformance_upb_failures.txt index 7ff834aece..33c013d927 100644 --- a/tests/conformance_upb_failures.txt +++ b/tests/conformance_upb_failures.txt @@ -12,10 +12,4 @@ Required.ProtobufInput.RepeatedScalarSelectsLast.FIXED32.ProtobufOutput Required.ProtobufInput.RepeatedScalarSelectsLast.FIXED64.ProtobufOutput Required.ProtobufInput.RepeatedScalarSelectsLast.UINT64.ProtobufOutput Required.ProtobufInput.ValidDataRepeated.BOOL.ProtobufOutput -Required.ProtobufInput.ValidDataRepeated.INT32.ProtobufOutput -Required.ProtobufInput.ValidDataRepeated.INT64.ProtobufOutput -Required.ProtobufInput.ValidDataRepeated.SINT32.ProtobufOutput -Required.ProtobufInput.ValidDataRepeated.SINT64.ProtobufOutput -Required.ProtobufInput.ValidDataRepeated.UINT32.ProtobufOutput -Required.ProtobufInput.ValidDataRepeated.UINT64.ProtobufOutput Required.ProtobufInput.ValidDataScalar.BOOL.ProtobufOutput diff --git a/upb/encode.c b/upb/encode.c index ced971ef81..8a220ef6e2 100644 --- a/upb/encode.c +++ b/upb/encode.c @@ -167,12 +167,12 @@ static bool upb_encode_array(upb_encstate *e, const char *field_mem, #define VARINT_CASE(ctype, encode) { \ ctype *start = arr->data; \ ctype *ptr = start + arr->len; \ - char *buf_ptr = e->ptr; \ + size_t pre_len = e->limit - e->ptr; \ do { \ ptr--; \ CHK(upb_put_varint(e, encode)); \ } while (ptr != start); \ - CHK(upb_put_varint(e, buf_ptr - e->ptr)); \ + CHK(upb_put_varint(e, e->limit - e->ptr - pre_len)); \ } \ break; \ do { ; } while(0)