intel / intel/tinycbor

Abstract reader/writer issue with non-contigous input data

Open
#250 3 comments 0 reactions 0 assignees View on GitHub
Dominant language
C
Stars
630
Forks
222
Avg merge
1d 3h
Merged PRs (30d)
1

Description

So I think this may be related to and/or covered by #208 , but I wanted to open an issue to report the specifics of what i am seeing.

I think the root of the issue is that in the structure `CborParserOperations` the function pointer `transfer_string` should advance the cursor but when calling `CborError cbor_value_copy_text_string(const CborValue *value, char *buffer, size_t *buflen, CborValue *next)` the cursor should be advanced for the output parameter `next` but *not advanced* in the in-out parameter `value`. I think the user data `token*` is shared between copies of `CborValue`.

I am working in an embedded system and transitioning some existing code to use a `struct netbuff` like structure instead of just copying around worst-case sized buffers. To do this i need to move all my code to work on iterators instead of just taking a `std::span` (we are on C++20). The iterators to this new structure are `bidirectional_iterator`, so no random access.

A simple (exposition only) example of the code that fails:
```
detail::ParserState cbor_parse;
CborValue it;
cbor_parse.init(data.begin(), data.end(), it);
CborValue it2;
char func_name_buff[10]{};
size_t name_len = 10;
if (!cbor_value_is_text_string(&it)) {
return BadValue;
}
if (auto err = cbor_value_copy_text_string(&it, func_name_buff, &name_len, &it2) != CborNoError) {
return err;
}
auto errr = cbor_value_advance(&it); // ERROR: CborErrorIllegalType
auto type = cbor_value_get_type(&it) // CborTextStringType, should be NullType after the advance
auto type2 = cbor_value_get_type(&it2) // CborNullType
```
I will work on getting a minimal reproducible example into compiler explorer, especially if this is a new case.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.