Read an int32 and verify lo <= v <= hi. On out-of-range, abort with a * protocol error naming "what". The bound is co-located with the read so it * cannot be forgotten by a downstream user. */
| 1890 | * protocol error naming "what". The bound is co-located with the read so it |
| 1891 | * cannot be forgotten by a downstream user. */ |
| 1892 | int32 read_int_bounded(int f, int32 lo, int32 hi, const char *what) |
| 1893 | { |
| 1894 | int32 v = read_int(f); |
| 1895 | if (v < lo || v > hi) { |
| 1896 | rprintf(FERROR, "wire value %s out of range: %ld not in [%ld,%ld] [%s]\n", |
| 1897 | what, (long)v, (long)lo, (long)hi, who_am_i()); |
| 1898 | exit_cleanup(RERR_PROTOCOL); |
| 1899 | } |
| 1900 | return v; |
| 1901 | } |
| 1902 | |
| 1903 | /* As read_int_bounded but for varint-encoded values. */ |
| 1904 | int32 read_varint_bounded(int f, int32 lo, int32 hi, const char *what) |