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
| 1924 | * before the moment the tree is corrupted, to see what happens. |
| 1925 | */ |
| 1926 | unsigned long raxTouch(raxNode *n) { |
| 1927 | debugf("Touching %p\n", (void*)n); |
| 1928 | unsigned long sum = 0; |
| 1929 | if (n->iskey) { |
| 1930 | sum += (unsigned long)raxGetData(n); |
| 1931 | } |
| 1932 | |
| 1933 | int numchildren = n->iscompr ? 1 : n->size; |
| 1934 | raxNode **cp = raxNodeFirstChildPtr(n); |
| 1935 | int count = 0; |
| 1936 | for (int i = 0; i < numchildren; i++) { |
| 1937 | if (numchildren > 1) { |
| 1938 | sum += (long)n->data[i]; |
| 1939 | } |
| 1940 | raxNode *child; |
| 1941 | memcpy(&child,cp,sizeof(child)); |
| 1942 | if (child == (void*)0x65d1760) count++; |
| 1943 | if (count > 1) exit(1); |
| 1944 | sum += raxTouch(child); |
| 1945 | cp++; |
| 1946 | } |
| 1947 | return sum; |
| 1948 | } |
nothing calls this directly
no test coverage detected