@@ -544,42 +544,50 @@ JsonNode *json_mkobject(void)
544
544
545
545
static void append_node (JsonNode *parent, JsonNode *child)
546
546
{
547
- child->parent = parent;
548
- child->prev = parent->children .tail ;
549
- child->next = NULL ;
550
-
551
- if (parent->children .tail != NULL )
552
- parent->children .tail ->next = child;
553
- else
554
- parent->children .head = child;
555
- parent->children .tail = child;
547
+ if (child != NULL && parent != NULL ) {
548
+ child->parent = parent;
549
+ child->prev = parent->children .tail ;
550
+ child->next = NULL ;
551
+
552
+ if (parent->children .tail != NULL )
553
+ parent->children .tail ->next = child;
554
+ else
555
+ parent->children .head = child;
556
+ parent->children .tail = child;
557
+ }
556
558
}
557
559
558
560
static void prepend_node (JsonNode *parent, JsonNode *child)
559
561
{
560
- child->parent = parent;
561
- child->prev = NULL ;
562
- child->next = parent->children .head ;
563
-
564
- if (parent->children .head != NULL )
565
- parent->children .head ->prev = child;
566
- else
567
- parent->children .tail = child;
568
- parent->children .head = child;
562
+ if (child != NULL && parent != NULL ) {
563
+ child->parent = parent;
564
+ child->prev = NULL ;
565
+ child->next = parent->children .head ;
566
+
567
+ if (parent->children .head != NULL )
568
+ parent->children .head ->prev = child;
569
+ else
570
+ parent->children .tail = child;
571
+ parent->children .head = child;
572
+ }
569
573
}
570
574
571
575
static void append_member (JsonNode *object, char *key, JsonNode *value)
572
576
{
573
- value->key = key;
574
- append_node (object, value);
577
+ if (value != NULL && object != NULL ) {
578
+ value->key = key;
579
+ append_node (object, value);
580
+ }
575
581
}
576
582
577
583
void json_append_element (JsonNode *array, JsonNode *element)
578
584
{
579
- assert (array->tag == JSON_ARRAY);
580
- assert (element->parent == NULL );
581
-
582
- append_node (array, element);
585
+ if (array != NULL && element !=NULL ) {
586
+ assert (array->tag == JSON_ARRAY);
587
+ assert (element->parent == NULL );
588
+
589
+ append_node (array, element);
590
+ }
583
591
}
584
592
585
593
void json_prepend_element (JsonNode *array, JsonNode *element)
@@ -592,40 +600,47 @@ void json_prepend_element(JsonNode *array, JsonNode *element)
592
600
593
601
void json_append_member (JsonNode *object, const char *key, JsonNode *value)
594
602
{
595
- assert (object->tag == JSON_OBJECT);
596
- assert (value->parent == NULL );
597
-
598
- append_member (object, json_strdup (key), value);
603
+ if (object != NULL && key != NULL && value != NULL ) {
604
+ assert (object->tag == JSON_OBJECT);
605
+ assert (value->parent == NULL );
606
+
607
+ append_member (object, json_strdup (key), value);
608
+ }
599
609
}
600
610
601
611
void json_prepend_member (JsonNode *object, const char *key, JsonNode *value)
602
612
{
603
- assert (object->tag == JSON_OBJECT);
604
- assert (value->parent == NULL );
605
-
606
- value->key = json_strdup (key);
607
- prepend_node (object, value);
613
+ if (object != NULL && key != NULL && value != NULL ) {
614
+ assert (object->tag == JSON_OBJECT);
615
+ assert (value->parent == NULL );
616
+
617
+ value->key = json_strdup (key);
618
+ prepend_node (object, value);
619
+ }
608
620
}
609
621
610
622
void json_remove_from_parent (JsonNode *node)
611
623
{
612
- JsonNode *parent = node->parent ;
613
-
614
- if (parent != NULL ) {
615
- if (node->prev != NULL )
616
- node->prev ->next = node->next ;
617
- else
618
- parent->children .head = node->next ;
619
- if (node->next != NULL )
620
- node->next ->prev = node->prev ;
621
- else
622
- parent->children .tail = node->prev ;
623
-
624
- free (node->key );
625
-
626
- node->parent = NULL ;
627
- node->prev = node->next = NULL ;
628
- node->key = NULL ;
624
+ if (node != NULL ) {
625
+ JsonNode *parent = node->parent ;
626
+
627
+ if (parent != NULL ) {
628
+ if (node->prev != NULL )
629
+ node->prev ->next = node->next ;
630
+ else
631
+ parent->children .head = node->next ;
632
+
633
+ if (node->next != NULL )
634
+ node->next ->prev = node->prev ;
635
+ else
636
+ parent->children .tail = node->prev ;
637
+
638
+ free (node->key );
639
+
640
+ node->parent = NULL ;
641
+ node->prev = node->next = NULL ;
642
+ node->key = NULL ;
643
+ }
629
644
}
630
645
}
631
646
0 commit comments