summaryrefslogtreecommitdiff
path: root/binfile.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-01-25 22:10:46 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2020-01-25 22:10:46 -0500
commit99617c04505fc3921cecaf6fa204229a2a1f3544 (patch)
treedb424250f445908071f938b881a008187346e09c /binfile.c
parentc12e005630f77c608b4fdebbb5054c5f46ab4df0 (diff)
mostly fixed packages
Diffstat (limited to 'binfile.c')
-rw-r--r--binfile.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/binfile.c b/binfile.c
index 884665b..9777718 100644
--- a/binfile.c
+++ b/binfile.c
@@ -277,11 +277,14 @@ static void write_vlq(FILE *fp, U64 x) {
}
static U64 read_vlq(FILE *fp) {
- U8 byte = read_u8(fp);
- if (byte & 0x80) {
- return (read_vlq(fp) << 7) + (byte & 0x7F);
- } else {
- return byte;
+ U64 q = 0;
+ U64 bit = 0;
+ while (1) {
+ U8 byte = read_u8(fp);
+ assert(!feof(fp));
+ q |= (U64)(byte & 0x7F) << bit;
+ bit += 7;
+ if (!(byte & 0x80)) return q;
}
}
@@ -291,6 +294,8 @@ static void binfile_test(void) {
FILE *fp = tmpfile();
U64 a = 234873485734;
write_vlq(fp, a);
+ U64 s = 3;
+ write_vlq(fp, s);
I64 b = -123981232131;
write_i64(fp, b);
U8 c = 12;
@@ -313,6 +318,7 @@ static void binfile_test(void) {
}
expect(U64, U64_FMT, read_vlq(fp), a);
+ expect(U64, U64_FMT, read_vlq(fp), s);
expect(I64, I64_FMT, read_i64(fp), b);
expect(U8, U8_FMT, read_u8(fp), c);
expect(F32, F32_FMT, read_f32(fp), d);