Fix bug in bitreader handling of read callback returning a short count (SF#2490454...
[platform/upstream/flac.git] / src / libFLAC / ia32 / bitreader_asm.nasm
index 4c65133..ba2fc3c 100644 (file)
@@ -272,10 +272,11 @@ cident FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap
        ;; edi          uval
        ;; ebp          br
        mov     edx, [ebp + 12]         ;     edx <- br->bytes
-       test    edx, edx
-       jz      .read1                  ;     if(br->bytes) {  [NOTE: this case is rare so it doesn't have to be all that fast ]
+       shl     edx, 3                  ;     edx <- br->bytes*8
+       cmp     edx, ecx
+       jbe     .read1                  ;     if(br->bytes*8 > cbits) {  [NOTE: this case is rare so it doesn't have to be all that fast ]
        mov     ebx, [ebp]
-       shl     edx, 3                  ;       edx <- const unsigned end = br->bytes * 8;
+                                       ;       edx <- const unsigned end = br->bytes * 8;
        mov     eax, [ebx + 4*esi]      ;       b = br->buffer[cwords]
        xchg    edx, ecx                ;       [edx <- cbits , ecx <- end]
        mov     ebx, 0xffffffff         ;       ebx <- FLAC__WORD_ALL_ONES
@@ -296,7 +297,7 @@ cident FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap
 .c1_next3:                             ;       } else {
        sub     edi, ecx
        add     edi, edx                ;         uval += end - cbits;
-       add     ecx, edx                ;         cbits += end
+       mov     ecx, edx                ;         cbits = end
                                        ;         /* didn't find stop bit yet, have to keep going... */
                                        ;       }
                                        ;     }