| 1814 | } |
| 1815 | |
| 1816 | int32 read_varint(int f) |
| 1817 | { |
| 1818 | union { |
| 1819 | char b[5]; |
| 1820 | int32 x; |
| 1821 | } u; |
| 1822 | uchar ch; |
| 1823 | int extra; |
| 1824 | |
| 1825 | u.x = 0; |
| 1826 | ch = read_byte(f); |
| 1827 | extra = int_byte_extra[ch / 4]; |
| 1828 | if (extra) { |
| 1829 | uchar bit = ((uchar)1<<(8-extra)); |
| 1830 | if (extra >= (int)sizeof u.b) { |
| 1831 | rprintf(FERROR, "Overflow in read_varint()\n"); |
| 1832 | exit_cleanup(RERR_STREAMIO); |
| 1833 | } |
| 1834 | read_buf(f, u.b, extra); |
| 1835 | u.b[extra] = ch & (bit-1); |
| 1836 | } else |
| 1837 | u.b[0] = ch; |
| 1838 | #if CAREFUL_ALIGNMENT |
| 1839 | u.x = IVAL(u.b,0); |
| 1840 | #endif |
| 1841 | #if SIZEOF_INT32 > 4 |
| 1842 | if (u.x & (int32)0x80000000) |
| 1843 | u.x |= ~(int32)0xffffffff; |
| 1844 | #endif |
| 1845 | return u.x; |
| 1846 | } |
| 1847 | |
| 1848 | int64 read_varlong(int f, uchar min_bytes) |
| 1849 | { |
no test coverage detected