diff options
author | Leo Howell <leo@lwh.jp> | 2009-09-29 18:59:02 +0900 |
---|---|---|
committer | Leo Howell <leo@lwh.jp> | 2009-09-29 18:59:02 +0900 |
commit | 81eee33d754108de281fd279e0859de80a0e2586 (patch) | |
tree | 350172d3153def1dda2cf15ca448ce9a7d69e097 | |
parent | 7b61f48876af1c0a91c32355862e8bcb2e6d126c (diff) | |
download | pdf-simple-sign-81eee33d754108de281fd279e0859de80a0e2586.tar.gz pdf-simple-sign-81eee33d754108de281fd279e0859de80a0e2586.tar.xz pdf-simple-sign-81eee33d754108de281fd279e0859de80a0e2586.zip |
Fix bit/byte bug in bitstream
-rw-r--r-- | lpg/libqr/qr-bitstream.c | 7 |
1 files changed, 3 insertions, 4 deletions
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); |