| 147 | } |
| 148 | |
| 149 | static inline bool DecodeSignedLeb128Checked(const uint8_t** data, |
| 150 | const void* end, |
| 151 | int32_t* out) { |
| 152 | const uint8_t* ptr = *data; |
| 153 | if (ptr >= end) { |
| 154 | return false; |
| 155 | } |
| 156 | int32_t result = *(ptr++); |
| 157 | if (result <= 0x7f) { |
| 158 | result = (result << 25) >> 25; |
| 159 | } else { |
| 160 | if (ptr >= end) { |
| 161 | return false; |
| 162 | } |
| 163 | int cur = *(ptr++); |
| 164 | result = (result & 0x7f) | ((cur & 0x7f) << 7); |
| 165 | if (cur <= 0x7f) { |
| 166 | result = (result << 18) >> 18; |
| 167 | } else { |
| 168 | if (ptr >= end) { |
| 169 | return false; |
| 170 | } |
| 171 | cur = *(ptr++); |
| 172 | result |= (cur & 0x7f) << 14; |
| 173 | if (cur <= 0x7f) { |
| 174 | result = (result << 11) >> 11; |
| 175 | } else { |
| 176 | if (ptr >= end) { |
| 177 | return false; |
| 178 | } |
| 179 | cur = *(ptr++); |
| 180 | result |= (cur & 0x7f) << 21; |
| 181 | if (cur <= 0x7f) { |
| 182 | result = (result << 4) >> 4; |
| 183 | } else { |
| 184 | if (ptr >= end) { |
| 185 | return false; |
| 186 | } |
| 187 | // Note: We don't check to see if cur is out of range here, |
| 188 | // meaning we tolerate garbage in the four high-order bits. |
| 189 | cur = *(ptr++); |
| 190 | result |= cur << 28; |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | *data = ptr; |
| 196 | *out = static_cast<uint32_t>(result); |
| 197 | return true; |
| 198 | } |
| 199 | |
| 200 | // Returns the number of bytes needed to encode the value in unsigned LEB128. |
| 201 | static inline uint32_t UnsignedLeb128Size(uint32_t data) { |
nothing calls this directly
no outgoing calls
no test coverage detected