diff options
author | Pau Espin Pedrol <pespin@sysmocom.de> | 2017-06-18 00:52:56 +0200 |
---|---|---|
committer | Pau Espin Pedrol <pespin@sysmocom.de> | 2017-06-18 10:40:18 +0200 |
commit | 21be83794fb856f93e545ece7d60a451ea26bacc (patch) | |
tree | a70ac01b8659f3544c28fee5194519b179413597 /tests | |
parent | faa04613143eff3345e9a0e1b7abebefb977e6e0 (diff) |
tlv_test.c: Fix compilation warnings
Several warnings like the one below are fixed:
warning: array subscript is below array bounds [-Warray-bounds]
uint8_t *unchanged_ptr = buf - 1;
Change-Id: I35d7d926939c14700cbca732bd64e588c75424b4
Diffstat (limited to 'tests')
-rw-r--r-- | tests/tlv/tlv_test.c | 44 |
1 files changed, 25 insertions, 19 deletions
diff --git a/tests/tlv/tlv_test.c b/tests/tlv/tlv_test.c index c571c3bd..87b002f0 100644 --- a/tests/tlv/tlv_test.c +++ b/tests/tlv/tlv_test.c @@ -70,23 +70,24 @@ static void check_lv_shift(uint8_t **data, size_t *data_len, static void check_tlv_match_data_len(size_t data_len, uint8_t tag, size_t len, const uint8_t *test_data) { - uint8_t buf[300] = {0}; + uint8_t buf[301] = {0}; + *buf = 0xfe; - uint8_t *unchanged_ptr = buf - 1; + uint8_t *unchanged_ptr = buf; size_t unchanged_len = 0xdead; size_t tmp_data_len = data_len; uint8_t *value = unchanged_ptr; size_t value_len = unchanged_len; - uint8_t *data = buf; + uint8_t *data = buf + 1; - OSMO_ASSERT(data_len <= sizeof(buf)); + OSMO_ASSERT(data_len <= sizeof(buf) - 1); tlv_put(data, tag, len, test_data); if (data_len < len + 2) { OSMO_ASSERT(-1 == osmo_match_shift_tlv(&data, &tmp_data_len, tag, &value, &value_len)); OSMO_ASSERT(tmp_data_len == 0); - OSMO_ASSERT(data == buf + data_len); + OSMO_ASSERT(data == buf + 1 + data_len); OSMO_ASSERT(value == unchanged_ptr); OSMO_ASSERT(value_len == unchanged_len); } else { @@ -101,14 +102,15 @@ static void check_tv_fixed_match_data_len(size_t data_len, uint8_t tag, size_t len, const uint8_t *test_data) { - uint8_t buf[300] = {0}; + uint8_t buf[301] = {0}; + *buf = 0xfe; - uint8_t *unchanged_ptr = buf - 1; + uint8_t *unchanged_ptr = buf; size_t tmp_data_len = data_len; uint8_t *value = unchanged_ptr; - uint8_t *data = buf; + uint8_t *data = buf + 1; - OSMO_ASSERT(data_len <= sizeof(buf)); + OSMO_ASSERT(data_len <= sizeof(buf) - 1); tv_fixed_put(data, tag, len, test_data); @@ -116,7 +118,7 @@ static void check_tv_fixed_match_data_len(size_t data_len, OSMO_ASSERT(-1 == osmo_match_shift_tv_fixed(&data, &tmp_data_len, tag, len, &value)); OSMO_ASSERT(tmp_data_len == 0); - OSMO_ASSERT(data == buf + data_len); + OSMO_ASSERT(data == buf + 1 + data_len); OSMO_ASSERT(value == unchanged_ptr); } else { OSMO_ASSERT(0 <= osmo_match_shift_tv_fixed(&data, &tmp_data_len, @@ -128,14 +130,15 @@ static void check_tv_fixed_match_data_len(size_t data_len, static void check_v_fixed_shift_data_len(size_t data_len, size_t len, const uint8_t *test_data) { - uint8_t buf[300] = {0}; + uint8_t buf[301] = {0}; + *buf = 0xfe; - uint8_t *unchanged_ptr = buf - 1; + uint8_t *unchanged_ptr = buf; size_t tmp_data_len = data_len; uint8_t *value = unchanged_ptr; - uint8_t *data = buf; + uint8_t *data = buf + 1; - OSMO_ASSERT(data_len <= sizeof(buf)); + OSMO_ASSERT(data_len <= sizeof(buf) - 1); memcpy(data, test_data, len); @@ -143,7 +146,7 @@ static void check_v_fixed_shift_data_len(size_t data_len, OSMO_ASSERT(-1 == osmo_shift_v_fixed(&data, &tmp_data_len, len, &value)); OSMO_ASSERT(tmp_data_len == 0); - OSMO_ASSERT(data == buf + data_len); + OSMO_ASSERT(data == buf + 1 + data_len); OSMO_ASSERT(value == unchanged_ptr); } else { OSMO_ASSERT(0 <= osmo_shift_v_fixed(&data, &tmp_data_len, @@ -155,21 +158,24 @@ static void check_v_fixed_shift_data_len(size_t data_len, static void check_lv_shift_data_len(size_t data_len, size_t len, const uint8_t *test_data) { - uint8_t buf[300] = {0}; + uint8_t buf[301] = {0}; + *buf = 0xfe; - uint8_t *unchanged_ptr = buf - 1; + uint8_t *unchanged_ptr = buf; size_t unchanged_len = 0xdead; size_t tmp_data_len = data_len; uint8_t *value = unchanged_ptr; size_t value_len = unchanged_len; - uint8_t *data = buf; + uint8_t *data = buf + 1; + + OSMO_ASSERT(data_len <= sizeof(buf) - 1); lv_put(data, len, test_data); if (data_len < len + 1) { OSMO_ASSERT(-1 == osmo_shift_lv(&data, &tmp_data_len, &value, &value_len)); OSMO_ASSERT(tmp_data_len == 0); - OSMO_ASSERT(data == buf + data_len); + OSMO_ASSERT(data == buf + 1 + data_len); OSMO_ASSERT(value == unchanged_ptr); OSMO_ASSERT(value_len == unchanged_len); } else { |