]> git.kaiwu.me - klib.git/commitdiff
minor change
authorHeng Li <lh3@me.com>
Sun, 30 Nov 2014 01:35:28 +0000 (20:35 -0500)
committerHeng Li <lh3@me.com>
Sun, 30 Nov 2014 01:35:28 +0000 (20:35 -0500)
kson.h

diff --git a/kson.h b/kson.h
index 5555bfe86565f204c6acdbbc37226e11003ba2c2..861843369062eb477a92da34fe139989f063d0c0 100644 (file)
--- a/kson.h
+++ b/kson.h
@@ -58,6 +58,7 @@ extern "C" {
 static inline const kson_node_t *kson_by_key(const kson_node_t *p, const char *key)
 {
        long i;
+       if (p->type != KSON_TYPE_BRACE) return 0;
        for (i = 0; i < (long)p->n; ++i) {
                const kson_node_t *q = p->v.child[i];
                if (q->key && strcmp(q->key, key) == 0)
@@ -68,6 +69,7 @@ static inline const kson_node_t *kson_by_key(const kson_node_t *p, const char *k
 
 static inline const kson_node_t *kson_by_index(const kson_node_t *p, long i)
 {
+       if (p->type != KSON_TYPE_BRACKET) return 0;
        return 0 <= i && i < (long)p->n? p->v.child[i] : 0;
 }