| 612 | } |
| 613 | |
| 614 | static cJSON_bool compare_json(cJSON *a, cJSON *b, const cJSON_bool case_sensitive) |
| 615 | { |
| 616 | if ((a == NULL) || (b == NULL) || ((a->type & 0xFF) != (b->type & 0xFF))) |
| 617 | { |
| 618 | /* mismatched type. */ |
| 619 | return false; |
| 620 | } |
| 621 | switch (a->type & 0xFF) |
| 622 | { |
| 623 | case cJSON_Number: |
| 624 | /* numeric mismatch. */ |
| 625 | if ((a->valueint != b->valueint) || (!compare_double(a->valuedouble, b->valuedouble))) |
| 626 | { |
| 627 | return false; |
| 628 | } |
| 629 | else |
| 630 | { |
| 631 | return true; |
| 632 | } |
| 633 | |
| 634 | case cJSON_String: |
| 635 | /* string mismatch. */ |
| 636 | if (strcmp(a->valuestring, b->valuestring) != 0) |
| 637 | { |
| 638 | return false; |
| 639 | } |
| 640 | else |
| 641 | { |
| 642 | return true; |
| 643 | } |
| 644 | |
| 645 | case cJSON_Array: |
| 646 | for ((void)(a = a->child), b = b->child; (a != NULL) && (b != NULL); (void)(a = a->next), b = b->next) |
| 647 | { |
| 648 | cJSON_bool identical = compare_json(a, b, case_sensitive); |
| 649 | if (!identical) |
| 650 | { |
| 651 | return false; |
| 652 | } |
| 653 | } |
| 654 | |
| 655 | /* array size mismatch? (one of both children is not NULL) */ |
| 656 | if ((a != NULL) || (b != NULL)) |
| 657 | { |
| 658 | return false; |
| 659 | } |
| 660 | else |
| 661 | { |
| 662 | return true; |
| 663 | } |
| 664 | |
| 665 | case cJSON_Object: |
| 666 | sort_object(a, case_sensitive); |
| 667 | sort_object(b, case_sensitive); |
| 668 | for ((void)(a = a->child), b = b->child; (a != NULL) && (b != NULL); (void)(a = a->next), b = b->next) |
| 669 | { |
| 670 | cJSON_bool identical = false; |
| 671 | /* compare object keys */ |
no test coverage detected