Merge pull request #103 from TeBoring/php-change

Fix problems of upb_encode_growbuffer
pull/13171/head
Paul Yang 7 years ago committed by GitHub
commit 298c252695
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      upb/encode.c

@ -66,7 +66,7 @@ static bool upb_encode_growbuffer(upb_encstate *e, size_t bytes) {
CHK(new_buf); CHK(new_buf);
/* We want previous data at the end, realloc() put it at the beginning. */ /* We want previous data at the end, realloc() put it at the beginning. */
memmove(e->limit - old_size, e->buf, old_size); memmove(new_buf + new_size - old_size, e->buf, old_size);
e->ptr = new_buf + new_size - (e->limit - e->ptr); e->ptr = new_buf + new_size - (e->limit - e->ptr);
e->limit = new_buf + new_size; e->limit = new_buf + new_size;
@ -347,7 +347,7 @@ bool upb_encode_message(upb_encstate* e, const char *msg,
const upb_msglayout_msginit_v1 *m, const upb_msglayout_msginit_v1 *m,
size_t *size) { size_t *size) {
int i; int i;
char *buf_end = e->ptr; size_t pre_len = e->limit - e->ptr;
if (msg == NULL) { if (msg == NULL) {
return true; return true;
@ -371,7 +371,7 @@ bool upb_encode_message(upb_encstate* e, const char *msg,
} }
} }
*size = buf_end - e->ptr; *size = (e->limit - e->ptr) - pre_len;
return true; return true;
} }

Loading…
Cancel
Save