aboutsummaryrefslogtreecommitdiff
path: root/src/pack_unpack.c
diff options
context:
space:
mode:
authorMaxim Zhukov <mussitantesmortem@gmail.com>2020-01-09 20:40:47 +0300
committerMaxim Zhukov <mussitantesmortem@gmail.com>2020-08-12 09:57:14 +0300
commitba4503804bb6605598ce43d5cbde9ce1fa735d4d (patch)
treeecbf3ef2353fb2c0dffd3eac0ab7c4ebca8a7b67 /src/pack_unpack.c
parent966f9cc20a45e68e150e26adc6fa84b4a7844767 (diff)
downloadjansson-ba4503804bb6605598ce43d5cbde9ce1fa735d4d.zip
jansson-ba4503804bb6605598ce43d5cbde9ce1fa735d4d.tar.gz
jansson-ba4503804bb6605598ce43d5cbde9ce1fa735d4d.tar.bz2
pass length of the key to internal API
Use key length for internal API Signed-off-by: Maxim Zhukov <mussitantesmortem@gmail.com>
Diffstat (limited to 'src/pack_unpack.c')
-rw-r--r--src/pack_unpack.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/pack_unpack.c b/src/pack_unpack.c
index a89be58..04c116e 100644
--- a/src/pack_unpack.c
+++ b/src/pack_unpack.c
@@ -544,7 +544,7 @@ static int unpack_object(scanner_t *s, json_t *root, va_list *ap) {
if (unpack(s, value, ap))
goto out;
- hashtable_set(&key_set, key, json_null());
+ hashtable_set(&key_set, key, strlen(key), json_null());
next_token(s);
}
@@ -554,6 +554,7 @@ static int unpack_object(scanner_t *s, json_t *root, va_list *ap) {
if (root && strict == 1) {
/* We need to check that all non optional items have been parsed */
const char *key;
+ size_t key_len;
/* keys_res is 1 for uninitialized, 0 for success, -1 for error. */
int keys_res = 1;
strbuffer_t unrecognized_keys;
@@ -562,7 +563,8 @@ static int unpack_object(scanner_t *s, json_t *root, va_list *ap) {
if (gotopt || json_object_size(root) != key_set.size) {
json_object_foreach(root, key, value) {
- if (!hashtable_get(&key_set, key)) {
+ key_len = strlen(key);
+ if (!hashtable_get(&key_set, key, key_len)) {
unpacked++;
/* Save unrecognized keys for the error message */
@@ -574,7 +576,7 @@ static int unpack_object(scanner_t *s, json_t *root, va_list *ap) {
if (!keys_res)
keys_res =
- strbuffer_append_bytes(&unrecognized_keys, key, strlen(key));
+ strbuffer_append_bytes(&unrecognized_keys, key, key_len);
}
}
}