]> git.sesse.net Git - fjl/blobdiff - input_test.c
read_huffman_tables() takes in unstuffed data, not raw data.
[fjl] / input_test.c
index 108b3b63a85ce2c47db7f7019d572e1dc22ed3a4..57fae748621cfc5d2d4e0c87f1fe529773a91201 100644 (file)
@@ -24,7 +24,7 @@ ssize_t custom_read(void* userdata, uint8_t* buf, size_t count)
 ssize_t custom_read_slow(void* userdata, uint8_t* buf, size_t count)
 {
        struct custom_read_userdata* ud = (struct custom_read_userdata*)userdata;
-       size_t num_to_read = (count > 0 ? 1 : 0);
+       size_t num_to_read = ((count > 0 && ud->bytes_left > 0) ? 1 : 0);
        memcpy(buf, ud->bytes, num_to_read);
        ud->bytes += num_to_read;
        ud->bytes_left -= num_to_read;
@@ -42,7 +42,7 @@ void test_basic_reading()
        struct bit_source source;
        init_bit_source(&source, custom_read, &ud);
 
-       for (int i = 0; i < sizeof(bytes) * 8 / 6; ++i) {
+       for (unsigned i = 0; i < sizeof(bytes) * 8 / 6; ++i) {
                possibly_refill(&source, 6);
                unsigned ret = read_bits(&source, 6);
                assert(ret == 0x2a);
@@ -62,7 +62,7 @@ void test_slow_source()
        struct bit_source source;
        init_bit_source(&source, custom_read_slow, &ud);
 
-       for (int i = 0; i < sizeof(bytes) * 8 / 6; ++i) {
+       for (unsigned i = 0; i < sizeof(bytes) * 8 / 6; ++i) {
                possibly_refill(&source, 6);
                unsigned ret = read_bits(&source, 6);
                assert(ret == 0x2a);