summaryrefslogtreecommitdiffhomepage
path: root/value.c
diff options
context:
space:
mode:
Diffstat (limited to 'value.c')
-rw-r--r--value.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/value.c b/value.c
index 18b7a5e..4312135 100644
--- a/value.c
+++ b/value.c
@@ -205,6 +205,7 @@ uc_getval(json_object *scope, json_object *key)
const char *k;
int64_t idx;
double d;
+ char *e;
if (json_object_is_type(scope, json_type_array)) {
/* only consider doubles with integer values as array keys */
@@ -216,13 +217,20 @@ uc_getval(json_object *scope, json_object *key)
else
idx = -1;
}
- else {
- errno = 0;
+ else if (json_object_is_type(key, json_type_int)) {
idx = json_object_get_int64(key);
+ }
+ else if (json_object_is_type(key, json_type_string)) {
+ errno = 0;
+ k = json_object_get_string(key);
+ idx = strtoll(k, &e, 0);
- if (errno != 0)
+ if (errno != 0 || e == k || *e != 0)
idx = -1;
}
+ else {
+ idx = -1;
+ }
if (idx >= 0 && idx < json_object_array_length(scope))
return json_object_get(json_object_array_get_idx(scope, idx));