Comments (3)
Thanks for the report, this is indeed a bug.
It is caused by the nanocbor_skip
call that overwrites the res
value returned by the nanocbor_get_key_tstr
call. This means that if the final element of the map is skipped with nanocbor_skip
and the key is not found, the res
value is taken from the nanocbor_skip
call and returned.
I'll have a fix out asap
from nanocbor.
I have to check if I don't cause a regression here, but I think this patch should fix your issue:
diff --git a/src/decoder.c b/src/decoder.c
index 80e69f2..2fc2282 100644
--- a/src/decoder.c
+++ b/src/decoder.c
@@ -433,8 +433,9 @@ int nanocbor_get_key_tstr(nanocbor_value_t *start, const char *key,
const uint8_t *s = NULL;
size_t s_len = 0;
- if ((res = nanocbor_get_tstr(value, &s, &s_len)) < 0) {
- break;
+ int call_res = NANOCBOR_OK;
+ if ((call_res = nanocbor_get_tstr(value, &s, &s_len)) < 0) {
+ return call_res;
}
if (s_len == len && !strncmp(key, (const char *)s, len)) {
@@ -442,8 +443,8 @@ int nanocbor_get_key_tstr(nanocbor_value_t *start, const char *key,
break;
}
- if ((res = nanocbor_skip(value)) < 0) {
- break;
+ if ((call_res = nanocbor_skip(value)) < 0) {
+ return call_res;
}
}
from nanocbor.
Hi, I also stubbled upon the same issue.
Did you test for regression ?
from nanocbor.
Related Issues (10)
- Support double HOT 1
- Some operations are not 8/16 bit platform proof
- No support for indefinite array HOT 5
- nanocbor_enter_array() does not return NANOCBOR_OK on success HOT 1
- nanocbor_skip() doesn't work on nested structures HOT 3
- Wrong docstring for nanocbor_put_bstr
- automated and encode tests overlap?
- Pre-buffer offset?
- Error with the waspmote-pro board HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nanocbor.