diff options
-rw-r--r-- | node.c | 23 | ||||
-rw-r--r-- | ted.c | 6 | ||||
-rw-r--r-- | ted.h | 2 |
3 files changed, 23 insertions, 8 deletions
@@ -89,7 +89,9 @@ void node_join(Ted *ted, Node *node) { arr_foreach_ptr(b->tabs, u16, tab) { arr_add(parent->tabs, *tab); } - if (parent->tabs) { + if (!parent->tabs) { + ted_out_of_mem(ted); + } else { if (node == a) { parent->active_tab = a->active_tab; } else { @@ -99,6 +101,9 @@ void node_join(Ted *ted, Node *node) { node_free(b); ted->nodes_used[parent->split_a] = false; ted->nodes_used[parent->split_b] = false; + // this isn't really needed since parent->tabs is not NULL anymore. + parent->split_a = 0; + parent->split_b = 0; } } } @@ -107,9 +112,14 @@ void node_join(Ted *ted, Node *node) { void node_close(Ted *ted, u16 node_idx) { ted->dragging_tab_node = NULL; ted->resizing_split = NULL; - - assert(node_idx < TED_MAX_NODES); - assert(ted->nodes_used[node_idx]); + if (node_idx >= TED_MAX_NODES) { + assert(0); + return; + } + if (!ted->nodes_used[node_idx]) { + assert(0); + return; + } i32 parent_idx = node_parent(ted, node_idx); ted->nodes_used[node_idx] = false; @@ -130,7 +140,10 @@ void node_close(Ted *ted, u16 node_idx) { } else { // turn parent from split node into tab node Node *parent = &ted->nodes[parent_idx]; - assert(!parent->tabs); + if (parent->tabs) { + assert(0); // this node's parent should be a split node + return; + } u16 other_side; if (node_idx == parent->split_a) { other_side = parent->split_b; @@ -52,7 +52,7 @@ void ted_clearerr(Ted *ted) { } -static void ted_out_of_mem(Ted *ted) { +void ted_out_of_mem(Ted *ted) { ted_seterr(ted, "Out of memory."); } @@ -599,8 +599,8 @@ void ted_cancel_lsp_request(Ted *ted, LSPID lsp, LSPRequestID request) { static void mark_node_reachable(Ted *ted, u16 node, bool reachable[TED_MAX_NODES]) { if (reachable[node]) { - ted_seterr(ted, "NODE CYCLE %u\nThis should never happen.", node); - ted_log(ted, "NODE CYCLE %u\n", node); + ted_seterr(ted, "Node %u reachable in 2 different ways\nThis should never happen.", node); + ted_log(ted, "Node %u reachable in 2 different ways\n", node); node_close(ted, node); return; } @@ -1038,6 +1038,8 @@ void die(PRINTF_FORMAT_STRING const char *fmt, ...) ATTRIBUTE_PRINTF(1, 2); void ted_seterr(Ted *ted, PRINTF_FORMAT_STRING const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3); // for information that should be logged void ted_log(Ted *ted, PRINTF_FORMAT_STRING const char *fmt, ...) ATTRIBUTE_PRINTF(2, 3); +// set error to "out of memory" message. +void ted_out_of_mem(Ted *ted); void *ted_malloc(Ted *ted, size_t size); void *ted_calloc(Ted *ted, size_t n, size_t size); void *ted_realloc(Ted *ted, void *p, size_t new_size); |