This is merely a historical archive of years 2008-2021, before the migration to mailman3.
A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.
daniel gerrit-no-reply at lists.osmocom.orgdaniel has uploaded this change for review. ( https://gerrit.osmocom.org/c/libosmocore/+/23401 ) Change subject: tlv: Fix length returned by t{l16,16l}v_put ...................................................................... tlv: Fix length returned by t{l16,16l}v_put Every other function returns a pointer to the first byte after the tlv that was just written. tl16v seems to be a copy and paste error from tlv16 above and t16lv seems to count the 16-bit tag twice. The new tests verify that the return value of *_put(buf, tag, len, val) points to buf + *_GROSS_LEN(len). Change-Id: I268a7e11fb5dce67ce1bd7974ab86c4d2bd002f7 --- M include/osmocom/gsm/tlv.h M tests/tlv/tlv_test.c 2 files changed, 34 insertions(+), 2 deletions(-) git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/01/23401/1 diff --git a/include/osmocom/gsm/tlv.h b/include/osmocom/gsm/tlv.h index dc61de1..7e6dfb5 100644 --- a/include/osmocom/gsm/tlv.h +++ b/include/osmocom/gsm/tlv.h @@ -148,7 +148,7 @@ *buf++ = len >> 8; *buf++ = len & 0xff; memcpy(buf, val, len); - return buf + len*2; + return buf + len; } /*! put (append) a TL16 field. */ @@ -168,7 +168,7 @@ *buf++ = tag & 0xff; *buf++ = len; memcpy(buf, val, len); - return buf + len + 2; + return buf + len; } /*! put (append) a TvLV field */ diff --git a/tests/tlv/tlv_test.c b/tests/tlv/tlv_test.c index 3b4f441..fdd15ab 100644 --- a/tests/tlv/tlv_test.c +++ b/tests/tlv/tlv_test.c @@ -423,6 +423,37 @@ OSMO_ASSERT(TLVP_VAL(&dec, 0x23) == NULL); } +static void test_tlv_lens() +{ + uint16_t buf_len; + uint8_t buf[512]; + uint8_t val[512] = { 0 }; + uint16_t x; + + + for (x = 0; x < 16; x++) { + buf_len = lv_put(buf, x, val) - buf; + OSMO_ASSERT(buf_len == LV_GROSS_LEN(x)); + buf_len = tlv_put(buf, 0x23, x, val) - buf; + OSMO_ASSERT(buf_len == TLV_GROSS_LEN(x)); + buf_len = tlv16_put(buf, 0x23, x, (uint16_t *) val) - buf; + OSMO_ASSERT(buf_len == TLV16_GROSS_LEN(x)); + buf_len = tl16v_put(buf, 0x23, x, val) - buf; + OSMO_ASSERT(buf_len == TL16V_GROSS_LEN(x)); + buf_len = t16lv_put(buf, 0x2342, x, val) - buf; + OSMO_ASSERT(buf_len == T16LV_GROSS_LEN(x)); + buf_len = tvlv_put(buf, 0x23, x, val) - buf; + OSMO_ASSERT(buf_len == TVLV_GROSS_LEN(x)); + } + + for (x = 250; x < 300; x++) { + buf_len = tl16v_put(buf, 0x23, x, val) - buf; + OSMO_ASSERT(buf_len == TL16V_GROSS_LEN(x)); + buf_len = tvlv_put(buf, 0x23, x, val) - buf; + OSMO_ASSERT(buf_len == TVLV_GROSS_LEN(x)); + } +} + int main(int argc, char **argv) { //osmo_init_logging2(ctx, &info); @@ -431,6 +462,7 @@ test_tlv_repeated_ie(); test_tlv_encoder(); test_tlv_parser_bounds(); + test_tlv_lens(); printf("Done.\n"); return EXIT_SUCCESS; -- To view, visit https://gerrit.osmocom.org/c/libosmocore/+/23401 To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings Gerrit-Project: libosmocore Gerrit-Branch: master Gerrit-Change-Id: I268a7e11fb5dce67ce1bd7974ab86c4d2bd002f7 Gerrit-Change-Number: 23401 Gerrit-PatchSet: 1 Gerrit-Owner: daniel <dwillmann at sysmocom.de> Gerrit-MessageType: newchange -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210318/12ca65b1/attachment.htm>