From fcd0a0bfaa14d941f913cc522ecc5a3e7ebd8c76 Mon Sep 17 00:00:00 2001 From: wph612 <43688928+vickit144@users.noreply.github.com> Date: Tue, 24 Mar 2020 19:47:18 -0400 Subject: [PATCH 1/2] Remove if (f->valid_bits < 0) return 0; on line 1603 I propose to remove this line because f->valid_bits will never be less than zero since, in the while loop, you're adding 8 to it. Therefore, it will always evaluate to false. This is to help remove redundant code. --- stb_vorbis.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stb_vorbis.c b/stb_vorbis.c index b28944a..4e67726 100644 --- a/stb_vorbis.c +++ b/stb_vorbis.c @@ -1600,7 +1600,7 @@ static uint32 get_bits(vorb *f, int n) f->valid_bits += 8; } } - if (f->valid_bits < 0) return 0; + z = f->acc & ((1 << n)-1); f->acc >>= n; f->valid_bits -= n; From 2e78eb603b1be816deb4a9701452bfe9905714c2 Mon Sep 17 00:00:00 2001 From: wph612 <43688928+vickit144@users.noreply.github.com> Date: Tue, 24 Mar 2020 20:49:40 -0400 Subject: [PATCH 2/2] Added debugging check on line 1604 I added the code assert(f->valid_bits >= n); instead of removing if (f->valid_bits < 0) return 0; to improve code with checking and debugging instead. --- stb_vorbis.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stb_vorbis.c b/stb_vorbis.c index 4e67726..2662d15 100644 --- a/stb_vorbis.c +++ b/stb_vorbis.c @@ -1601,6 +1601,8 @@ static uint32 get_bits(vorb *f, int n) } } + assert(f->valid_bits >= n); + z = f->acc & ((1 << n)-1); f->acc >>= n; f->valid_bits -= n;