From 81eee33d754108de281fd279e0859de80a0e2586 Mon Sep 17 00:00:00 2001 From: Leo Howell Date: Tue, 29 Sep 2009 18:59:02 +0900 Subject: Fix bit/byte bug in bitstream --- lpg/libqr/qr-bitstream.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'lpg/libqr') diff --git a/lpg/libqr/qr-bitstream.c b/lpg/libqr/qr-bitstream.c index 3df2549..b223f4c 100644 --- a/lpg/libqr/qr-bitstream.c +++ b/lpg/libqr/qr-bitstream.c @@ -30,14 +30,13 @@ static size_t bits_to_bytes(size_t bits) static int ensure_available(struct qr_bitstream * stream, size_t bits) { size_t need_bits = stream->pos + bits; - size_t need_bytes = need_bits / CHAR_BIT + ((need_bits % CHAR_BIT) ? 0 : 1); size_t newsize; - if (stream->bufsiz >= need_bytes) + if (stream->bufsiz * CHAR_BIT >= need_bits) return 0; - newsize = MAX(stream->bufsiz, 100); - while (newsize < need_bytes) + newsize = MAX(stream->bufsiz, 100) * CHAR_BIT; + while (newsize < need_bits) newsize *= 2; return qr_bitstream_resize(stream, newsize); -- cgit v1.2.3-70-g09d2