Reads a signed LEB128 value, updating the given pointer to point just past the end of the read value. This function tolerates non-zero high-order bits in the fifth encoded byte.
| 114 | // just past the end of the read value. This function tolerates |
| 115 | // non-zero high-order bits in the fifth encoded byte. |
| 116 | static inline int32_t DecodeSignedLeb128(const uint8_t** data) { |
| 117 | const uint8_t* ptr = *data; |
| 118 | int32_t result = *(ptr++); |
| 119 | if (result <= 0x7f) { |
| 120 | result = (result << 25) >> 25; |
| 121 | } else { |
| 122 | int cur = *(ptr++); |
| 123 | result = (result & 0x7f) | ((cur & 0x7f) << 7); |
| 124 | if (cur <= 0x7f) { |
| 125 | result = (result << 18) >> 18; |
| 126 | } else { |
| 127 | cur = *(ptr++); |
| 128 | result |= (cur & 0x7f) << 14; |
| 129 | if (cur <= 0x7f) { |
| 130 | result = (result << 11) >> 11; |
| 131 | } else { |
| 132 | cur = *(ptr++); |
| 133 | result |= (cur & 0x7f) << 21; |
| 134 | if (cur <= 0x7f) { |
| 135 | result = (result << 4) >> 4; |
| 136 | } else { |
| 137 | // Note: We don't check to see if cur is out of range here, |
| 138 | // meaning we tolerate garbage in the four high-order bits. |
| 139 | cur = *(ptr++); |
| 140 | result |= cur << 28; |
| 141 | } |
| 142 | } |
| 143 | } |
| 144 | } |
| 145 | *data = ptr; |
| 146 | return result; |
| 147 | } |
| 148 | |
| 149 | static inline bool DecodeSignedLeb128Checked(const uint8_t** data, |
| 150 | const void* end, |
no outgoing calls
no test coverage detected