diff --git a/protobuf.c b/protobuf.c index 50b1e68..44f9ed7 100644 --- a/protobuf.c +++ b/protobuf.c @@ -10,8 +10,9 @@ static uint32_t read_num(FILE* fp) { uint8_t i = 0; do { c = fgetc(fp); - n |= (c & 0x7f) << (7 * i++); - } while(c & 0x80); + if(feof(fp)) return n; + else n |= (c & 0x7f) << (7 * i++); + } while((c & 0x80)); return n; } @@ -46,6 +47,7 @@ SIMPLE_PB* get_pb(FILE* fp) { while(p < end) { uint32_t offset = read_num(fp); uint32_t data_len = read_num(fp); + printf("offset: %u, datlen: %u\n", offset, data_len); if(data_len > 0) fread(p, data_len, 1, fp); p += offset; }