]> git.sesse.net Git - fjl/blobdiff - bitsource.c
Let the bit source alert about EOF as soon as we have started eating into padding...
[fjl] / bitsource.c
index 7a4ea4a0ca3c553e276be095932061313e833441..b1593aa6ec554959b4bba6bbe3aceb75d4e04863 100644 (file)
@@ -45,17 +45,20 @@ void possibly_refill_slow_path(struct bit_source* source, unsigned num_bits)
                        fprintf(stderr, "Input function returned error\n");
                        exit(1);
                }
-               if (bytes_read == 0 && source->padding_bytes_available > 0) {
-                       unsigned padding_to_add = source->padding_bytes_available;
-                       if (padding_to_add > bytes_to_read) {
-                               padding_to_add = bytes_to_read;
+               if (bytes_read == 0) {
+                       source->source_eof = true;
+                       if (source->padding_bytes_available > 0) {
+                               unsigned padding_to_add = source->padding_bytes_available;
+                               if (padding_to_add > bytes_to_read) {
+                                       padding_to_add = bytes_to_read;
+                               }
+                               memset(source->bytes + source->bytes_available, 0, padding_to_add);
+                               source->padding_bytes_available -= padding_to_add;
+                               source->bytes_available += padding_to_add;
+                       } else {
+                               fprintf(stderr, "Premature EOF\n");
+                               exit(1);
                        }
-                       memset(source->bytes + source->bytes_available, 0, padding_to_add);
-                       source->padding_bytes_available -= padding_to_add;
-                       source->bytes_available += padding_to_add;
-               } else if (bytes_read == 0) {
-                       fprintf(stderr, "Premature EOF\n");
-                       exit(1);
                } else {
                        source->bytes_available += bytes_read;
                }