Touch all the nodes of a tree returning a check sum. This is useful * in order to make Valgrind detect if there is something wrong while * reading the data structure. * * This function was used in order to identify Rax bugs after a big refactoring * using this technique: * * 1. The rax-test is executed using Valgrind, adding a printf() so that for * the fuzz tester we see what iteration
| 2717 | * before the moment the tree is corrupted, to see what happens. |
| 2718 | */ |
| 2719 | unsigned long raxTouch(raxNode *n) { |
| 2720 | debugf("Touching %p\n", (void*)n); |
| 2721 | unsigned long sum = 0; |
| 2722 | if (n->iskey) { |
| 2723 | sum += (unsigned long)raxGetData(n); |
| 2724 | } |
| 2725 | |
| 2726 | int numchildren = n->iscompr ? 1 : n->size; |
| 2727 | raxNode **cp = raxNodeFirstChildPtr(n); |
| 2728 | int count = 0; |
| 2729 | for (int i = 0; i < numchildren; i++) { |
| 2730 | if (numchildren > 1) { |
| 2731 | sum += (long)n->data[i]; |
| 2732 | } |
| 2733 | if (raxIsInlineLeaf(n,i)) { |
| 2734 | void *val; |
| 2735 | memcpy(&val,cp,sizeof(val)); |
| 2736 | sum += (unsigned long)val; |
| 2737 | } else { |
| 2738 | raxNode *child; |
| 2739 | memcpy(&child,cp,sizeof(child)); |
| 2740 | if (child == (void*)0x65d1760) count++; |
| 2741 | if (count > 1) exit(1); |
| 2742 | sum += raxTouch(child); |
| 2743 | } |
| 2744 | cp++; |
| 2745 | } |
| 2746 | return sum; |
| 2747 | } |
nothing calls this directly
no test coverage detected