MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / do_check_tree

Function do_check_tree

system/lib/dlmalloc.c:3382–3430  ·  view source on GitHub ↗

Check a tree and its subtrees. */

Source from the content-addressed store, hash-verified

3380
3381/* Check a tree and its subtrees. */
3382static void do_check_tree(mstate m, tchunkptr t) {
3383 tchunkptr head = 0;
3384 tchunkptr u = t;
3385 bindex_t tindex = t->index;
3386 size_t tsize = chunksize(t);
3387 bindex_t idx;
3388 compute_tree_index(tsize, idx);
3389 assert(tindex == idx);
3390 assert(tsize >= MIN_LARGE_SIZE);
3391 assert(tsize >= minsize_for_tree_index(idx));
3392 assert((idx == NTREEBINS-1) || (tsize < minsize_for_tree_index((idx+1))));
3393
3394 do { /* traverse through chain of same-sized nodes */
3395 do_check_any_chunk(m, ((mchunkptr)u));
3396 assert(u->index == tindex);
3397 assert(chunksize(u) == tsize);
3398 assert(!is_inuse(u));
3399 assert(!next_pinuse(u));
3400 assert(u->fd->bk == u);
3401 assert(u->bk->fd == u);
3402 if (u->parent == 0) {
3403 assert(u->child[0] == 0);
3404 assert(u->child[1] == 0);
3405 }
3406 else {
3407 assert(head == 0); /* only one node on chain has parent */
3408 head = u;
3409 assert(u->parent != u);
3410 assert (u->parent->child[0] == u ||
3411 u->parent->child[1] == u ||
3412 *((tbinptr*)(u->parent)) == u);
3413 if (u->child[0] != 0) {
3414 assert(u->child[0]->parent == u);
3415 assert(u->child[0] != u);
3416 do_check_tree(m, u->child[0]);
3417 }
3418 if (u->child[1] != 0) {
3419 assert(u->child[1]->parent == u);
3420 assert(u->child[1] != u);
3421 do_check_tree(m, u->child[1]);
3422 }
3423 if (u->child[0] != 0 && u->child[1] != 0) {
3424 assert(chunksize(u->child[0]) < chunksize(u->child[1]));
3425 }
3426 }
3427 u = u->fd;
3428 } while (u != t);
3429 assert(head != 0);
3430}
3431
3432/* Check all the chunks in a treebin. */
3433static void do_check_treebin(mstate m, bindex_t i) {

Callers 1

do_check_treebinFunction · 0.85

Calls 2

do_check_any_chunkFunction · 0.85
assertFunction · 0.50

Tested by

no test coverage detected