Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zcbor.py: Fix range_checks for 'OTHER' type #375

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions tests/cases/corner_cases.cddl
Original file line number Diff line number Diff line change
Expand Up @@ -254,3 +254,8 @@ Uint64List = [
? uint64_lit: 0x0123456789abcdef,
* nint64_lit: -0x0123456789abcdef,
]

BstrSize = {
bstr12,
}
bstr12 = ("s" : bstr .size 12)
1 change: 1 addition & 0 deletions tests/decode/test5_corner_cases/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ set(py_command
Intmax2
InvalidIdentifiers
Uint64List
BstrSize
--decode
--git-sha-header
--short-names
Expand Down
20 changes: 20 additions & 0 deletions tests/decode/test5_corner_cases/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2103,4 +2103,24 @@ ZTEST(cbor_decode_test5, test_uint64_list)
}


ZTEST(cbor_decode_test5, test_bstr_size)
{
uint8_t bstr_size_payload1[] = {MAP(1),
0x61, 's',
0x4c, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55,
0x66, 0x77, 0x88, 0x99, 0xaa, 0xbb,
END
};

struct BstrSize result;
size_t num_decode;

zassert_equal(ZCBOR_SUCCESS, cbor_decode_BstrSize(bstr_size_payload1,
sizeof(bstr_size_payload1), &result, &num_decode), NULL);
zassert_equal(sizeof(bstr_size_payload1), num_decode, NULL);

zassert_equal(12, result.bstr12_m.s.len, NULL);
}


ZTEST_SUITE(cbor_decode_test5, NULL, NULL, NULL, NULL, NULL);
3 changes: 2 additions & 1 deletion zcbor/zcbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2389,7 +2389,8 @@ def range_checks(self, access):
if self.max_size is not None:
range_checks.append(f"({access}.len <= {self.max_size})")
elif self.type == "OTHER":
range_checks.extend(self.my_types[self.value].range_checks(access))
if not self.my_types[self.value].single_func_impl_condition():
range_checks.extend(self.my_types[self.value].range_checks(access))

if range_checks:
range_checks[0] = "((" + range_checks[0]
Expand Down