Simplify comparisons between bool and 0/1 in JBig2_Context.cpp.

Then flip some if (!cond) / else blocks.

Change-Id: Ibf6af3e327ac79c58eff8ab07a9e69af8bee4f86
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/89851
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
diff --git a/core/fxcodec/jbig2/JBig2_Context.cpp b/core/fxcodec/jbig2/JBig2_Context.cpp
index 692eb4a..4a2fab6 100644
--- a/core/fxcodec/jbig2/JBig2_Context.cpp
+++ b/core/fxcodec/jbig2/JBig2_Context.cpp
@@ -386,14 +386,14 @@
   pSymbolDictDecoder->SDREFAGG = (wFlags >> 1) & 0x0001;
   pSymbolDictDecoder->SDTEMPLATE = (wFlags >> 10) & 0x0003;
   pSymbolDictDecoder->SDRTEMPLATE = !!((wFlags >> 12) & 0x0003);
-  if (pSymbolDictDecoder->SDHUFF == 0) {
+  if (!pSymbolDictDecoder->SDHUFF) {
     const uint32_t dwTemp = (pSymbolDictDecoder->SDTEMPLATE == 0) ? 8 : 2;
     for (uint32_t i = 0; i < dwTemp; ++i) {
       if (m_pStream->read1Byte((uint8_t*)&pSymbolDictDecoder->SDAT[i]) != 0)
         return JBig2_Result::kFailure;
     }
   }
-  if (pSymbolDictDecoder->SDREFAGG == 1 && !pSymbolDictDecoder->SDRTEMPLATE) {
+  if (pSymbolDictDecoder->SDREFAGG && !pSymbolDictDecoder->SDRTEMPLATE) {
     for (int32_t i = 0; i < 4; ++i) {
       if (m_pStream->read1Byte((uint8_t*)&pSymbolDictDecoder->SDRAT[i]) != 0)
         return JBig2_Result::kFailure;
@@ -444,7 +444,7 @@
 
   uint8_t cSDHUFFDH = (wFlags >> 2) & 0x0003;
   uint8_t cSDHUFFDW = (wFlags >> 4) & 0x0003;
-  if (pSymbolDictDecoder->SDHUFF == 1) {
+  if (pSymbolDictDecoder->SDHUFF) {
     if (cSDHUFFDH == 2 || cSDHUFFDW == 2)
       return JBig2_Result::kFailure;
 
@@ -481,7 +481,7 @@
         return JBig2_Result::kFailure;
       pSymbolDictDecoder->SDHUFFBMSIZE = pSeg->m_HuffmanTable.get();
     }
-    if (pSymbolDictDecoder->SDREFAGG == 1) {
+    if (pSymbolDictDecoder->SDREFAGG) {
       uint8_t cSDHUFFAGGINST = (wFlags >> 7) & 0x0001;
       if (cSDHUFFAGGINST == 0) {
         pSymbolDictDecoder->SDHUFFAGGINST = GetHuffmanTable(1);
@@ -495,8 +495,8 @@
     }
   }
 
-  const bool bUseGbContext = (pSymbolDictDecoder->SDHUFF == 0);
-  const bool bUseGrContext = (pSymbolDictDecoder->SDREFAGG == 1);
+  const bool bUseGbContext = !pSymbolDictDecoder->SDHUFF;
+  const bool bUseGrContext = pSymbolDictDecoder->SDREFAGG;
   const size_t gbContextSize =
       GetHuffContextSize(pSymbolDictDecoder->SDTEMPLATE);
   const size_t grContextSize =
@@ -602,10 +602,10 @@
   }
   pTRD->SBRTEMPLATE = !!((wFlags >> 15) & 0x0001);
 
-  if (pTRD->SBHUFF == 1 && m_pStream->readShortInteger(&wFlags) != 0) {
+  if (pTRD->SBHUFF && m_pStream->readShortInteger(&wFlags) != 0) {
     return JBig2_Result::kFailure;
   }
-  if (pTRD->SBREFINE == 1 && !pTRD->SBRTEMPLATE) {
+  if (pTRD->SBREFINE && !pTRD->SBRTEMPLATE) {
     for (int32_t i = 0; i < 4; ++i) {
       if (m_pStream->read1Byte((uint8_t*)&pTRD->SBRAT[i]) != 0)
         return JBig2_Result::kFailure;
@@ -660,7 +660,7 @@
     pTRD->SBSYMS = nullptr;
   }
 
-  if (pTRD->SBHUFF == 1) {
+  if (pTRD->SBHUFF) {
     std::vector<JBig2HuffmanCode> SBSYMCODES =
         DecodeSymbolIDHuffmanTable(pTRD->SBNUMSYMS);
     if (SBSYMCODES.empty())
@@ -676,7 +676,7 @@
     pTRD->SBSYMCODELEN = (uint8_t)dwTemp;
   }
 
-  if (pTRD->SBHUFF == 1) {
+  if (pTRD->SBHUFF) {
     uint8_t cSBHUFFFS = wFlags & 0x0003;
     uint8_t cSBHUFFDS = (wFlags >> 2) & 0x0003;
     uint8_t cSBHUFFDT = (wFlags >> 4) & 0x0003;
@@ -782,33 +782,30 @@
     }
   }
   std::unique_ptr<JBig2ArithCtx, FxFreeDeleter> grContext;
-  if (pTRD->SBREFINE == 1) {
+  if (pTRD->SBREFINE) {
     const size_t size = GetRefAggContextSize(pTRD->SBRTEMPLATE);
     grContext.reset(FX_Alloc(JBig2ArithCtx, size));
   }
-  if (pTRD->SBHUFF == 0) {
+  pSegment->m_nResultType = JBIG2_IMAGE_POINTER;
+  if (pTRD->SBHUFF) {
+    pSegment->m_Image = pTRD->DecodeHuffman(m_pStream.get(), grContext.get());
+    if (!pSegment->m_Image)
+      return JBig2_Result::kFailure;
+    m_pStream->alignByte();
+  } else {
     auto pArithDecoder = std::make_unique<CJBig2_ArithDecoder>(m_pStream.get());
-    pSegment->m_nResultType = JBIG2_IMAGE_POINTER;
     pSegment->m_Image =
         pTRD->DecodeArith(pArithDecoder.get(), grContext.get(), nullptr);
     if (!pSegment->m_Image)
       return JBig2_Result::kFailure;
     m_pStream->alignByte();
     m_pStream->offset(2);
-  } else {
-    pSegment->m_nResultType = JBIG2_IMAGE_POINTER;
-    pSegment->m_Image = pTRD->DecodeHuffman(m_pStream.get(), grContext.get());
-    if (!pSegment->m_Image)
-      return JBig2_Result::kFailure;
-    m_pStream->alignByte();
   }
   if (pSegment->m_cFlags.s.type != 4) {
     if (!m_bBufSpecified) {
       const auto& pPageInfo = m_PageInfoList.back();
-      if ((pPageInfo->m_bIsStriped == 1) &&
-          (ri.y + ri.height > m_pPage->height())) {
+      if (pPageInfo->m_bIsStriped && ri.y + ri.height > m_pPage->height())
         m_pPage->Expand(ri.y + ri.height, pPageInfo->m_bDefaultPixelValue);
-      }
     }
     m_pPage->ComposeFrom(ri.x, ri.y, pSegment->m_Image.get(),
                          (JBig2ComposeOp)(ri.flags & 0x03));
@@ -833,7 +830,12 @@
   pPDD->HDMMR = cFlags & 0x01;
   pPDD->HDTEMPLATE = (cFlags >> 1) & 0x03;
   pSegment->m_nResultType = JBIG2_PATTERN_DICT_POINTER;
-  if (pPDD->HDMMR == 0) {
+  if (pPDD->HDMMR) {
+    pSegment->m_PatternDict = pPDD->DecodeMMR(m_pStream.get());
+    if (!pSegment->m_PatternDict)
+      return JBig2_Result::kFailure;
+    m_pStream->alignByte();
+  } else {
     const size_t size = GetHuffContextSize(pPDD->HDTEMPLATE);
     std::unique_ptr<JBig2ArithCtx, FxFreeDeleter> gbContext(
         FX_Alloc(JBig2ArithCtx, size));
@@ -845,11 +847,6 @@
 
     m_pStream->alignByte();
     m_pStream->offset(2);
-  } else {
-    pSegment->m_PatternDict = pPDD->DecodeMMR(m_pStream.get());
-    if (!pSegment->m_PatternDict)
-      return JBig2_Result::kFailure;
-    m_pStream->alignByte();
   }
   return JBig2_Result::kSuccess;
 }
@@ -900,7 +897,12 @@
   pHRD->HPW = pPatternDict->HDPATS[0]->width();
   pHRD->HPH = pPatternDict->HDPATS[0]->height();
   pSegment->m_nResultType = JBIG2_IMAGE_POINTER;
-  if (pHRD->HMMR == 0) {
+  if (pHRD->HMMR) {
+    pSegment->m_Image = pHRD->DecodeMMR(m_pStream.get());
+    if (!pSegment->m_Image)
+      return JBig2_Result::kFailure;
+    m_pStream->alignByte();
+  } else {
     const size_t size = GetHuffContextSize(pHRD->HTEMPLATE);
     std::unique_ptr<JBig2ArithCtx, FxFreeDeleter> gbContext(
         FX_Alloc(JBig2ArithCtx, size));
@@ -912,19 +914,12 @@
 
     m_pStream->alignByte();
     m_pStream->offset(2);
-  } else {
-    pSegment->m_Image = pHRD->DecodeMMR(m_pStream.get());
-    if (!pSegment->m_Image)
-      return JBig2_Result::kFailure;
-    m_pStream->alignByte();
   }
   if (pSegment->m_cFlags.s.type != 20) {
     if (!m_bBufSpecified) {
       const auto& pPageInfo = m_PageInfoList.back();
-      if (pPageInfo->m_bIsStriped == 1 &&
-          ri.y + ri.height > m_pPage->height()) {
+      if (pPageInfo->m_bIsStriped && ri.y + ri.height > m_pPage->height())
         m_pPage->Expand(ri.y + ri.height, pPageInfo->m_bDefaultPixelValue);
-      }
     }
     m_pPage->ComposeFrom(ri.x, ri.y, pSegment->m_Image.get(),
                          (JBig2ComposeOp)(ri.flags & 0x03));
@@ -949,7 +944,7 @@
     pGRD->MMR = cFlags & 0x01;
     pGRD->GBTEMPLATE = (cFlags >> 1) & 0x03;
     pGRD->TPGDON = (cFlags >> 3) & 0x01;
-    if (pGRD->MMR == 0) {
+    if (!pGRD->MMR) {
       if (pGRD->GBTEMPLATE == 0) {
         for (int32_t i = 0; i < 8; ++i) {
           if (m_pStream->read1Byte((uint8_t*)&pGRD->GBAT[i]) != 0)
@@ -966,7 +961,14 @@
     m_pGRD = std::move(pGRD);
   }
   pSegment->m_nResultType = JBIG2_IMAGE_POINTER;
-  if (m_pGRD->MMR == 0) {
+  if (m_pGRD->MMR) {
+    m_pGRD->StartDecodeMMR(&pSegment->m_Image, m_pStream.get());
+    if (!pSegment->m_Image) {
+      m_pGRD.reset();
+      return JBig2_Result::kFailure;
+    }
+    m_pStream->alignByte();
+  } else {
     if (m_gbContext.empty())
       m_gbContext.resize(GetHuffContextSize(m_pGRD->GBTEMPLATE));
 
@@ -987,8 +989,8 @@
         if (pSegment->m_cFlags.s.type != 36) {
           if (!m_bBufSpecified) {
             const auto& pPageInfo = m_PageInfoList.back();
-            if ((pPageInfo->m_bIsStriped == 1) &&
-                (m_ri.y + m_ri.height > m_pPage->height())) {
+            if (pPageInfo->m_bIsStriped &&
+                m_ri.y + m_ri.height > m_pPage->height()) {
               m_pPage->Expand(m_ri.y + m_ri.height,
                               pPageInfo->m_bDefaultPixelValue);
             }
@@ -1010,21 +1012,12 @@
     }
     m_pStream->alignByte();
     m_pStream->offset(2);
-  } else {
-    m_pGRD->StartDecodeMMR(&pSegment->m_Image, m_pStream.get());
-    if (!pSegment->m_Image) {
-      m_pGRD.reset();
-      return JBig2_Result::kFailure;
-    }
-    m_pStream->alignByte();
   }
   if (pSegment->m_cFlags.s.type != 36) {
     if (!m_bBufSpecified) {
       JBig2PageInfo* pPageInfo = m_PageInfoList.back().get();
-      if ((pPageInfo->m_bIsStriped == 1) &&
-          (m_ri.y + m_ri.height > m_pPage->height())) {
+      if (pPageInfo->m_bIsStriped && m_ri.y + m_ri.height > m_pPage->height())
         m_pPage->Expand(m_ri.y + m_ri.height, pPageInfo->m_bDefaultPixelValue);
-      }
     }
     const FX_RECT& rect = m_pGRD->GetReplaceRect();
     m_pPage->ComposeFromWithRect(m_ri.x + rect.left, m_ri.y + rect.top,
@@ -1094,10 +1087,8 @@
   if (pSegment->m_cFlags.s.type != 40) {
     if (!m_bBufSpecified) {
       JBig2PageInfo* pPageInfo = m_PageInfoList.back().get();
-      if ((pPageInfo->m_bIsStriped == 1) &&
-          (ri.y + ri.height > m_pPage->height())) {
+      if (pPageInfo->m_bIsStriped && ri.y + ri.height > m_pPage->height())
         m_pPage->Expand(ri.y + ri.height, pPageInfo->m_bDefaultPixelValue);
-      }
     }
     m_pPage->ComposeFrom(ri.x, ri.y, pSegment->m_Image.get(),
                          (JBig2ComposeOp)(ri.flags & 0x03));