2 * Copyright (C) 2008 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * Functions for interpreting LEB128 (little endian base 128) values
24 * Reads an unsigned LEB128 value, updating the given pointer to point
25 * just past the end of the read value and also indicating whether the
26 * value was syntactically valid. The only syntactically *invalid*
27 * values are ones that are five bytes long where the final byte has
28 * any but the low-order four bits set. Additionally, if the limit is
29 * passed as non-NULL and bytes would need to be read past the limit,
30 * then the read is considered invalid.
32 int readAndVerifyUnsignedLeb128(const u1** pStream, const u1* limit,
34 const u1* ptr = *pStream;
35 int result = readUnsignedLeb128(pStream);
37 if (((limit != NULL) && (*pStream > limit))
38 || (((*pStream - ptr) == 5) && (ptr[4] > 0x0f))) {
46 * Reads a signed LEB128 value, updating the given pointer to point
47 * just past the end of the read value and also indicating whether the
48 * value was syntactically valid. The only syntactically *invalid*
49 * values are ones that are five bytes long where the final byte has
50 * any but the low-order four bits set. Additionally, if the limit is
51 * passed as non-NULL and bytes would need to be read past the limit,
52 * then the read is considered invalid.
54 int readAndVerifySignedLeb128(const u1** pStream, const u1* limit,
56 const u1* ptr = *pStream;
57 int result = readSignedLeb128(pStream);
59 if (((limit != NULL) && (*pStream > limit))
60 || (((*pStream - ptr) == 5) && (ptr[4] > 0x0f))) {