MdeModulePkg BrotliLib: Fix the regression logic issue in loop
authorLiming Gao <liming.gao@intel.com>
Thu, 13 Apr 2017 16:13:06 +0000 (00:13 +0800)
committerLiming Gao <liming.gao@intel.com>
Fri, 14 Apr 2017 02:28:59 +0000 (10:28 +0800)
In V2, change logic to avoid use mtf[-1] style to get value.

Roll back to previous logic, and use point + offset to get byte value.

Cc: Bell Song <binx.song@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Liming Gao <liming.gao@intel.com>
Reviewed-by: Bell Song <binx.song@intel.com>
MdeModulePkg/Library/BrotliCustomDecompressLib/dec/decode.c

index 67f0ff2cd96fbdb86fcb6ed3dc78b32775c10ae9..6557ba67d56b6fb043a3bc30e3391b72e3a2ec64 100644 (file)
@@ -855,6 +855,7 @@ static BROTLI_NOINLINE void InverseMoveToFrontTransform(
   uint32_t i = 4;\r
   uint32_t upper_bound = state->mtf_upper_bound;\r
   uint8_t* mtf = &state->mtf[4];  /* Make mtf[-1] addressable. */\r
+  uint8_t* mtft = &state->mtf[3];\r
   /* Load endian-aware constant. */\r
   const uint8_t b0123[4] = {0, 1, 2, 3};\r
   uint32_t pattern;\r
@@ -875,10 +876,10 @@ static BROTLI_NOINLINE void InverseMoveToFrontTransform(
     uint8_t value = mtf[index];\r
     upper_bound |= (uint32_t)v[i];\r
     v[i] = value;\r
-    mtf[-1] = value;\r
-    while (index > 0) {\r
+    mtft[0] = value;\r
+    while (index >= 0) {\r
+      mtft[index + 1] = mtft[index];\r
       index--;\r
-      mtf[index + 1] = mtf[index];\r
     }\r
   }\r
   /* Remember amount of elements to be reinitialized. */\r