1 /* lzo1_d.ch -- common decompression stuff
3 This file is part of the LZO real-time data compression library.
5 Copyright (C) 1996-2014 Markus Franz Xaver Johannes Oberhumer
8 The LZO library is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of
11 the License, or (at your option) any later version.
13 The LZO library is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with the LZO library; see the file COPYING.
20 If not, write to the Free Software Foundation, Inc.,
21 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
23 Markus F.X.J. Oberhumer
24 <markus@oberhumer.com>
25 http://www.oberhumer.com/opensource/lzo/
30 #if defined(LZO_TEST_OVERRUN)
31 # if !defined(LZO_TEST_OVERRUN_INPUT)
32 # define LZO_TEST_OVERRUN_INPUT 2
34 # if !defined(LZO_TEST_OVERRUN_OUTPUT)
35 # define LZO_TEST_OVERRUN_OUTPUT 2
37 # if !defined(LZO_TEST_OVERRUN_LOOKBEHIND)
38 # define LZO_TEST_OVERRUN_LOOKBEHIND 1
43 /***********************************************************************
44 // Overrun detection is internally handled by these macros:
46 // TEST_IP test input overrun at loop begin
47 // NEED_IP test input overrun at every input byte
49 // TEST_OP test output overrun at loop begin
50 // NEED_OP test output overrun at every output byte
52 // TEST_LB test match position
54 // The fastest decompressor results when testing for no overruns
55 // and using LZO_EOF_CODE.
56 ************************************************************************/
60 #undef TEST_IP_AND_TEST_OP
75 #if defined(LZO_TEST_OVERRUN_INPUT)
76 # if (LZO_TEST_OVERRUN_INPUT >= 1)
77 # define TEST_IP (ip < ip_end)
79 # if (LZO_TEST_OVERRUN_INPUT >= 2)
81 if ((lzo_uint)(ip_end - ip) < (lzo_uint)(x)) goto input_overrun
82 # define TEST_IV(x) if ((x) > (lzo_uint)0 - (511)) goto input_overrun
86 #if defined(LZO_TEST_OVERRUN_OUTPUT)
87 # if (LZO_TEST_OVERRUN_OUTPUT >= 1)
88 # define TEST_OP (op <= op_end)
90 # if (LZO_TEST_OVERRUN_OUTPUT >= 2)
91 # undef TEST_OP /* don't need both of the tests here */
93 if ((lzo_uint)(op_end - op) < (lzo_uint)(x)) goto output_overrun
94 # define TEST_OV(x) if ((x) > (lzo_uint)0 - (511)) goto output_overrun
98 #if defined(LZO_TEST_OVERRUN_LOOKBEHIND)
99 # define TEST_LB(m_pos) if (PTR_LT(m_pos,out) || PTR_GE(m_pos,op)) goto lookbehind_overrun
100 # define TEST_LBO(m_pos,o) if (PTR_LT(m_pos,out) || PTR_GE(m_pos,op-(o))) goto lookbehind_overrun
102 # define TEST_LB(m_pos) ((void) 0)
103 # define TEST_LBO(m_pos,o) ((void) 0)
107 #if !defined(LZO_EOF_CODE) && !defined(TEST_IP)
108 /* if we have no EOF code, we have to test for the end of the input */
109 # define TEST_IP (ip < ip_end)
114 # define HAVE_TEST_IP 1
119 # define HAVE_TEST_OP 1
124 #if defined(HAVE_TEST_IP) && defined(HAVE_TEST_OP)
125 # define TEST_IP_AND_TEST_OP (TEST_IP && TEST_OP)
126 #elif defined(HAVE_TEST_IP)
127 # define TEST_IP_AND_TEST_OP TEST_IP
128 #elif defined(HAVE_TEST_OP)
129 # define TEST_IP_AND_TEST_OP TEST_OP
131 # define TEST_IP_AND_TEST_OP 1
135 # define HAVE_NEED_IP 1
137 # define NEED_IP(x) ((void) 0)
138 # define TEST_IV(x) ((void) 0)
141 # define HAVE_NEED_OP 1
143 # define NEED_OP(x) ((void) 0)
144 # define TEST_OV(x) ((void) 0)
148 #if defined(HAVE_TEST_IP) || defined(HAVE_NEED_IP)
149 # define HAVE_ANY_IP 1
151 #if defined(HAVE_TEST_OP) || defined(HAVE_NEED_OP)
152 # define HAVE_ANY_OP 1