]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Library/BrotliCustomDecompressLib/dec/bit_reader.c
MdeModulePkg BrotliLib: Fix the regression logic issue in loop
[mirror_edk2.git] / MdeModulePkg / Library / BrotliCustomDecompressLib / dec / bit_reader.c
CommitLineData
36ff6d80
SB
1/* Copyright 2013 Google Inc. All Rights Reserved.\r
2\r
3 Distributed under MIT license.\r
4 See file LICENSE for detail or copy at https://opensource.org/licenses/MIT\r
5*/\r
6\r
7/* Bit reading helpers */\r
8\r
9#include "./bit_reader.h"\r
10\r
11#include "../common/types.h"\r
12#include "./port.h"\r
13\r
14#if defined(__cplusplus) || defined(c_plusplus)\r
15extern "C" {\r
16#endif\r
17\r
18void BrotliInitBitReader(BrotliBitReader* const br) {\r
19 br->val_ = 0;\r
20 br->bit_pos_ = sizeof(br->val_) << 3;\r
21}\r
22\r
23BROTLI_BOOL BrotliWarmupBitReader(BrotliBitReader* const br) {\r
24 size_t aligned_read_mask = (sizeof(br->val_) >> 1) - 1;\r
25 /* Fixing alignment after unaligned BrotliFillWindow would result accumulator\r
26 overflow. If unalignment is caused by BrotliSafeReadBits, then there is\r
27 enough space in accumulator to fix aligment. */\r
28 if (!BROTLI_ALIGNED_READ) {\r
29 aligned_read_mask = 0;\r
30 }\r
31 if (BrotliGetAvailableBits(br) == 0) {\r
32 if (!BrotliPullByte(br)) {\r
33 return BROTLI_FALSE;\r
34 }\r
35 }\r
36\r
841b2590 37 while ((((size_t)(*br->next_in)) & aligned_read_mask) != 0) {\r
36ff6d80
SB
38 if (!BrotliPullByte(br)) {\r
39 /* If we consumed all the input, we don't care about the alignment. */\r
40 return BROTLI_TRUE;\r
41 }\r
42 }\r
43 return BROTLI_TRUE;\r
44}\r
45\r
46#if defined(__cplusplus) || defined(c_plusplus)\r
47} /* extern "C" */\r
48#endif\r