Check for NULL pointers in CJBig2_SymbolDict::DeepCopy().
[pdfium.git] / core / src / fxcodec / jbig2 / JBig2_ArithDecoder.h
index 1664257..214688d 100644 (file)
-// Copyright 2014 PDFium Authors. All rights reserved.\r
-// Use of this source code is governed by a BSD-style license that can be\r
-// found in the LICENSE file.\r
\r
-// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com\r
-\r
-#ifndef _JBIG2_ARITHMETIC_DECODER_H_\r
-#define _JBIG2_ARITHMETIC_DECODER_H_\r
-#include "JBig2_Define.h"\r
-#include "JBig2_BitStream.h"\r
-#include "JBig2_ArithQe.h"\r
-typedef struct {\r
-    unsigned int MPS;\r
-    unsigned int I;\r
-} JBig2ArithCtx;\r
-class CJBig2_ArithDecoder : public CJBig2_Object\r
-{\r
-public:\r
-\r
-    CJBig2_ArithDecoder(CJBig2_BitStream *pStream);\r
-\r
-    ~CJBig2_ArithDecoder();\r
-\r
-    int DECODE(JBig2ArithCtx *pCX);\r
-private:\r
-\r
-    void INITDEC();\r
-\r
-    void BYTEIN();\r
-    unsigned char B;\r
-    unsigned int C;\r
-    unsigned int A;\r
-    unsigned int CT;\r
-    CJBig2_BitStream *m_pStream;\r
-};\r
-inline CJBig2_ArithDecoder::CJBig2_ArithDecoder(CJBig2_BitStream *pStream)\r
-{\r
-    m_pStream = pStream;\r
-    INITDEC();\r
-}\r
-inline CJBig2_ArithDecoder::~CJBig2_ArithDecoder()\r
-{\r
-}\r
-inline void CJBig2_ArithDecoder::INITDEC()\r
-{\r
-    B = m_pStream->getCurByte_arith();\r
-    C = (B ^ 0xff) << 16;;\r
-    BYTEIN();\r
-    C = C << 7;\r
-    CT = CT - 7;\r
-    A = 0x8000;\r
-}\r
-inline void CJBig2_ArithDecoder::BYTEIN()\r
-{\r
-    unsigned char B1;\r
-    if(B == 0xff) {\r
-        B1 = m_pStream->getNextByte_arith();\r
-        if(B1 > 0x8f) {\r
-            CT = 8;\r
-        } else {\r
-            m_pStream->incByteIdx();\r
-            B = B1;\r
-            C = C + 0xfe00 - (B << 9);\r
-            CT = 7;\r
-        }\r
-    } else {\r
-        m_pStream->incByteIdx();\r
-        B = m_pStream->getCurByte_arith();\r
-        C = C + 0xff00 - (B << 8);\r
-        CT = 8;\r
-    }\r
-}\r
-inline int CJBig2_ArithDecoder::DECODE(JBig2ArithCtx *pCX)\r
-{\r
-    int D;\r
-    const JBig2ArithQe * qe = &QeTable[pCX->I];\r
-    A = A - qe->Qe;\r
-    if((C >> 16) < A) {\r
-        if(A & 0x8000) {\r
-            D = pCX->MPS;\r
-        } else {\r
-            if(A < qe->Qe) {\r
-                D = 1 - pCX->MPS;\r
-                if(qe->nSwitch == 1) {\r
-                    pCX->MPS = 1 - pCX->MPS;\r
-                }\r
-                pCX->I = qe->NLPS;\r
-            } else {\r
-                D = pCX->MPS;\r
-                pCX->I = qe->NMPS;\r
-            }\r
-            do {\r
-                if (CT == 0) {\r
-                    BYTEIN();\r
-                }\r
-                A <<= 1;\r
-                C <<= 1;\r
-                CT--;\r
-            } while ((A & 0x8000) == 0);\r
-        }\r
-    } else {\r
-        C -= A << 16;\r
-        if(A < qe->Qe) {\r
-            A = qe->Qe;\r
-            D = pCX->MPS;\r
-            pCX->I = qe->NMPS;\r
-        } else {\r
-            A = qe->Qe;\r
-            D = 1 - pCX->MPS;\r
-            if(qe->nSwitch == 1) {\r
-                pCX->MPS = 1 - pCX->MPS;\r
-            }\r
-            pCX->I = qe->NLPS;\r
-        }\r
-        do {\r
-            if (CT == 0) {\r
-                BYTEIN();\r
-            }\r
-            A <<= 1;\r
-            C <<= 1;\r
-            CT--;\r
-        } while ((A & 0x8000) == 0);\r
-    }\r
-    return D;\r
-}\r
-#endif\r
+// Copyright 2014 PDFium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
+
+#ifndef _JBIG2_ARITHMETIC_DECODER_H_
+#define _JBIG2_ARITHMETIC_DECODER_H_
+#include "JBig2_Define.h"
+#include "JBig2_BitStream.h"
+#include "JBig2_ArithQe.h"
+typedef struct {
+    unsigned int MPS;
+    unsigned int I;
+} JBig2ArithCtx;
+class CJBig2_ArithDecoder : public CJBig2_Object
+{
+public:
+
+    CJBig2_ArithDecoder(CJBig2_BitStream *pStream);
+
+    ~CJBig2_ArithDecoder();
+
+    int DECODE(JBig2ArithCtx *pCX);
+private:
+
+    void INITDEC();
+
+    void BYTEIN();
+    unsigned char B;
+    unsigned int C;
+    unsigned int A;
+    unsigned int CT;
+    CJBig2_BitStream *m_pStream;
+};
+inline CJBig2_ArithDecoder::CJBig2_ArithDecoder(CJBig2_BitStream *pStream)
+{
+    m_pStream = pStream;
+    INITDEC();
+}
+inline CJBig2_ArithDecoder::~CJBig2_ArithDecoder()
+{
+}
+inline void CJBig2_ArithDecoder::INITDEC()
+{
+    B = m_pStream->getCurByte_arith();
+    C = (B ^ 0xff) << 16;;
+    BYTEIN();
+    C = C << 7;
+    CT = CT - 7;
+    A = 0x8000;
+}
+inline void CJBig2_ArithDecoder::BYTEIN()
+{
+    unsigned char B1;
+    if(B == 0xff) {
+        B1 = m_pStream->getNextByte_arith();
+        if(B1 > 0x8f) {
+            CT = 8;
+        } else {
+            m_pStream->incByteIdx();
+            B = B1;
+            C = C + 0xfe00 - (B << 9);
+            CT = 7;
+        }
+    } else {
+        m_pStream->incByteIdx();
+        B = m_pStream->getCurByte_arith();
+        C = C + 0xff00 - (B << 8);
+        CT = 8;
+    }
+}
+inline int CJBig2_ArithDecoder::DECODE(JBig2ArithCtx *pCX)
+{
+    int D;
+    const JBig2ArithQe * qe = &QeTable[pCX->I];
+    A = A - qe->Qe;
+    if((C >> 16) < A) {
+        if(A & 0x8000) {
+            D = pCX->MPS;
+        } else {
+            if(A < qe->Qe) {
+                D = 1 - pCX->MPS;
+                if(qe->nSwitch == 1) {
+                    pCX->MPS = 1 - pCX->MPS;
+                }
+                pCX->I = qe->NLPS;
+            } else {
+                D = pCX->MPS;
+                pCX->I = qe->NMPS;
+            }
+            do {
+                if (CT == 0) {
+                    BYTEIN();
+                }
+                A <<= 1;
+                C <<= 1;
+                CT--;
+            } while ((A & 0x8000) == 0);
+        }
+    } else {
+        C -= A << 16;
+        if(A < qe->Qe) {
+            A = qe->Qe;
+            D = pCX->MPS;
+            pCX->I = qe->NMPS;
+        } else {
+            A = qe->Qe;
+            D = 1 - pCX->MPS;
+            if(qe->nSwitch == 1) {
+                pCX->MPS = 1 - pCX->MPS;
+            }
+            pCX->I = qe->NLPS;
+        }
+        do {
+            if (CT == 0) {
+                BYTEIN();
+            }
+            A <<= 1;
+            C <<= 1;
+            CT--;
+        } while ((A & 0x8000) == 0);
+    }
+    return D;
+}
+#endif