mirror of
https://github.com/fumiama/simple-protobuf.git
synced 2026-06-05 00:10:24 +08:00
修复读到文件末尾时read_num出错
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user