LLVMFuzzerTestOneInput:
   26|  1.59k|{
   27|  1.59k|	plist_t root_node = NULL;
   28|  1.59k|	plist_from_openstep(reinterpret_cast<const char*>(data), size, &root_node);
   29|  1.59k|	plist_free(root_node);
   30|       |
   31|  1.59k|	return 0;
   32|  1.59k|}

node_destroy:
   31|   298k|{
   32|   298k|	if(!node) return;
  ------------------
  |  Branch (32:5): [True: 0, False: 298k]
  ------------------
   33|       |
   34|   298k|	if (node->children && node->children->count > 0) {
  ------------------
  |  Branch (34:6): [True: 13.2k, False: 285k]
  |  Branch (34:24): [True: 0, False: 13.2k]
  ------------------
   35|      0|		node_t ch;
   36|      0|		while ((ch = node->children->begin)) {
  ------------------
  |  Branch (36:10): [True: 0, False: 0]
  ------------------
   37|      0|			node_list_remove(node->children, ch);
   38|      0|			node_destroy(ch);
   39|      0|		}
   40|      0|	}
   41|   298k|	node_list_destroy(node->children);
   42|   298k|	node->children = NULL;
   43|       |
   44|   298k|	free(node);
   45|   298k|}
node_create:
   48|   298k|{
   49|   298k|	int error = 0;
   50|       |
   51|   298k|	node_t node = (node_t)calloc(1, sizeof(struct node));
   52|   298k|	if (node == NULL) {
  ------------------
  |  Branch (52:6): [True: 0, False: 298k]
  ------------------
   53|      0|		return NULL;
   54|      0|	}
   55|       |
   56|   298k|	node->data = data;
   57|   298k|	node->next = NULL;
   58|   298k|	node->prev = NULL;
   59|   298k|	node->count = 0;
   60|   298k|	node->parent = NULL;
   61|   298k|	node->children = NULL;
   62|       |
   63|       |	// Pass NULL to create a root node
   64|   298k|	if (parent != NULL) {
  ------------------
  |  Branch (64:6): [True: 0, False: 298k]
  ------------------
   65|       |		// This is a child node so attach it to it's parent
   66|      0|		error = node_attach(parent, node);
   67|      0|		if (error < 0) {
  ------------------
  |  Branch (67:7): [True: 0, False: 0]
  ------------------
   68|       |			// Unable to attach nodes
   69|      0|			node_destroy(node);
   70|      0|			return NULL;
   71|      0|		}
   72|      0|	}
   73|       |
   74|   298k|	return node;
   75|   298k|}
node_attach:
  133|   201k|{
  134|   201k|	if (!parent || !child) return NODE_ERR_INVALID_ARG;
  ------------------
  |  |   36|      0|#define NODE_ERR_INVALID_ARG  -1
  ------------------
  |  Branch (134:6): [True: 0, False: 201k]
  |  Branch (134:17): [True: 0, False: 201k]
  ------------------
  135|       |
  136|       |	// already parented?
  137|   201k|	if (child->parent) return NODE_ERR_PARENT;
  ------------------
  |  |   38|      0|#define NODE_ERR_PARENT       -3
  ------------------
  |  Branch (137:6): [True: 0, False: 201k]
  ------------------
  138|       |
  139|       |	// self/cycle guard
  140|   201k|	if (parent == child) return NODE_ERR_CIRCULAR_REF;
  ------------------
  |  |   39|      0|#define NODE_ERR_CIRCULAR_REF -4
  ------------------
  |  Branch (140:6): [True: 0, False: 201k]
  ------------------
  141|   201k|	if (would_create_cycle(parent, child)) return NODE_ERR_CIRCULAR_REF;
  ------------------
  |  |   39|      0|#define NODE_ERR_CIRCULAR_REF -4
  ------------------
  |  Branch (141:6): [True: 0, False: 201k]
  ------------------
  142|       |
  143|       |	// depth guard: depth(parent)+1+max_depth(child_subtree) <= NODE_MAX_DEPTH
  144|   201k|	int pd = node_depth_from_root(parent);
  145|   201k|	int cd = node_subtree_max_depth(child);
  146|   201k|	if (pd + 1 + cd > NODE_MAX_DEPTH) {
  ------------------
  |  |   32|   201k|#define NODE_MAX_DEPTH 512
  ------------------
  |  Branch (146:6): [True: 0, False: 201k]
  ------------------
  147|      0|		return NODE_ERR_MAX_DEPTH;
  ------------------
  |  |   40|      0|#define NODE_ERR_MAX_DEPTH    -5
  ------------------
  148|      0|	}
  149|       |
  150|   201k|	if (!parent->children) {
  ------------------
  |  Branch (150:6): [True: 13.2k, False: 188k]
  ------------------
  151|  13.2k|		parent->children = node_list_create();
  152|  13.2k|		if (!parent->children) return NODE_ERR_NO_MEM;
  ------------------
  |  |   37|      0|#define NODE_ERR_NO_MEM       -2
  ------------------
  |  Branch (152:7): [True: 0, False: 13.2k]
  ------------------
  153|  13.2k|	}
  154|   201k|	int res = node_list_add(parent->children, child);
  155|   201k|	if (res == 0) {
  ------------------
  |  Branch (155:6): [True: 201k, False: 0]
  ------------------
  156|   201k|		child->parent = parent;
  157|   201k|		parent->count++;
  158|   201k|	}
  159|   201k|	return res;
  160|   201k|}
node_detach:
  163|   202k|{
  164|   202k|	if (!parent || !child) return NODE_ERR_INVALID_ARG;
  ------------------
  |  |   36|      0|#define NODE_ERR_INVALID_ARG  -1
  ------------------
  |  Branch (164:6): [True: 0, False: 202k]
  |  Branch (164:17): [True: 0, False: 202k]
  ------------------
  165|   202k|	if (!parent->children) return NODE_ERR_NOT_FOUND;
  ------------------
  |  |   41|      0|#define NODE_ERR_NOT_FOUND    -6
  ------------------
  |  Branch (165:6): [True: 0, False: 202k]
  ------------------
  166|   202k|	if (child->parent && child->parent != parent) return NODE_ERR_PARENT;
  ------------------
  |  |   38|      0|#define NODE_ERR_PARENT       -3
  ------------------
  |  Branch (166:6): [True: 202k, False: 0]
  |  Branch (166:23): [True: 0, False: 202k]
  ------------------
  167|       |
  168|   202k|	int node_index = node_list_remove(parent->children, child);
  169|   202k|	if (node_index >= 0) {
  ------------------
  |  Branch (169:6): [True: 202k, False: 0]
  ------------------
  170|   202k|		if (parent->count > 0) parent->count--;
  ------------------
  |  Branch (170:7): [True: 202k, False: 0]
  ------------------
  171|   202k|		child->parent = NULL;
  172|   202k|		child->prev = NULL;
  173|       |		child->next = NULL;
  174|   202k|	}
  175|   202k|	return node_index;
  176|   202k|}
node_insert:
  179|  1.35k|{
  180|  1.35k|	if (!parent || !child) return NODE_ERR_INVALID_ARG;
  ------------------
  |  |   36|      0|#define NODE_ERR_INVALID_ARG  -1
  ------------------
  |  Branch (180:6): [True: 0, False: 1.35k]
  |  Branch (180:17): [True: 0, False: 1.35k]
  ------------------
  181|       |
  182|       |	// already parented?
  183|  1.35k|	if (child->parent) return NODE_ERR_PARENT;
  ------------------
  |  |   38|      0|#define NODE_ERR_PARENT       -3
  ------------------
  |  Branch (183:6): [True: 0, False: 1.35k]
  ------------------
  184|       |
  185|       |	// self/cycle guard
  186|  1.35k|	if (parent == child) return NODE_ERR_CIRCULAR_REF;
  ------------------
  |  |   39|      0|#define NODE_ERR_CIRCULAR_REF -4
  ------------------
  |  Branch (186:6): [True: 0, False: 1.35k]
  ------------------
  187|  1.35k|	if (would_create_cycle(parent, child)) return NODE_ERR_CIRCULAR_REF;
  ------------------
  |  |   39|      0|#define NODE_ERR_CIRCULAR_REF -4
  ------------------
  |  Branch (187:6): [True: 0, False: 1.35k]
  ------------------
  188|       |
  189|       |	// depth guard: depth(parent)+1+max_depth(child_subtree) <= NODE_MAX_DEPTH
  190|  1.35k|	int pd = node_depth_from_root(parent);
  191|  1.35k|	int cd = node_subtree_max_depth(child);
  192|  1.35k|	if (pd + 1 + cd > NODE_MAX_DEPTH) {
  ------------------
  |  |   32|  1.35k|#define NODE_MAX_DEPTH 512
  ------------------
  |  Branch (192:6): [True: 0, False: 1.35k]
  ------------------
  193|      0|		return NODE_ERR_MAX_DEPTH;
  ------------------
  |  |   40|      0|#define NODE_ERR_MAX_DEPTH    -5
  ------------------
  194|      0|	}
  195|       |
  196|  1.35k|	if (!parent->children) {
  ------------------
  |  Branch (196:6): [True: 0, False: 1.35k]
  ------------------
  197|      0|		parent->children = node_list_create();
  198|      0|		if (!parent->children) return NODE_ERR_NO_MEM;
  ------------------
  |  |   37|      0|#define NODE_ERR_NO_MEM       -2
  ------------------
  |  Branch (198:7): [True: 0, False: 0]
  ------------------
  199|      0|	}
  200|  1.35k|	int res = node_list_insert(parent->children, node_index, child);
  201|  1.35k|	if (res == 0) {
  ------------------
  |  Branch (201:6): [True: 1.35k, False: 0]
  ------------------
  202|  1.35k|		child->parent = parent;
  203|  1.35k|		parent->count++;
  204|  1.35k|	}
  205|  1.35k|	return res;
  206|  1.35k|}
node_first_child:
  262|  2.89M|{
  263|  2.89M|	if (!node || !node->children) return NULL;
  ------------------
  |  Branch (263:6): [True: 0, False: 2.89M]
  |  Branch (263:15): [True: 285k, False: 2.61M]
  ------------------
  264|  2.61M|	return node->children->begin;
  265|  2.89M|}
node_prev_sibling:
  268|  1.35k|{
  269|  1.35k|	if (!node) return NULL;
  ------------------
  |  Branch (269:6): [True: 0, False: 1.35k]
  ------------------
  270|  1.35k|	return node->prev;
  271|  1.35k|}
node_next_sibling:
  274|  21.3M|{
  275|  21.3M|	if (!node) return NULL;
  ------------------
  |  Branch (275:6): [True: 0, False: 21.3M]
  ------------------
  276|  21.3M|	return node->next;
  277|  21.3M|}
node.c:would_create_cycle:
  124|   202k|{
  125|       |	// if parent is anywhere in child's ancestor chain => cycle
  126|   405k|	for (node_t p = parent; p; p = p->parent) {
  ------------------
  |  Branch (126:26): [True: 202k, False: 202k]
  ------------------
  127|   202k|		if (p == child) return 1;
  ------------------
  |  Branch (127:7): [True: 0, False: 202k]
  ------------------
  128|   202k|	}
  129|   202k|	return 0;
  130|   202k|}
node.c:node_depth_from_root:
   78|   202k|{
   79|   202k|	int d = 0;
   80|   202k|	while (n && n->parent) {
  ------------------
  |  Branch (80:9): [True: 202k, False: 0]
  |  Branch (80:14): [True: 0, False: 202k]
  ------------------
   81|      0|		d++;
   82|      0|		n = n->parent;
   83|      0|		if (d > NODE_MAX_DEPTH) return d; // early out
  ------------------
  |  |   32|      0|#define NODE_MAX_DEPTH 512
  ------------------
  |  Branch (83:7): [True: 0, False: 0]
  ------------------
   84|      0|	}
   85|   202k|	return d;
   86|   202k|}
node.c:node_subtree_max_depth:
   89|   202k|{
   90|   202k|	if (!root) return 0;
  ------------------
  |  Branch (90:6): [True: 0, False: 202k]
  ------------------
   91|       |
   92|   202k|	typedef struct { node_t n; int depth; } frame_t;
   93|   202k|	size_t cap = 64, sp = 0;
   94|   202k|	frame_t *st = (frame_t*)malloc(cap * sizeof(*st));
   95|   202k|	if (!st) return NODE_MAX_DEPTH + 1;
  ------------------
  |  |   32|      0|#define NODE_MAX_DEPTH 512
  ------------------
  |  Branch (95:6): [True: 0, False: 202k]
  ------------------
   96|       |
   97|   202k|	st[sp++] = (frame_t){ root, 0 };
   98|   202k|	int maxd = 0;
   99|       |
  100|  2.79M|	while (sp) {
  ------------------
  |  Branch (100:9): [True: 2.59M, False: 202k]
  ------------------
  101|  2.59M|		frame_t f = st[--sp];
  102|  2.59M|		if (f.depth > maxd) maxd = f.depth;
  ------------------
  |  Branch (102:7): [True: 2.31M, False: 271k]
  ------------------
  103|  2.59M|		if (maxd > NODE_MAX_DEPTH) break;
  ------------------
  |  |   32|  2.59M|#define NODE_MAX_DEPTH 512
  ------------------
  |  Branch (103:7): [True: 0, False: 2.59M]
  ------------------
  104|       |
  105|  2.59M|		if (!f.n->children) continue;
  ------------------
  |  Branch (105:7): [True: 271k, False: 2.31M]
  ------------------
  106|       |
  107|  4.70M|		for (node_t ch = node_first_child(f.n); ch; ch = node_next_sibling(ch)) {
  ------------------
  |  Branch (107:43): [True: 2.38M, False: 2.31M]
  ------------------
  108|  2.38M|			if (sp == cap) {
  ------------------
  |  Branch (108:8): [True: 370, False: 2.38M]
  ------------------
  109|    370|				cap *= 2;
  110|    370|				frame_t *tmp = (frame_t*)realloc(st, cap * sizeof(*st));
  111|    370|				if (!tmp) { maxd = NODE_MAX_DEPTH + 1; goto out; }
  ------------------
  |  |   32|      0|#define NODE_MAX_DEPTH 512
  ------------------
  |  Branch (111:9): [True: 0, False: 370]
  ------------------
  112|    370|				st = tmp;
  113|    370|			}
  114|  2.38M|			st[sp++] = (frame_t){ ch, f.depth + 1 };
  115|  2.38M|		}
  116|  2.31M|	}
  117|       |
  118|   202k|out:
  119|   202k|	free(st);
  120|   202k|	return maxd;
  121|   202k|}

node_list_destroy:
   32|   298k|{
   33|   298k|	free(list);
   34|   298k|}
node_list_create:
   37|  13.2k|{
   38|  13.2k|	node_list_t list = (node_list_t)calloc(1, sizeof(struct node_list));
   39|  13.2k|	if (list == NULL) {
  ------------------
  |  Branch (39:6): [True: 0, False: 13.2k]
  ------------------
   40|      0|		return NULL;
   41|      0|	}
   42|       |
   43|       |	// Initialize structure
   44|  13.2k|	list->begin = NULL;
   45|       |	list->end = NULL;
   46|  13.2k|	list->count = 0;
   47|  13.2k|	return list;
   48|  13.2k|}
node_list_add:
   51|   202k|{
   52|   202k|	if (!list || !node) return NODE_ERR_INVALID_ARG;
  ------------------
  |  |   36|      0|#define NODE_ERR_INVALID_ARG  -1
  ------------------
  |  Branch (52:6): [True: 0, False: 202k]
  |  Branch (52:15): [True: 0, False: 202k]
  ------------------
   53|       |
   54|       |	// Find the last element in the list
   55|   202k|	node_t last = list->end;
   56|       |
   57|       |	// Setup our new node as the new last element
   58|   202k|	node->next = NULL;
   59|   202k|	node->prev = last;
   60|       |
   61|       |	// Set the next element of our old "last" element
   62|   202k|	if (last) {
  ------------------
  |  Branch (62:6): [True: 188k, False: 13.2k]
  ------------------
   63|       |		// but only if the node list is not empty
   64|   188k|		last->next = node;
   65|   188k|	} else {
   66|       |		// otherwise this is the start of the list
   67|  13.2k|		list->begin = node;
   68|  13.2k|	}
   69|       |
   70|       |	// Set the lists prev to the new last element
   71|   202k|	list->end = node;
   72|       |
   73|       |	// Increment our node count for this list
   74|   202k|	list->count++;
   75|   202k|	return NODE_ERR_SUCCESS;
  ------------------
  |  |   35|   202k|#define NODE_ERR_SUCCESS       0
  ------------------
   76|   202k|}
node_list_insert:
   79|  1.35k|{
   80|  1.35k|	if (!list || !node) return NODE_ERR_INVALID_ARG;
  ------------------
  |  |   36|      0|#define NODE_ERR_INVALID_ARG  -1
  ------------------
  |  Branch (80:6): [True: 0, False: 1.35k]
  |  Branch (80:15): [True: 0, False: 1.35k]
  ------------------
   81|  1.35k|	if (node_index > list->count) return NODE_ERR_INVALID_ARG;
  ------------------
  |  |   36|      0|#define NODE_ERR_INVALID_ARG  -1
  ------------------
  |  Branch (81:6): [True: 0, False: 1.35k]
  ------------------
   82|  1.35k|	if (node_index == list->count) {
  ------------------
  |  Branch (82:6): [True: 418, False: 936]
  ------------------
   83|    418|		return node_list_add(list, node);
   84|    418|	}
   85|       |
   86|       |	// Get the first element in the list
   87|    936|	node_t cur = list->begin;
   88|    936|	node_t prev = NULL;
   89|       |
   90|   196k|	for (unsigned int pos = 0; pos < node_index; pos++) {
  ------------------
  |  Branch (90:29): [True: 195k, False: 936]
  ------------------
   91|   195k|		if (!cur) return NODE_ERR_INVALID_ARG;
  ------------------
  |  |   36|      0|#define NODE_ERR_INVALID_ARG  -1
  ------------------
  |  Branch (91:7): [True: 0, False: 195k]
  ------------------
   92|   195k|		prev = cur;
   93|   195k|		cur = cur->next;
   94|   195k|	}
   95|       |
   96|       |	// insert node before cur
   97|    936|	node->prev = prev;
   98|    936|	node->next = cur;
   99|       |
  100|    936|	if (prev) {
  ------------------
  |  Branch (100:6): [True: 936, False: 0]
  ------------------
  101|    936|		prev->next = node;
  102|    936|	} else {
  103|      0|		list->begin = node;
  104|      0|	}
  105|       |
  106|    936|	if (cur) {
  ------------------
  |  Branch (106:6): [True: 936, False: 0]
  ------------------
  107|    936|		cur->prev = node;
  108|    936|	} else {
  109|       |		// should not happen with bounds above, but keeps things consistent
  110|      0|		list->end = node;
  111|      0|	}
  112|       |
  113|       |	// Increment our node count for this list
  114|    936|	list->count++;
  115|    936|	return NODE_ERR_SUCCESS;
  ------------------
  |  |   35|    936|#define NODE_ERR_SUCCESS       0
  ------------------
  116|    936|}
node_list_remove:
  120|   202k|{
  121|   202k|	if (!list || !node) return NODE_ERR_INVALID_ARG;
  ------------------
  |  |   36|      0|#define NODE_ERR_INVALID_ARG  -1
  ------------------
  |  Branch (121:6): [True: 0, False: 202k]
  |  Branch (121:15): [True: 0, False: 202k]
  ------------------
  122|   202k|	if (list->count == 0) return NODE_ERR_NOT_FOUND;
  ------------------
  |  |   41|      0|#define NODE_ERR_NOT_FOUND    -6
  ------------------
  |  Branch (122:6): [True: 0, False: 202k]
  ------------------
  123|       |
  124|   202k|	int node_index = 0;
  125|   432k|	for (node_t n = list->begin; n; n = n->next, node_index++) {
  ------------------
  |  Branch (125:31): [True: 432k, False: 0]
  ------------------
  126|   432k|		if (node != n) continue;
  ------------------
  |  Branch (126:7): [True: 229k, False: 202k]
  ------------------
  127|       |
  128|   202k|		node_t newnode = node->next;
  129|   202k|		if (node->prev) {
  ------------------
  |  Branch (129:7): [True: 1.35k, False: 201k]
  ------------------
  130|  1.35k|			node->prev->next = newnode;
  131|   201k|		} else {
  132|       |			// we just removed the first element
  133|   201k|			list->begin = newnode;
  134|   201k|		}
  135|       |
  136|   202k|		if (newnode) {
  ------------------
  |  Branch (136:7): [True: 189k, False: 13.6k]
  ------------------
  137|   189k|			newnode->prev = node->prev;
  138|   189k|		} else {
  139|       |			// we removed the last element, set new end
  140|  13.6k|			list->end = node->prev;
  141|  13.6k|		}
  142|       |
  143|       |		// fully detach node from list
  144|   202k|		node->prev = NULL;
  145|   202k|		node->next = NULL;
  146|       |
  147|   202k|		list->count--;
  148|   202k|		return node_index;
  149|   432k|	}
  150|      0|	return NODE_ERR_NOT_FOUND;
  ------------------
  |  |   41|      0|#define NODE_ERR_NOT_FOUND    -6
  ------------------
  151|   202k|}

plist_bin_init:
  287|      2|{
  288|       |    /* init binary plist stuff */
  289|      2|#ifdef DEBUG
  290|      2|    char *env_debug = getenv("PLIST_BIN_DEBUG");
  291|      2|    if (env_debug && !strcmp(env_debug, "1")) {
  ------------------
  |  Branch (291:9): [True: 0, False: 2]
  |  Branch (291:22): [True: 0, False: 0]
  ------------------
  292|      0|        plist_bin_debug = 1;
  293|      0|    }
  294|      2|#endif
  295|      2|}

byte_array_new:
   28|    314|{
   29|    314|	bytearray_t *a = (bytearray_t*)malloc(sizeof(bytearray_t));
   30|    314|	if (!a) {
  ------------------
  |  Branch (30:6): [True: 0, False: 314]
  ------------------
   31|      0|		return NULL;
   32|      0|	}
   33|    314|	if (initial > PAGE_SIZE) {
  ------------------
  |  |   25|    314|#define PAGE_SIZE 4096
  ------------------
  |  Branch (33:6): [True: 0, False: 314]
  ------------------
   34|      0|		if (initial > SIZE_MAX - (PAGE_SIZE-1)) {
  ------------------
  |  |   25|      0|#define PAGE_SIZE 4096
  ------------------
  |  Branch (34:7): [True: 0, False: 0]
  ------------------
   35|       |			/* rounding up to the page size would overflow */
   36|      0|			free(a);
   37|      0|			return NULL;
   38|      0|		}
   39|      0|		a->capacity = (initial+(PAGE_SIZE-1)) & (~(PAGE_SIZE-1));
  ------------------
  |  |   25|      0|#define PAGE_SIZE 4096
  ------------------
              		a->capacity = (initial+(PAGE_SIZE-1)) & (~(PAGE_SIZE-1));
  ------------------
  |  |   25|      0|#define PAGE_SIZE 4096
  ------------------
   40|    314|	} else {
   41|    314|		a->capacity = PAGE_SIZE;
  ------------------
  |  |   25|    314|#define PAGE_SIZE 4096
  ------------------
   42|    314|	}
   43|    314|	a->data = malloc(a->capacity);
   44|    314|	if (!a->data) {
  ------------------
  |  Branch (44:6): [True: 0, False: 314]
  ------------------
   45|      0|		free(a);
   46|      0|		return NULL;
   47|      0|	}
   48|    314|	a->len = 0;
   49|       |	a->stream = NULL;
   50|    314|	return a;
   51|    314|}
byte_array_free:
   67|    314|{
   68|    314|	if (!ba) return;
  ------------------
  |  Branch (68:6): [True: 0, False: 314]
  ------------------
   69|    314|	if (ba->data) {
  ------------------
  |  Branch (69:6): [True: 71, False: 243]
  ------------------
   70|     71|		free(ba->data);
   71|     71|	}
   72|    314|	free(ba);
   73|    314|}
byte_array_append:
  121|  6.57k|{
  122|  6.57k|	if (!ba || (!ba->stream && !ba->data) || (len <= 0)) return;
  ------------------
  |  Branch (122:6): [True: 0, False: 6.57k]
  |  Branch (122:14): [True: 6.57k, False: 0]
  |  Branch (122:29): [True: 0, False: 6.57k]
  |  Branch (122:43): [True: 0, False: 6.57k]
  ------------------
  123|  6.57k|	if (ba->stream) {
  ------------------
  |  Branch (123:6): [True: 0, False: 6.57k]
  ------------------
  124|      0|		if (fwrite(buf, 1, len, ba->stream) < len) {
  ------------------
  |  Branch (124:7): [True: 0, False: 0]
  ------------------
  125|       |#if DEBUG
  126|       |			fprintf(stderr, "ERROR: Failed to write to stream.\n");
  127|       |#endif
  128|      0|		}
  129|  6.57k|	} else {
  130|  6.57k|		if (len > SIZE_MAX - ba->len) {
  ------------------
  |  Branch (130:7): [True: 0, False: 6.57k]
  ------------------
  131|       |			/* integer overflow when computing the new total length */
  132|      0|			return;
  133|      0|		}
  134|  6.57k|		size_t remaining = ba->capacity-ba->len;
  135|  6.57k|		if (len > remaining) {
  ------------------
  |  Branch (135:7): [True: 0, False: 6.57k]
  ------------------
  136|      0|			size_t needed = len - remaining;
  137|      0|			byte_array_grow(ba, needed);
  138|      0|			if (!ba->data) {
  ------------------
  |  Branch (138:8): [True: 0, False: 0]
  ------------------
  139|      0|				return;
  140|      0|			}
  141|      0|		}
  142|  6.57k|		memcpy(((char*)ba->data) + ba->len, buf, len);
  143|  6.57k|	}
  144|  6.57k|	ba->len += len;
  145|  6.57k|}

hash_table_new:
   24|    292|{
   25|    292|	hashtable_t* ht = (hashtable_t*)malloc(sizeof(hashtable_t));
   26|    292|	int i;
   27|    292|	if (!ht) {
  ------------------
  |  Branch (27:6): [True: 0, False: 292]
  ------------------
   28|      0|		return NULL;
   29|      0|	}
   30|  1.19M|	for (i = 0; i < 4096; i++) {
  ------------------
  |  Branch (30:14): [True: 1.19M, False: 292]
  ------------------
   31|       |		ht->entries[i] = NULL;
   32|  1.19M|	}
   33|    292|	ht->count = 0;
   34|    292|	ht->hash_func = hash_func;
   35|    292|	ht->compare_func = compare_func;
   36|    292|	ht->free_func = free_func;
   37|    292|	return ht;
   38|    292|}
hash_table_destroy:
   41|  17.5k|{
   42|  17.5k|	if (!ht) return;
  ------------------
  |  Branch (42:6): [True: 17.2k, False: 292]
  ------------------
   43|       |
   44|    292|	int i = 0;
   45|  1.19M|	for (i = 0; i < 4096; i++) {
  ------------------
  |  Branch (45:14): [True: 1.19M, False: 292]
  ------------------
   46|  1.19M|		if (ht->entries[i]) {
  ------------------
  |  Branch (46:7): [True: 72.1k, False: 1.12M]
  ------------------
   47|  72.1k|			hashentry_t* e = ht->entries[i];
   48|   145k|			while (e) {
  ------------------
  |  Branch (48:11): [True: 73.8k, False: 72.1k]
  ------------------
   49|  73.8k|				if (ht->free_func) {
  ------------------
  |  Branch (49:9): [True: 0, False: 73.8k]
  ------------------
   50|      0|					ht->free_func(e->value);
   51|      0|				}
   52|  73.8k|				hashentry_t* old = e;
   53|  73.8k|				e = e->next;
   54|  73.8k|				free(old);
   55|  73.8k|			}
   56|  72.1k|		}
   57|  1.19M|	}
   58|    292|	free(ht);
   59|    292|}
hash_table_insert:
   62|  74.4k|{
   63|  74.4k|	if (!ht || !key) return -1;
  ------------------
  |  Branch (63:6): [True: 0, False: 74.4k]
  |  Branch (63:13): [True: 0, False: 74.4k]
  ------------------
   64|       |
   65|  74.4k|	unsigned int hash = ht->hash_func(key);
   66|       |
   67|  74.4k|	int idx0 = hash & 0xFFF;
   68|       |
   69|       |	// get the idx0 list
   70|  74.4k|	hashentry_t* e = ht->entries[idx0];
   71|  76.7k|	while (e) {
  ------------------
  |  Branch (71:9): [True: 2.90k, False: 73.8k]
  ------------------
   72|  2.90k|		if (ht->compare_func(e->key, key)) {
  ------------------
  |  Branch (72:7): [True: 630, False: 2.27k]
  ------------------
   73|       |			// element already present. replace value.
   74|    630|			e->value = value;
   75|    630|			return 0;
   76|    630|		}
   77|  2.27k|		e = e->next;
   78|  2.27k|	}
   79|       |
   80|       |	// if we get here, the element is not yet in the list.
   81|       |
   82|       |	// make a new entry.
   83|  73.8k|	hashentry_t* entry = (hashentry_t*)malloc(sizeof(hashentry_t));
   84|  73.8k|	if (!entry) {
  ------------------
  |  Branch (84:6): [True: 0, False: 73.8k]
  ------------------
   85|      0|		return -1;
   86|      0|	}
   87|  73.8k|	entry->key = key;
   88|  73.8k|	entry->value = value;
   89|  73.8k|	if (!ht->entries[idx0]) {
  ------------------
  |  Branch (89:6): [True: 72.1k, False: 1.61k]
  ------------------
   90|       |		// first entry
   91|  72.1k|		entry->next = NULL;
   92|  72.1k|	} else {
   93|       |		// add to list
   94|  1.61k|		entry->next = ht->entries[idx0];
   95|  1.61k|	}
   96|  73.8k|	ht->entries[idx0] = entry;
   97|  73.8k|	ht->count++;
   98|  73.8k|	return 0;
   99|  73.8k|}
hash_table_lookup:
  102|  1.14k|{
  103|  1.14k|	if (!ht || !key) return NULL;
  ------------------
  |  Branch (103:6): [True: 0, False: 1.14k]
  |  Branch (103:13): [True: 0, False: 1.14k]
  ------------------
  104|  1.14k|	unsigned int hash = ht->hash_func(key);
  105|       |
  106|  1.14k|	int idx0 = hash & 0xFFF;
  107|       |
  108|  1.14k|	hashentry_t* e = ht->entries[idx0];
  109|  1.68k|	while (e) {
  ------------------
  |  Branch (109:9): [True: 1.17k, False: 512]
  ------------------
  110|  1.17k|		if (ht->compare_func(e->key, key)) {
  ------------------
  |  Branch (110:7): [True: 630, False: 542]
  ------------------
  111|    630|			return e->value;
  112|    630|		}
  113|    542|		e = e->next;
  114|    542|	}
  115|    512|	return NULL;
  116|  1.14k|}

plist_json_init:
   56|      2|{
   57|       |    /* init JSON stuff */
   58|      2|#ifdef DEBUG
   59|      2|    char *env_debug = getenv("PLIST_JSON_DEBUG");
   60|      2|    if (env_debug && !strcmp(env_debug, "1")) {
  ------------------
  |  Branch (60:9): [True: 0, False: 2]
  |  Branch (60:22): [True: 0, False: 0]
  ------------------
   61|      0|        plist_json_debug = 1;
   62|      0|    }
   63|      2|#endif
   64|      2|}

plist_ostep_init:
   54|      2|{
   55|       |    /* init OpenStep stuff */
   56|      2|#ifdef DEBUG
   57|      2|    char *env_debug = getenv("PLIST_OSTEP_DEBUG");
   58|      2|    if (env_debug && !strcmp(env_debug, "1")) {
  ------------------
  |  Branch (58:9): [True: 0, False: 2]
  |  Branch (58:22): [True: 0, False: 0]
  ------------------
   59|      0|        plist_ostep_debug = 1;
   60|      0|    }
   61|      2|#endif
   62|      2|}
plist_from_openstep:
 1037|  1.59k|{
 1038|  1.59k|    if (!plist) {
  ------------------
  |  Branch (1038:9): [True: 0, False: 1.59k]
  ------------------
 1039|      0|        return PLIST_ERR_INVALID_ARG;
 1040|      0|    }
 1041|  1.59k|    *plist = NULL;
 1042|  1.59k|    if (!plist_ostep || (length == 0)) {
  ------------------
  |  Branch (1042:9): [True: 0, False: 1.59k]
  |  Branch (1042:25): [True: 0, False: 1.59k]
  ------------------
 1043|      0|        return PLIST_ERR_INVALID_ARG;
 1044|      0|    }
 1045|       |
 1046|  1.59k|    struct _parse_ctx ctx = { plist_ostep, plist_ostep, plist_ostep + length, 0 , 0 };
 1047|       |
 1048|  1.59k|    plist_err_t err = node_from_openstep(&ctx, plist);
 1049|  1.59k|    if (err == 0) {
  ------------------
  |  Branch (1049:9): [True: 1.11k, False: 482]
  ------------------
 1050|  1.11k|        if (!*plist) {
  ------------------
  |  Branch (1050:13): [True: 61, False: 1.05k]
  ------------------
 1051|       |            /* whitespace only file is considered an empty dictionary */
 1052|     61|            *plist = plist_new_dict();
 1053|     61|            if (!*plist) {
  ------------------
  |  Branch (1053:17): [True: 0, False: 61]
  ------------------
 1054|      0|                err = PLIST_ERR_NO_MEM;
 1055|      0|            }
 1056|  1.05k|        } else if (ctx.pos < ctx.end && *ctx.pos == '=') {
  ------------------
  |  Branch (1056:20): [True: 882, False: 173]
  |  Branch (1056:41): [True: 869, False: 13]
  ------------------
 1057|       |            /* attempt to parse this as 'strings' data */
 1058|    869|            plist_free(*plist);
 1059|    869|            *plist = NULL;
 1060|    869|            plist_t pl = plist_new_dict();
 1061|    869|            if (!pl) {
  ------------------
  |  Branch (1061:17): [True: 0, False: 869]
  ------------------
 1062|      0|                return PLIST_ERR_NO_MEM;
 1063|      0|            }
 1064|    869|            ctx.pos = plist_ostep;
 1065|    869|            parse_dict_data(&ctx, pl);
 1066|    869|            if (ctx.err != PLIST_ERR_SUCCESS) {
  ------------------
  |  Branch (1066:17): [True: 540, False: 329]
  ------------------
 1067|    540|                plist_free(pl);
 1068|    540|                PLIST_OSTEP_ERR("Failed to parse strings data\n");
  ------------------
  |  |   46|    540|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 540]
  |  |  ------------------
  ------------------
 1069|    540|                err = ctx.err;
 1070|    540|            } else {
 1071|    329|                *plist = pl;
 1072|    329|            }
 1073|    869|        }
 1074|  1.11k|    }
 1075|       |
 1076|  1.59k|    return err;
 1077|  1.59k|}
oplist.c:node_from_openstep:
  684|   220k|{
  685|   220k|    plist_t subnode = NULL;
  686|   220k|    const char *p = NULL;
  687|   220k|    ctx->depth++;
  688|   220k|    if (ctx->depth > PLIST_MAX_NESTING_DEPTH) {
  ------------------
  |  |   68|   220k|#define PLIST_MAX_NESTING_DEPTH NODE_MAX_DEPTH
  |  |  ------------------
  |  |  |  |   32|   220k|#define NODE_MAX_DEPTH 512
  |  |  ------------------
  ------------------
  |  Branch (688:9): [True: 4, False: 220k]
  ------------------
  689|      4|        PLIST_OSTEP_ERR("Too many levels of recursion (%u) at offset %ld\n", ctx->depth, (long int)(ctx->pos - ctx->start));
  ------------------
  |  |   46|      4|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 4]
  |  |  ------------------
  ------------------
  690|      4|        ctx->err = PLIST_ERR_MAX_NESTING;
  691|      4|        return ctx->err;
  692|      4|    }
  693|   220k|    while (ctx->pos < ctx->end && !ctx->err) {
  ------------------
  |  Branch (693:12): [True: 220k, False: 0]
  |  Branch (693:35): [True: 220k, False: 0]
  ------------------
  694|   220k|        parse_skip_ws(ctx);
  695|   220k|        if (ctx->pos >= ctx->end) {
  ------------------
  |  Branch (695:13): [True: 67, False: 220k]
  ------------------
  696|     67|            break;
  697|     67|        }
  698|   220k|        plist_data_t data = plist_new_plist_data();
  699|   220k|        if (!data) {
  ------------------
  |  Branch (699:13): [True: 0, False: 220k]
  ------------------
  700|      0|            PLIST_OSTEP_ERR("Out of memory\n");
  ------------------
  |  |   46|      0|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  701|      0|            ctx->err = PLIST_ERR_NO_MEM;
  702|      0|            goto err_out;
  703|      0|        }
  704|   220k|        if (*ctx->pos == '{') {
  ------------------
  |  Branch (704:13): [True: 16.5k, False: 203k]
  ------------------
  705|  16.5k|            data->type = PLIST_DICT;
  706|  16.5k|            subnode = plist_new_node(data);
  707|  16.5k|            if (!subnode) {
  ------------------
  |  Branch (707:17): [True: 0, False: 16.5k]
  ------------------
  708|      0|                plist_free_data(data);
  709|      0|                PLIST_OSTEP_ERR("Out of memory\n");
  ------------------
  |  |   46|      0|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  710|      0|                ctx->err = PLIST_ERR_NO_MEM;
  711|      0|                goto err_out;
  712|      0|            }
  713|  16.5k|            ctx->pos++;
  714|  16.5k|            parse_dict_data(ctx, subnode);
  715|  16.5k|            if (ctx->err) {
  ------------------
  |  Branch (715:17): [True: 11.1k, False: 5.38k]
  ------------------
  716|  11.1k|                goto err_out;
  717|  11.1k|            }
  718|  5.38k|            if (ctx->pos >= ctx->end) {
  ------------------
  |  Branch (718:17): [True: 79, False: 5.30k]
  ------------------
  719|     79|                PLIST_OSTEP_ERR("EOF while parsing dictionary terminator '}' at offset %ld\n", (long int)(ctx->pos - ctx->start));
  ------------------
  |  |   46|     79|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 79]
  |  |  ------------------
  ------------------
  720|     79|                ctx->err = PLIST_ERR_PARSE;
  721|     79|                break;
  722|     79|            }
  723|  5.30k|            if (*ctx->pos != '}') {
  ------------------
  |  Branch (723:17): [True: 0, False: 5.30k]
  ------------------
  724|      0|                PLIST_OSTEP_ERR("Missing terminating '}' at offset %ld\n", (long int)(ctx->pos - ctx->start));
  ------------------
  |  |   46|      0|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  725|      0|                ctx->err = PLIST_ERR_PARSE;
  726|      0|                goto err_out;
  727|      0|            }
  728|  5.30k|            ctx->pos++;
  729|  5.30k|            *plist = subnode;
  730|  5.30k|            parse_skip_ws(ctx);
  731|  5.30k|            break;
  732|   203k|        } else if (*ctx->pos == '(') {
  ------------------
  |  Branch (732:20): [True: 15.5k, False: 188k]
  ------------------
  733|  15.5k|            data->type = PLIST_ARRAY;
  734|  15.5k|            subnode = plist_new_node(data);
  735|  15.5k|            if (!subnode) {
  ------------------
  |  Branch (735:17): [True: 0, False: 15.5k]
  ------------------
  736|      0|                plist_free_data(data);
  737|      0|                PLIST_OSTEP_ERR("Out of memory\n");
  ------------------
  |  |   46|      0|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  738|      0|                ctx->err = PLIST_ERR_NO_MEM;
  739|      0|                goto err_out;
  740|      0|            }
  741|  15.5k|            ctx->pos++;
  742|  15.5k|            plist_t tmp = NULL;
  743|  50.2k|            while (ctx->pos < ctx->end && !ctx->err) {
  ------------------
  |  Branch (743:20): [True: 50.1k, False: 22]
  |  Branch (743:43): [True: 50.1k, False: 0]
  ------------------
  744|  50.1k|                parse_skip_ws(ctx);
  745|  50.1k|                if (ctx->pos >= ctx->end || *ctx->pos == ')') {
  ------------------
  |  Branch (745:21): [True: 1, False: 50.1k]
  |  Branch (745:45): [True: 342, False: 49.8k]
  ------------------
  746|    343|                    break;
  747|    343|                }
  748|  49.8k|                ctx->err = node_from_openstep(ctx, &tmp);
  749|  49.8k|                if (ctx->err != PLIST_ERR_SUCCESS) {
  ------------------
  |  Branch (749:21): [True: 2.74k, False: 47.0k]
  ------------------
  750|  2.74k|                    break;
  751|  2.74k|                }
  752|  47.0k|                if (!tmp) {
  ------------------
  |  Branch (752:21): [True: 1, False: 47.0k]
  ------------------
  753|      1|                    ctx->err = PLIST_ERR_PARSE;
  754|      1|                    break;
  755|      1|                }
  756|  47.0k|                if (plist_array_append_item(subnode, tmp) != PLIST_ERR_SUCCESS) {
  ------------------
  |  Branch (756:21): [True: 0, False: 47.0k]
  ------------------
  757|      0|                    ctx->err = PLIST_ERR_NO_MEM;
  758|      0|                    break;
  759|      0|                }
  760|  47.0k|                tmp = NULL;
  761|  47.0k|                parse_skip_ws(ctx);
  762|  47.0k|                if (ctx->pos >= ctx->end) {
  ------------------
  |  Branch (762:21): [True: 100, False: 46.9k]
  ------------------
  763|    100|                    PLIST_OSTEP_ERR("EOF while parsing array item delimiter ',' at offset %ld\n", (long int)(ctx->pos - ctx->start));
  ------------------
  |  |   46|    100|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 100]
  |  |  ------------------
  ------------------
  764|    100|                    ctx->err = PLIST_ERR_PARSE;
  765|    100|                    break;
  766|    100|                }
  767|  46.9k|                if (*ctx->pos != ',') {
  ------------------
  |  Branch (767:21): [True: 12.3k, False: 34.6k]
  ------------------
  768|  12.3k|                    break;
  769|  12.3k|                }
  770|  34.6k|                ctx->pos++;
  771|  34.6k|            }
  772|  15.5k|	    plist_free(tmp);
  773|  15.5k|	    tmp = NULL;
  774|  15.5k|            if (ctx->err != PLIST_ERR_SUCCESS) {
  ------------------
  |  Branch (774:17): [True: 2.84k, False: 12.6k]
  ------------------
  775|  2.84k|                goto err_out;
  776|  2.84k|            }
  777|  12.6k|            if (ctx->pos >= ctx->end) {
  ------------------
  |  Branch (777:17): [True: 23, False: 12.6k]
  ------------------
  778|     23|                PLIST_OSTEP_ERR("EOF while parsing array terminator ')' at offset %ld\n", (long int)(ctx->pos - ctx->start));
  ------------------
  |  |   46|     23|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 23]
  |  |  ------------------
  ------------------
  779|     23|                ctx->err = PLIST_ERR_PARSE;
  780|     23|                break;
  781|     23|            }
  782|  12.6k|            if (*ctx->pos != ')') {
  ------------------
  |  Branch (782:17): [True: 14, False: 12.6k]
  ------------------
  783|     14|                PLIST_OSTEP_ERR("Missing terminating ')' at offset %ld\n", (long int)(ctx->pos - ctx->start));
  ------------------
  |  |   46|     14|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 14]
  |  |  ------------------
  ------------------
  784|     14|                ctx->err = PLIST_ERR_PARSE;
  785|     14|                goto err_out;
  786|     14|            }
  787|  12.6k|            ctx->pos++;
  788|  12.6k|            *plist = subnode;
  789|  12.6k|            parse_skip_ws(ctx);
  790|  12.6k|            break;
  791|   188k|        } else if (*ctx->pos == '<') {
  ------------------
  |  Branch (791:20): [True: 314, False: 188k]
  ------------------
  792|    314|            data->type = PLIST_DATA;
  793|    314|            ctx->pos++;
  794|    314|            bytearray_t *bytes = byte_array_new(256);
  795|    314|            if (!bytes) {
  ------------------
  |  Branch (795:17): [True: 0, False: 314]
  ------------------
  796|      0|                plist_free_data(data);
  797|      0|                PLIST_OSTEP_ERR("Out of memory\n");
  ------------------
  |  |   46|      0|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  798|      0|                ctx->err = PLIST_ERR_NO_MEM;
  799|      0|                goto err_out;
  800|      0|            }
  801|  6.88k|            while (ctx->pos < ctx->end && !ctx->err) {
  ------------------
  |  Branch (801:20): [True: 6.84k, False: 42]
  |  Branch (801:43): [True: 6.84k, False: 0]
  ------------------
  802|  6.84k|                parse_skip_ws(ctx);
  803|  6.84k|                if (ctx->pos >= ctx->end) {
  ------------------
  |  Branch (803:21): [True: 1, False: 6.84k]
  ------------------
  804|      1|                    PLIST_OSTEP_ERR("EOF while parsing data terminator '>' at offset %ld\n", (long int)(ctx->pos - ctx->start));
  ------------------
  |  |   46|      1|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 1]
  |  |  ------------------
  ------------------
  805|      1|                    ctx->err = PLIST_ERR_PARSE;
  806|      1|                    break;
  807|      1|                }
  808|  6.84k|                if (*ctx->pos == '>') {
  ------------------
  |  Branch (808:21): [True: 243, False: 6.60k]
  ------------------
  809|    243|                    break;
  810|    243|                }
  811|  6.60k|                if (!isxdigit(*ctx->pos)) {
  ------------------
  |  Branch (811:21): [True: 7, False: 6.59k]
  ------------------
  812|      7|                    PLIST_OSTEP_ERR("Invalid byte group in data at offset %ld\n", (long int)(ctx->pos - ctx->start));
  ------------------
  |  |   46|      7|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 7]
  |  |  ------------------
  ------------------
  813|      7|                    ctx->err = PLIST_ERR_PARSE;
  814|      7|                    break;
  815|      7|                }
  816|  6.59k|                uint8_t b = HEX_DIGIT(*ctx->pos);
  ------------------
  |  |  607|  6.59k|#define HEX_DIGIT(x) ((x <= '9') ? (x - '0') : ((x <= 'F') ? (x - 'A' + 10) : (x - 'a' + 10)))
  |  |  ------------------
  |  |  |  Branch (607:23): [True: 2.66k, False: 3.92k]
  |  |  |  Branch (607:49): [True: 1.08k, False: 2.84k]
  |  |  ------------------
  ------------------
  817|  6.59k|                ctx->pos++;
  818|  6.59k|                if (ctx->pos >= ctx->end) {
  ------------------
  |  Branch (818:21): [True: 18, False: 6.57k]
  ------------------
  819|     18|                    PLIST_OSTEP_ERR("Unexpected end of data at offset %ld\n", (long int)(ctx->pos - ctx->start));
  ------------------
  |  |   46|     18|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 18]
  |  |  ------------------
  ------------------
  820|     18|                    ctx->err = PLIST_ERR_PARSE;
  821|     18|                    break;
  822|     18|                }
  823|  6.57k|                if (!isxdigit(*ctx->pos)) {
  ------------------
  |  Branch (823:21): [True: 3, False: 6.57k]
  ------------------
  824|      3|                    PLIST_OSTEP_ERR("Invalid byte group in data at offset %ld\n", (long int)(ctx->pos - ctx->start));
  ------------------
  |  |   46|      3|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 3]
  |  |  ------------------
  ------------------
  825|      3|                    ctx->err = PLIST_ERR_PARSE;
  826|      3|                    break;
  827|      3|                }
  828|  6.57k|                b = (b << 4) + HEX_DIGIT(*ctx->pos);
  ------------------
  |  |  607|  6.57k|#define HEX_DIGIT(x) ((x <= '9') ? (x - '0') : ((x <= 'F') ? (x - 'A' + 10) : (x - 'a' + 10)))
  |  |  ------------------
  |  |  |  Branch (607:23): [True: 2.64k, False: 3.92k]
  |  |  |  Branch (607:49): [True: 1.08k, False: 2.83k]
  |  |  ------------------
  ------------------
  829|  6.57k|                byte_array_append(bytes, &b, 1);
  830|  6.57k|                if (!bytes->data) {
  ------------------
  |  Branch (830:21): [True: 0, False: 6.57k]
  ------------------
  831|      0|                    PLIST_OSTEP_ERR("Out of memory while parsing data at offset %ld\n", (long int)(ctx->pos - ctx->start));
  ------------------
  |  |   46|      0|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  832|      0|                    ctx->err = PLIST_ERR_NO_MEM;
  833|      0|                    break;
  834|      0|                }
  835|  6.57k|                ctx->pos++;
  836|  6.57k|            }
  837|    314|            if (ctx->err) {
  ------------------
  |  Branch (837:17): [True: 29, False: 285]
  ------------------
  838|     29|                byte_array_free(bytes);
  839|     29|                plist_free_data(data);
  840|     29|                goto err_out;
  841|     29|            }
  842|    285|            if (ctx->pos >= ctx->end) {
  ------------------
  |  Branch (842:17): [True: 42, False: 243]
  ------------------
  843|     42|                byte_array_free(bytes);
  844|     42|                plist_free_data(data);
  845|     42|                PLIST_OSTEP_ERR("EOF while parsing data terminator '>' at offset %ld\n", (long int)(ctx->pos - ctx->start));
  ------------------
  |  |   46|     42|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 42]
  |  |  ------------------
  ------------------
  846|     42|                ctx->err = PLIST_ERR_PARSE;
  847|     42|                goto err_out;
  848|     42|            }
  849|    243|            if (*ctx->pos != '>') {
  ------------------
  |  Branch (849:17): [True: 0, False: 243]
  ------------------
  850|      0|                byte_array_free(bytes);
  851|      0|                plist_free_data(data);
  852|      0|                PLIST_OSTEP_ERR("Missing terminating '>' at offset %ld\n", (long int)(ctx->pos - ctx->start));
  ------------------
  |  |   46|      0|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  853|      0|                ctx->err = PLIST_ERR_PARSE;
  854|      0|                goto err_out;
  855|      0|            }
  856|    243|            ctx->pos++;
  857|    243|            data->buff = (uint8_t*)bytes->data;
  858|    243|            data->length = bytes->len;
  859|    243|            bytes->data = NULL;
  860|    243|            byte_array_free(bytes);
  861|    243|            *plist = plist_new_node(data);
  862|    243|            if (!*plist) {
  ------------------
  |  Branch (862:17): [True: 0, False: 243]
  ------------------
  863|      0|                plist_free_data(data);
  864|      0|                PLIST_OSTEP_ERR("Out of memory\n");
  ------------------
  |  |   46|      0|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  865|      0|                ctx->err = PLIST_ERR_NO_MEM;
  866|      0|                goto err_out;
  867|      0|            }
  868|    243|            parse_skip_ws(ctx);
  869|    243|            break;
  870|   188k|        } else if (*ctx->pos == '"' || *ctx->pos == '\'') {
  ------------------
  |  Branch (870:20): [True: 22.4k, False: 165k]
  |  Branch (870:40): [True: 4.68k, False: 160k]
  ------------------
  871|  27.1k|            char c = *ctx->pos;
  872|  27.1k|            ctx->pos++;
  873|  27.1k|            p = ctx->pos;
  874|  27.1k|            size_t num_escapes = 0;
  875|   102k|            while (ctx->pos < ctx->end) {
  ------------------
  |  Branch (875:20): [True: 102k, False: 61]
  ------------------
  876|   102k|                if (*ctx->pos == '\\') {
  ------------------
  |  Branch (876:21): [True: 16.1k, False: 85.8k]
  ------------------
  877|  16.1k|                    num_escapes++;
  878|  16.1k|                }
  879|   102k|                if ((*ctx->pos == c) && (*(ctx->pos-1) != '\\')) {
  ------------------
  |  Branch (879:21): [True: 27.5k, False: 74.4k]
  |  Branch (879:41): [True: 27.0k, False: 471]
  ------------------
  880|  27.0k|                    break;
  881|  27.0k|                }
  882|  74.9k|                ctx->pos++;
  883|  74.9k|            }
  884|  27.1k|            if (ctx->pos >= ctx->end) {
  ------------------
  |  Branch (884:17): [True: 61, False: 27.0k]
  ------------------
  885|     61|                plist_free_data(data);
  886|     61|                PLIST_OSTEP_ERR("EOF while parsing quoted string at offset %ld\n", (long int)(ctx->pos - ctx->start));
  ------------------
  |  |   46|     61|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 61]
  |  |  ------------------
  ------------------
  887|     61|                ctx->err = PLIST_ERR_PARSE;
  888|     61|                goto err_out;
  889|     61|            }
  890|  27.0k|            if (*ctx->pos != c) {
  ------------------
  |  Branch (890:17): [True: 0, False: 27.0k]
  ------------------
  891|      0|                plist_free_data(data);
  892|      0|                PLIST_OSTEP_ERR("Missing closing quote (%c) at offset %ld\n", c, (long int)(ctx->pos - ctx->start));
  ------------------
  |  |   46|      0|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  893|      0|                ctx->err = PLIST_ERR_PARSE;
  894|      0|                goto err_out;
  895|      0|            }
  896|  27.0k|            size_t slen = ctx->pos - p;
  897|  27.0k|            ctx->pos++; // skip the closing quote
  898|  27.0k|            char* strbuf = (char*)malloc(slen+1);
  899|  27.0k|            if (!strbuf) {
  ------------------
  |  Branch (899:17): [True: 0, False: 27.0k]
  ------------------
  900|      0|                plist_free_data(data);
  901|      0|                PLIST_OSTEP_ERR("Out of memory\n");
  ------------------
  |  |   46|      0|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  902|      0|                ctx->err = PLIST_ERR_NO_MEM;
  903|      0|                goto err_out;
  904|      0|            }
  905|  27.0k|            if (num_escapes > 0) {
  ------------------
  |  Branch (905:17): [True: 989, False: 26.1k]
  ------------------
  906|    989|                size_t i = 0;
  907|    989|                size_t o = 0;
  908|  23.5k|                while (i < slen) {
  ------------------
  |  Branch (908:24): [True: 22.5k, False: 989]
  ------------------
  909|  22.5k|                    if (p[i] == '\\') {
  ------------------
  |  Branch (909:25): [True: 7.98k, False: 14.5k]
  ------------------
  910|       |                        /* handle escape sequence */
  911|  7.98k|                        i++;
  912|  7.98k|                        switch (p[i]) {
  913|    422|                            case '0':
  ------------------
  |  Branch (913:29): [True: 422, False: 7.56k]
  ------------------
  914|    792|                            case '1':
  ------------------
  |  Branch (914:29): [True: 370, False: 7.61k]
  ------------------
  915|  1.19k|                            case '2':
  ------------------
  |  Branch (915:29): [True: 398, False: 7.59k]
  ------------------
  916|  1.58k|                            case '3':
  ------------------
  |  Branch (916:29): [True: 392, False: 7.59k]
  ------------------
  917|  1.94k|                            case '4':
  ------------------
  |  Branch (917:29): [True: 366, False: 7.62k]
  ------------------
  918|  2.21k|                            case '5':
  ------------------
  |  Branch (918:29): [True: 266, False: 7.72k]
  ------------------
  919|  2.69k|                            case '6':
  ------------------
  |  Branch (919:29): [True: 477, False: 7.51k]
  ------------------
  920|  3.31k|                            case '7': {
  ------------------
  |  Branch (920:29): [True: 626, False: 7.36k]
  ------------------
  921|       |                                // max 3 digits octal
  922|  3.31k|                                unsigned char chr = 0;
  923|  3.31k|                                int maxd = 3;
  924|  7.20k|                                while ((i < slen) && (p[i] >= '0' && p[i] <= '7') && --maxd) {
  ------------------
  |  Branch (924:40): [True: 6.84k, False: 369]
  |  Branch (924:55): [True: 6.54k, False: 298]
  |  Branch (924:70): [True: 4.15k, False: 2.38k]
  |  Branch (924:86): [True: 3.89k, False: 263]
  ------------------
  925|  3.89k|                                    chr = (chr << 3) + p[i] - '0';
  926|  3.89k|                                    i++;
  927|  3.89k|                                }
  928|  3.31k|                                strbuf[o++] = (char)chr;
  929|  3.31k|                            }   break;
  930|  1.70k|                            case 'U': {
  ------------------
  |  Branch (930:29): [True: 1.70k, False: 6.28k]
  ------------------
  931|  1.70k|                                i++;
  932|       |                                // max 4 digits hex
  933|  1.70k|                                uint16_t wchr = 0;
  934|  1.70k|                                int maxd = 4;
  935|  4.91k|                                while ((i < slen) && isxdigit(p[i]) && maxd--) {
  ------------------
  |  Branch (935:40): [True: 4.60k, False: 317]
  |  Branch (935:54): [True: 3.38k, False: 1.21k]
  |  Branch (935:72): [True: 3.21k, False: 170]
  ------------------
  936|  3.21k|                                    wchr = (wchr << 4) + ((p[i] <= '9') ? (p[i] - '0') : ((p[i] <= 'F') ? (p[i] - 'A' + 10) : (p[i] - 'a' + 10)));
  ------------------
  |  Branch (936:59): [True: 1.35k, False: 1.86k]
  |  Branch (936:91): [True: 736, False: 1.12k]
  ------------------
  937|  3.21k|                                    i++;
  938|  3.21k|                                }
  939|  1.70k|                                if (wchr >= 0x800) {
  ------------------
  |  Branch (939:37): [True: 617, False: 1.08k]
  ------------------
  940|    617|                                    strbuf[o++] = (char)(0xE0 + ((wchr >> 12) & 0xF));
  941|    617|                                    strbuf[o++] = (char)(0x80 + ((wchr >> 6) & 0x3F));
  942|    617|                                    strbuf[o++] = (char)(0x80 + (wchr & 0x3F));
  943|  1.08k|                                } else if (wchr >= 0x80) {
  ------------------
  |  Branch (943:44): [True: 267, False: 822]
  ------------------
  944|    267|                                    strbuf[o++] = (char)(0xC0 + ((wchr >> 6) & 0x1F));
  945|    267|                                    strbuf[o++] = (char)(0x80 + (wchr & 0x3F));
  946|    822|                                } else {
  947|    822|                                    strbuf[o++] = (char)(wchr & 0x7F);
  948|    822|                                }
  949|  1.70k|                            }   break;
  950|    199|                            case 'a': strbuf[o++] = '\a'; i++; break;
  ------------------
  |  Branch (950:29): [True: 199, False: 7.78k]
  ------------------
  951|    208|                            case 'b': strbuf[o++] = '\b'; i++; break;
  ------------------
  |  Branch (951:29): [True: 208, False: 7.78k]
  ------------------
  952|    214|                            case 'f': strbuf[o++] = '\f'; i++; break;
  ------------------
  |  Branch (952:29): [True: 214, False: 7.77k]
  ------------------
  953|    203|                            case 'n': strbuf[o++] = '\n'; i++; break;
  ------------------
  |  Branch (953:29): [True: 203, False: 7.78k]
  ------------------
  954|    246|                            case 'r': strbuf[o++] = '\r'; i++; break;
  ------------------
  |  Branch (954:29): [True: 246, False: 7.74k]
  ------------------
  955|    433|                            case 't': strbuf[o++] = '\t'; i++; break;
  ------------------
  |  Branch (955:29): [True: 433, False: 7.55k]
  ------------------
  956|    197|                            case 'v': strbuf[o++] = '\v'; i++; break;
  ------------------
  |  Branch (956:29): [True: 197, False: 7.79k]
  ------------------
  957|    235|                            case '"': strbuf[o++] = '"';  i++; break;
  ------------------
  |  Branch (957:29): [True: 235, False: 7.75k]
  ------------------
  958|    263|                            case '\'': strbuf[o++] = '\''; i++; break;
  ------------------
  |  Branch (958:29): [True: 263, False: 7.72k]
  ------------------
  959|    767|                            default:
  ------------------
  |  Branch (959:29): [True: 767, False: 7.22k]
  ------------------
  960|    767|                                break;
  961|  7.98k|                        }
  962|  14.5k|                    } else {
  963|  14.5k|                        strbuf[o++] = p[i++];
  964|  14.5k|                    }
  965|  22.5k|                }
  966|    989|                strbuf[o] = '\0';
  967|    989|                slen = o;
  968|  26.1k|            } else {
  969|  26.1k|                strncpy(strbuf, p, slen);
  970|  26.1k|                strbuf[slen] = '\0';
  971|  26.1k|            }
  972|  27.0k|            data->type = PLIST_STRING;
  973|  27.0k|            data->strval = strbuf;
  974|  27.0k|            data->length = slen;
  975|  27.0k|            *plist = plist_new_node(data);
  976|  27.0k|            if (!*plist) {
  ------------------
  |  Branch (976:17): [True: 0, False: 27.0k]
  ------------------
  977|      0|                plist_free_data(data);
  978|      0|                PLIST_OSTEP_ERR("Out of memory\n");
  ------------------
  |  |   46|      0|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  979|      0|                ctx->err = PLIST_ERR_NO_MEM;
  980|      0|                goto err_out;
  981|      0|            }
  982|  27.0k|            parse_skip_ws(ctx);
  983|  27.0k|            break;
  984|   160k|        } else {
  985|       |            // unquoted string
  986|   160k|            size_t slen = 0;
  987|   160k|            parse_skip_ws(ctx);
  988|   160k|            p = ctx->pos;
  989|   391k|            while (ctx->pos < ctx->end) {
  ------------------
  |  Branch (989:20): [True: 391k, False: 108]
  ------------------
  990|   391k|                if (!allowed_unquoted_chars[(uint8_t)*ctx->pos]) {
  ------------------
  |  Branch (990:21): [True: 160k, False: 230k]
  ------------------
  991|   160k|                    break;
  992|   160k|                }
  993|   230k|                ctx->pos++;
  994|   230k|            }
  995|   160k|            slen = ctx->pos-p;
  996|   160k|            if (slen > 0) {
  ------------------
  |  Branch (996:17): [True: 160k, False: 128]
  ------------------
  997|   160k|                data->type = PLIST_STRING;
  998|   160k|                data->strval = strndup(p, slen);
  999|   160k|                if (!data->strval) {
  ------------------
  |  Branch (999:21): [True: 0, False: 160k]
  ------------------
 1000|      0|                    plist_free_data(data);
 1001|      0|                    PLIST_OSTEP_ERR("Out of memory\n");
  ------------------
  |  |   46|      0|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1002|      0|                    ctx->err = PLIST_ERR_NO_MEM;
 1003|      0|                    goto err_out;
 1004|      0|                }
 1005|   160k|                data->length = slen;
 1006|   160k|                *plist = plist_new_node(data);
 1007|   160k|                if (!*plist) {
  ------------------
  |  Branch (1007:21): [True: 0, False: 160k]
  ------------------
 1008|      0|                    plist_free_data(data);
 1009|      0|                    PLIST_OSTEP_ERR("Out of memory\n");
  ------------------
  |  |   46|      0|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1010|      0|                    ctx->err = PLIST_ERR_NO_MEM;
 1011|      0|                    goto err_out;
 1012|      0|                }
 1013|   160k|                parse_skip_ws(ctx);
 1014|   160k|                break;
 1015|   160k|            } else {
 1016|    128|                plist_free_data(data);
 1017|    128|                PLIST_OSTEP_ERR("Unexpected character when parsing unquoted string at offset %ld\n", (long int)(ctx->pos - ctx->start));
  ------------------
  |  |   46|    128|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 128]
  |  |  ------------------
  ------------------
 1018|    128|                ctx->err = PLIST_ERR_PARSE;
 1019|    128|                break;
 1020|    128|            }
 1021|   160k|        }
 1022|      0|        ctx->pos++;
 1023|      0|    }
 1024|   206k|    ctx->depth--;
 1025|       |
 1026|   220k|err_out:
 1027|   220k|    if (ctx->err != PLIST_ERR_SUCCESS) {
  ------------------
  |  Branch (1027:9): [True: 14.4k, False: 206k]
  ------------------
 1028|  14.4k|        plist_free(subnode);
 1029|  14.4k|        plist_free(*plist);
 1030|  14.4k|        *plist = NULL;
 1031|  14.4k|        return ctx->err;
 1032|  14.4k|    }
 1033|   206k|    return PLIST_ERR_SUCCESS;
 1034|   220k|}
oplist.c:parse_skip_ws:
  571|   945k|{
  572|   946k|    while (ctx->pos < ctx->end) {
  ------------------
  |  Branch (572:12): [True: 945k, False: 492]
  ------------------
  573|       |        // skip comments
  574|   945k|        if (*ctx->pos == '/' && (ctx->end - ctx->pos > 1)) {
  ------------------
  |  Branch (574:13): [True: 700, False: 945k]
  |  Branch (574:33): [True: 691, False: 9]
  ------------------
  575|    691|            if (*(ctx->pos+1) == '/') {
  ------------------
  |  Branch (575:17): [True: 340, False: 351]
  ------------------
  576|    340|                ctx->pos++;
  577|  2.43k|                while (ctx->pos < ctx->end) {
  ------------------
  |  Branch (577:24): [True: 2.41k, False: 23]
  ------------------
  578|  2.41k|                    if ((*ctx->pos == '\n') || (*ctx->pos == '\r')) {
  ------------------
  |  Branch (578:25): [True: 62, False: 2.35k]
  |  Branch (578:48): [True: 255, False: 2.09k]
  ------------------
  579|    317|                        break;
  580|    317|                    }
  581|  2.09k|                    ctx->pos++;
  582|  2.09k|                }
  583|    351|            } else if (*(ctx->pos+1) == '*') {
  ------------------
  |  Branch (583:24): [True: 295, False: 56]
  ------------------
  584|    295|                ctx->pos++;
  585|  7.75k|                while (ctx->pos < ctx->end) {
  ------------------
  |  Branch (585:24): [True: 7.72k, False: 30]
  ------------------
  586|  7.72k|                    if (*ctx->pos == '*' && (ctx->end - ctx->pos > 1)) {
  ------------------
  |  Branch (586:25): [True: 689, False: 7.03k]
  |  Branch (586:45): [True: 687, False: 2]
  ------------------
  587|    687|                        if (*(ctx->pos+1) == '/') {
  ------------------
  |  Branch (587:29): [True: 265, False: 422]
  ------------------
  588|    265|                            ctx->pos+=2;
  589|    265|                            break;
  590|    265|                        }
  591|    687|                    }
  592|  7.45k|                    ctx->pos++;
  593|  7.45k|                }
  594|    295|            }
  595|    691|            if (ctx->pos >= ctx->end) {
  ------------------
  |  Branch (595:17): [True: 55, False: 636]
  ------------------
  596|     55|                break;
  597|     55|            }
  598|    691|        }
  599|       |        // break on any char that's not white space
  600|   945k|        if (!(((*(ctx->pos) == ' ') || (*(ctx->pos) == '\t') || (*(ctx->pos) == '\r') || (*(ctx->pos) == '\n')))) {
  ------------------
  |  Branch (600:16): [True: 262, False: 945k]
  |  Branch (600:40): [True: 233, False: 945k]
  |  Branch (600:65): [True: 437, False: 944k]
  |  Branch (600:90): [True: 149, False: 944k]
  ------------------
  601|   944k|            break;
  602|   944k|        }
  603|  1.08k|        ctx->pos++;
  604|  1.08k|    }
  605|   945k|}
oplist.c:parse_dict_data:
  612|  17.4k|{
  613|  17.4k|    plist_t key = NULL;
  614|  17.4k|    plist_t val = NULL;
  615|  96.0k|    while (ctx->pos < ctx->end && !ctx->err) {
  ------------------
  |  Branch (615:12): [True: 95.6k, False: 403]
  |  Branch (615:35): [True: 95.6k, False: 0]
  ------------------
  616|  95.6k|        parse_skip_ws(ctx);
  617|  95.6k|        if (ctx->pos >= ctx->end || *ctx->pos == '}') {
  ------------------
  |  Branch (617:13): [True: 1, False: 95.6k]
  |  Branch (617:37): [True: 5.30k, False: 90.3k]
  ------------------
  618|  5.30k|            break;
  619|  5.30k|        }
  620|  90.3k|        key = NULL;
  621|  90.3k|        ctx->err = node_from_openstep(ctx, &key);
  622|  90.3k|        if (ctx->err != PLIST_ERR_SUCCESS) {
  ------------------
  |  Branch (622:13): [True: 10.9k, False: 79.3k]
  ------------------
  623|  10.9k|            break;
  624|  10.9k|        }
  625|  79.3k|        if (!PLIST_IS_STRING(key)) {
  ------------------
  |  | 1244|  79.3k|    #define PLIST_IS_STRING(__plist)  _PLIST_IS_TYPE(__plist, STRING)
  |  |  ------------------
  |  |  |  | 1234|  79.3k|    #define _PLIST_IS_TYPE(__plist, __plist_type) (__plist && (plist_get_node_type(__plist) == PLIST_##__plist_type))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1234:52): [True: 79.3k, False: 1]
  |  |  |  |  |  Branch (1234:63): [True: 79.1k, False: 221]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  626|    222|            PLIST_OSTEP_ERR("Invalid type for dictionary key at offset %ld\n", (long int)(ctx->pos - ctx->start));
  ------------------
  |  |   46|    222|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 222]
  |  |  ------------------
  ------------------
  627|    222|            ctx->err = PLIST_ERR_PARSE;
  628|    222|            break;
  629|    222|        }
  630|  79.1k|        parse_skip_ws(ctx);
  631|  79.1k|        if (ctx->pos >= ctx->end) {
  ------------------
  |  Branch (631:13): [True: 45, False: 79.0k]
  ------------------
  632|     45|            PLIST_OSTEP_ERR("EOF while parsing dictionary '=' delimiter at offset %ld\n", (long int)(ctx->pos - ctx->start));
  ------------------
  |  |   46|     45|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 45]
  |  |  ------------------
  ------------------
  633|     45|            ctx->err = PLIST_ERR_PARSE;
  634|     45|            break;
  635|     45|        }
  636|  79.0k|        if (*ctx->pos != '=') {
  ------------------
  |  Branch (636:13): [True: 16, False: 79.0k]
  ------------------
  637|     16|            PLIST_OSTEP_ERR("Missing '=' while parsing dictionary item at offset %ld\n", (long int)(ctx->pos - ctx->start));
  ------------------
  |  |   46|     16|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 16]
  |  |  ------------------
  ------------------
  638|     16|            ctx->err = PLIST_ERR_PARSE;
  639|     16|            break;
  640|     16|        }
  641|  79.0k|        ctx->pos++;
  642|  79.0k|        if (ctx->pos >= ctx->end) {
  ------------------
  |  Branch (642:13): [True: 232, False: 78.8k]
  ------------------
  643|    232|            PLIST_OSTEP_ERR("EOF while parsing dictionary item at offset %ld\n", (long int)(ctx->pos - ctx->start));
  ------------------
  |  |   46|    232|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 232]
  |  |  ------------------
  ------------------
  644|    232|            ctx->err = PLIST_ERR_PARSE;
  645|    232|            break;
  646|    232|        }
  647|  78.8k|        val = NULL;
  648|  78.8k|        ctx->err = node_from_openstep(ctx, &val);
  649|  78.8k|        if (ctx->err != PLIST_ERR_SUCCESS) {
  ------------------
  |  Branch (649:13): [True: 218, False: 78.6k]
  ------------------
  650|    218|            break;
  651|    218|        }
  652|  78.6k|        if (!val) {
  ------------------
  |  Branch (652:13): [True: 4, False: 78.6k]
  ------------------
  653|      4|            PLIST_OSTEP_ERR("Missing value for dictionary item at offset %ld\n", (long int)(ctx->pos - ctx->start));
  ------------------
  |  |   46|      4|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 4]
  |  |  ------------------
  ------------------
  654|      4|            ctx->err = PLIST_ERR_PARSE;
  655|      4|            break;
  656|      4|        }
  657|  78.6k|        parse_skip_ws(ctx);
  658|  78.6k|        if (ctx->pos >= ctx->end) {
  ------------------
  |  Branch (658:13): [True: 7, False: 78.6k]
  ------------------
  659|      7|            PLIST_OSTEP_ERR("EOF while parsing dictionary item terminator ';' at offset %ld\n", (long int)(ctx->pos - ctx->start));
  ------------------
  |  |   46|      7|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 7]
  |  |  ------------------
  ------------------
  660|      7|            ctx->err = PLIST_ERR_PARSE;
  661|      7|            break;
  662|      7|        }
  663|  78.6k|        if (*ctx->pos != ';') {
  ------------------
  |  Branch (663:13): [True: 15, False: 78.6k]
  ------------------
  664|     15|            PLIST_OSTEP_ERR("Missing terminating ';' while parsing dictionary item at offset %ld\n", (long int)(ctx->pos - ctx->start));
  ------------------
  |  |   46|     15|#define PLIST_OSTEP_ERR(...) if (plist_ostep_debug) { fprintf(stderr, "libplist[ostepparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (46:34): [True: 0, False: 15]
  |  |  ------------------
  ------------------
  665|     15|            ctx->err = PLIST_ERR_PARSE;
  666|     15|            break;
  667|     15|        }
  668|       |
  669|  78.6k|        if (plist_dict_set_item(dict, plist_get_string_ptr(key, NULL), val) != PLIST_ERR_SUCCESS) {
  ------------------
  |  Branch (669:13): [True: 0, False: 78.6k]
  ------------------
  670|      0|            ctx->err = PLIST_ERR_NO_MEM;
  671|      0|            break;
  672|      0|        }
  673|  78.6k|        plist_free(key);
  674|  78.6k|        key = NULL;
  675|  78.6k|        val = NULL;
  676|       |
  677|  78.6k|        ctx->pos++;
  678|  78.6k|    }
  679|  17.4k|    plist_free(key);
  680|  17.4k|    plist_free(val);
  681|  17.4k|}

plist.c:internal_plist_init:
  153|      2|{
  154|      2|    plist_bin_init();
  155|      2|    plist_xml_init();
  156|      2|    plist_json_init();
  157|      2|    plist_ostep_init();
  158|      2|    atexit(internal_plist_deinit);
  159|      2|}
plist_new_node:
  348|   298k|{
  349|       |    return (plist_t) node_create(NULL, data);
  350|   298k|}
plist_get_data:
  363|  28.9M|{
  364|  28.9M|    if (!node)
  ------------------
  |  Branch (364:9): [True: 0, False: 28.9M]
  ------------------
  365|      0|        return NULL;
  366|  28.9M|    return (plist_data_t)((node_t)node)->data;
  367|  28.9M|}
plist_new_plist_data:
  370|   298k|{
  371|   298k|    return (plist_data_t) calloc(1, sizeof(struct plist_data_s));
  372|   298k|}
plist_free_data:
  431|   298k|{
  432|   298k|    if (!data) return;
  ------------------
  |  Branch (432:9): [True: 0, False: 298k]
  ------------------
  433|   298k|    _plist_free_data(data);
  434|   298k|    free(data);
  435|   298k|}
plist_new_dict:
  497|    930|{
  498|    930|    plist_data_t data = plist_new_plist_data();
  499|    930|    if (!data) {
  ------------------
  |  Branch (499:9): [True: 0, False: 930]
  ------------------
  500|      0|        PLIST_ERR("%s: failed to allocate plist data\n", __func__);
  ------------------
  |  |   57|      0|#define PLIST_ERR(...) if (plist_debug > 0) { fprintf(stderr, "libplist ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (57:28): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  501|      0|        return NULL;
  502|      0|    }
  503|    930|    data->type = PLIST_DICT;
  504|    930|    return plist_new_node_or_free(data);
  505|    930|}
plist_free:
  682|   160k|{
  683|   160k|    if (plist)
  ------------------
  |  Branch (683:9): [True: 95.5k, False: 65.3k]
  ------------------
  684|  95.5k|    {
  685|  95.5k|        plist_free_node((node_t)plist);
  686|  95.5k|    }
  687|   160k|}
plist_array_append_item:
 1067|  47.0k|{
 1068|  47.0k|    if (!PLIST_IS_ARRAY(node) || !item) {
  ------------------
  |  | 1246|  47.0k|    #define PLIST_IS_ARRAY(__plist)   _PLIST_IS_TYPE(__plist, ARRAY)
  |  |  ------------------
  |  |  |  | 1234|  94.1k|    #define _PLIST_IS_TYPE(__plist, __plist_type) (__plist && (plist_get_node_type(__plist) == PLIST_##__plist_type))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1234:52): [True: 47.0k, False: 0]
  |  |  |  |  |  Branch (1234:63): [True: 47.0k, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (1068:34): [True: 0, False: 47.0k]
  ------------------
 1069|      0|        PLIST_ERR("invalid argument passed to %s (node=%p, item=%p)\n", __func__, node, item);
  ------------------
  |  |   57|      0|#define PLIST_ERR(...) if (plist_debug > 0) { fprintf(stderr, "libplist ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (57:28): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1070|      0|        return PLIST_ERR_INVALID_ARG;
 1071|      0|    }
 1072|  47.0k|    node_t it = (node_t)item;
 1073|  47.0k|    if (it->parent != NULL) {
  ------------------
  |  Branch (1073:9): [True: 0, False: 47.0k]
  ------------------
 1074|      0|        assert(it->parent == NULL && "item already has a parent; use plist_copy() or detach first");
  ------------------
  |  Branch (1074:9): [True: 0, False: 0]
  |  Branch (1074:9): [True: 0, False: 0]
  |  Branch (1074:9): [True: 0, False: 0]
  |  Branch (1074:9): [True: 0, False: 0]
  ------------------
 1075|      0|        PLIST_ERR("%s: item already has a parent; use plist_copy() or detach first\n", __func__);
  ------------------
  |  |   57|      0|#define PLIST_ERR(...) if (plist_debug > 0) { fprintf(stderr, "libplist ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (57:28): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1076|      0|        return PLIST_ERR_INVALID_ARG;
 1077|      0|    }
 1078|       |
 1079|  47.0k|    int r = node_attach((node_t)node, (node_t)item);
 1080|  47.0k|    if (r != NODE_ERR_SUCCESS) {
  ------------------
  |  |   35|  47.0k|#define NODE_ERR_SUCCESS       0
  ------------------
  |  Branch (1080:9): [True: 0, False: 47.0k]
  ------------------
 1081|      0|        PLIST_ERR("%s: failed to append item (err=%d)\n", __func__, r);
  ------------------
  |  |   57|      0|#define PLIST_ERR(...) if (plist_debug > 0) { fprintf(stderr, "libplist ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (57:28): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1082|      0|        return PLIST_ERR_UNKNOWN;
 1083|      0|    }
 1084|  47.0k|    _plist_array_post_insert(node, item, -1);
 1085|       |
 1086|  47.0k|    return PLIST_ERR_SUCCESS;
 1087|  47.0k|}
plist_dict_get_item:
 1268|  78.6k|{
 1269|  78.6k|    plist_t ret = NULL;
 1270|  78.6k|    if (!PLIST_IS_DICT(node) || !key) {
  ------------------
  |  | 1248|  78.6k|    #define PLIST_IS_DICT(__plist)    _PLIST_IS_TYPE(__plist, DICT)
  |  |  ------------------
  |  |  |  | 1234|   157k|    #define _PLIST_IS_TYPE(__plist, __plist_type) (__plist && (plist_get_node_type(__plist) == PLIST_##__plist_type))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1234:52): [True: 78.6k, False: 0]
  |  |  |  |  |  Branch (1234:63): [True: 78.6k, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (1270:33): [True: 0, False: 78.6k]
  ------------------
 1271|      0|        PLIST_ERR("invalid argument passed to %s (node=%p, key=%p)\n", __func__, node, key);
  ------------------
  |  |   57|      0|#define PLIST_ERR(...) if (plist_debug > 0) { fprintf(stderr, "libplist ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (57:28): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1272|      0|        return NULL;
 1273|      0|    }
 1274|  78.6k|    plist_data_t data = plist_get_data(node);
 1275|  78.6k|    if (!data) {
  ------------------
  |  Branch (1275:9): [True: 0, False: 78.6k]
  ------------------
 1276|      0|        PLIST_ERR("%s: invalid node\n", __func__);
  ------------------
  |  |   57|      0|#define PLIST_ERR(...) if (plist_debug > 0) { fprintf(stderr, "libplist ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (57:28): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1277|      0|        return NULL;
 1278|      0|    }
 1279|  78.6k|    size_t keylen = strlen(key);
 1280|  78.6k|    hashtable_t *ht = (hashtable_t*)data->hashtable;
 1281|  78.6k|    if (ht) {
  ------------------
  |  Branch (1281:9): [True: 1.14k, False: 77.4k]
  ------------------
 1282|  1.14k|        struct plist_data_s sdata = { 0 };
 1283|  1.14k|        sdata.strval = (char*)key;
 1284|  1.14k|        sdata.length = keylen;
 1285|  1.14k|        return (plist_t)hash_table_lookup(ht, &sdata);
 1286|  77.4k|    } else {
 1287|  77.4k|        plist_t k = NULL;
 1288|  9.45M|        for (k = (plist_t)node_first_child((node_t)node); k; ) {
  ------------------
  |  Branch (1288:59): [True: 9.37M, False: 76.7k]
  ------------------
 1289|  9.37M|            plist_t v = (plist_t)node_next_sibling(k);
 1290|  9.37M|            if (!v) break;
  ------------------
  |  Branch (1290:17): [True: 0, False: 9.37M]
  ------------------
 1291|  9.37M|            data = plist_get_data(k);
 1292|  9.37M|            assert(PLIST_IS_KEY(k));
  ------------------
  |  Branch (1292:13): [True: 0, False: 9.37M]
  |  Branch (1292:13): [True: 0, False: 0]
  |  Branch (1292:13): [True: 9.37M, False: 0]
  |  Branch (1292:13): [True: 9.37M, False: 0]
  ------------------
 1293|  9.37M|            if (!PLIST_IS_KEY(k) || !data || !data->strval) {
  ------------------
  |  | 1254|  9.37M|    #define PLIST_IS_KEY(__plist)     _PLIST_IS_TYPE(__plist, KEY)
  |  |  ------------------
  |  |  |  | 1234|  18.7M|    #define _PLIST_IS_TYPE(__plist, __plist_type) (__plist && (plist_get_node_type(__plist) == PLIST_##__plist_type))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1234:52): [True: 9.37M, False: 0]
  |  |  |  |  |  Branch (1234:63): [True: 9.37M, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (1293:37): [True: 0, False: 9.37M]
  |  Branch (1293:46): [True: 0, False: 9.37M]
  ------------------
 1294|      0|                PLIST_ERR("invalid key node at %p\n", k);
  ------------------
  |  |   57|      0|#define PLIST_ERR(...) if (plist_debug > 0) { fprintf(stderr, "libplist ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (57:28): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1295|      0|                break;
 1296|      0|            }
 1297|  9.37M|            if (data->length == keylen && !memcmp(key, data->strval, keylen+1)) {
  ------------------
  |  Branch (1297:17): [True: 4.73M, False: 4.63M]
  |  Branch (1297:43): [True: 724, False: 4.73M]
  ------------------
 1298|    724|                ret = v;
 1299|    724|                break;
 1300|    724|            }
 1301|  9.37M|            k = node_next_sibling(v);
 1302|  9.37M|        }
 1303|  77.4k|    }
 1304|  77.4k|    return ret;
 1305|  78.6k|}
plist_dict_set_item:
 1318|  78.6k|{
 1319|  78.6k|    if (!PLIST_IS_DICT(node) || !key || !item) {
  ------------------
  |  | 1248|  78.6k|    #define PLIST_IS_DICT(__plist)    _PLIST_IS_TYPE(__plist, DICT)
  |  |  ------------------
  |  |  |  | 1234|   157k|    #define _PLIST_IS_TYPE(__plist, __plist_type) (__plist && (plist_get_node_type(__plist) == PLIST_##__plist_type))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1234:52): [True: 78.6k, False: 0]
  |  |  |  |  |  Branch (1234:63): [True: 78.6k, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (1319:33): [True: 0, False: 78.6k]
  |  Branch (1319:41): [True: 0, False: 78.6k]
  ------------------
 1320|      0|        PLIST_ERR("invalid argument passed to %s (node=%p, key=%p, item=%p)\n", __func__, node, key, item);
  ------------------
  |  |   57|      0|#define PLIST_ERR(...) if (plist_debug > 0) { fprintf(stderr, "libplist ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (57:28): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1321|      0|        return PLIST_ERR_INVALID_ARG;
 1322|      0|    }
 1323|  78.6k|    node_t it = (node_t)item;
 1324|  78.6k|    if (it->parent != NULL) {
  ------------------
  |  Branch (1324:9): [True: 0, False: 78.6k]
  ------------------
 1325|      0|        assert(it->parent == NULL && "item already has a parent");
  ------------------
  |  Branch (1325:9): [True: 0, False: 0]
  |  Branch (1325:9): [True: 0, False: 0]
  |  Branch (1325:9): [True: 0, False: 0]
  |  Branch (1325:9): [True: 0, False: 0]
  ------------------
 1326|      0|        PLIST_ERR("%s: item already has a parent\n", __func__);
  ------------------
  |  |   57|      0|#define PLIST_ERR(...) if (plist_debug > 0) { fprintf(stderr, "libplist ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (57:28): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1327|      0|        return PLIST_ERR_INVALID_ARG;
 1328|      0|    }
 1329|       |
 1330|  78.6k|    hashtable_t *ht = (hashtable_t*)((plist_data_t)((node_t)node)->data)->hashtable;
 1331|       |
 1332|  78.6k|    plist_t old_item = plist_dict_get_item(node, key);
 1333|  78.6k|    plist_t key_node = NULL;
 1334|       |
 1335|  78.6k|    if (old_item) {
  ------------------
  |  Branch (1335:9): [True: 1.35k, False: 77.2k]
  ------------------
 1336|       |        // --- REPLACE EXISTING VALUE ---
 1337|  1.35k|        node_t old_val = (node_t)old_item;
 1338|  1.35k|        node_t old_key = node_prev_sibling(old_val);
 1339|  1.35k|        if (!old_key) {
  ------------------
  |  Branch (1339:13): [True: 0, False: 1.35k]
  ------------------
 1340|      0|            PLIST_ERR("%s: corrupt dict (value without key)\n", __func__);
  ------------------
  |  |   57|      0|#define PLIST_ERR(...) if (plist_debug > 0) { fprintf(stderr, "libplist ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (57:28): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1341|      0|            return PLIST_ERR_UNKNOWN;
 1342|      0|        }
 1343|  1.35k|        if (!PLIST_IS_KEY((plist_t)old_key)) {
  ------------------
  |  | 1254|  1.35k|    #define PLIST_IS_KEY(__plist)     _PLIST_IS_TYPE(__plist, KEY)
  |  |  ------------------
  |  |  |  | 1234|  1.35k|    #define _PLIST_IS_TYPE(__plist, __plist_type) (__plist && (plist_get_node_type(__plist) == PLIST_##__plist_type))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1234:52): [True: 1.35k, False: 0]
  |  |  |  |  |  Branch (1234:63): [True: 1.35k, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
 1344|      0|            PLIST_ERR("%s: corrupt dict ('key' node is not PLIST_KEY\n", __func__);
  ------------------
  |  |   57|      0|#define PLIST_ERR(...) if (plist_debug > 0) { fprintf(stderr, "libplist ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (57:28): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1345|      0|            return PLIST_ERR_UNKNOWN;
 1346|      0|        }
 1347|       |
 1348|       |        // detach old value (do NOT free yet)
 1349|  1.35k|        int idx = node_detach((node_t)node, old_val);
 1350|  1.35k|        if (idx < 0) {
  ------------------
  |  Branch (1350:13): [True: 0, False: 1.35k]
  ------------------
 1351|      0|            PLIST_ERR("%s: failed to detach old value (err=%d)\n", __func__, idx);
  ------------------
  |  |   57|      0|#define PLIST_ERR(...) if (plist_debug > 0) { fprintf(stderr, "libplist ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (57:28): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1352|      0|            return PLIST_ERR_UNKNOWN;
 1353|      0|        }
 1354|       |
 1355|       |        // insert new value at same position
 1356|  1.35k|        int r = node_insert((node_t)node, (unsigned)idx, (node_t)item);
 1357|  1.35k|        if (r != NODE_ERR_SUCCESS) {
  ------------------
  |  |   35|  1.35k|#define NODE_ERR_SUCCESS       0
  ------------------
  |  Branch (1357:13): [True: 0, False: 1.35k]
  ------------------
 1358|       |            // rollback: reinsert old value
 1359|      0|            int rb = node_insert((node_t)node, (unsigned)idx, old_val);
 1360|      0|            if (rb == NODE_ERR_SUCCESS && ht) {
  ------------------
  |  |   35|      0|#define NODE_ERR_SUCCESS       0
  ------------------
  |  Branch (1360:17): [True: 0, False: 0]
  |  Branch (1360:43): [True: 0, False: 0]
  ------------------
 1361|      0|                if (hash_table_insert(ht, ((node_t)old_key)->data, old_item) < 0) {
  ------------------
  |  Branch (1361:21): [True: 0, False: 0]
  ------------------
 1362|      0|                    plist_dict_drop_cache(node);
 1363|      0|                    ht = NULL;
 1364|      0|                }
 1365|      0|            }
 1366|      0|            PLIST_ERR("%s: failed to replace dict value (err=%d)\n", __func__, r);
  ------------------
  |  |   57|      0|#define PLIST_ERR(...) if (plist_debug > 0) { fprintf(stderr, "libplist ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (57:28): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1367|      0|            return PLIST_ERR_UNKNOWN;
 1368|      0|        }
 1369|  1.35k|        key_node = old_key;
 1370|       |
 1371|       |        // update hash table
 1372|  1.35k|        if (ht) {
  ------------------
  |  Branch (1372:13): [True: 630, False: 724]
  ------------------
 1373|    630|            if (hash_table_insert(ht, (plist_data_t)((node_t)key_node)->data, item) < 0) {
  ------------------
  |  Branch (1373:17): [True: 0, False: 630]
  ------------------
 1374|      0|                plist_dict_drop_cache(node);
 1375|      0|                ht = NULL;
 1376|      0|            }
 1377|    630|        }
 1378|       |
 1379|       |        // now it’s safe to free old value
 1380|  1.35k|        plist_free_node(old_val);
 1381|  77.2k|    } else {
 1382|       |        // --- INSERT NEW KEY/VALUE PAIR ---
 1383|  77.2k|        key_node = plist_new_key(key);
 1384|  77.2k|        if (!key_node) return PLIST_ERR_NO_MEM;
  ------------------
  |  Branch (1384:13): [True: 0, False: 77.2k]
  ------------------
 1385|       |
 1386|  77.2k|        int r = node_attach((node_t)node, (node_t)key_node);
 1387|  77.2k|        if (r != NODE_ERR_SUCCESS) {
  ------------------
  |  |   35|  77.2k|#define NODE_ERR_SUCCESS       0
  ------------------
  |  Branch (1387:13): [True: 0, False: 77.2k]
  ------------------
 1388|      0|            plist_free_node((node_t)key_node);
 1389|      0|            PLIST_ERR("%s: failed to attach dict key (err=%d)\n", __func__, r);
  ------------------
  |  |   57|      0|#define PLIST_ERR(...) if (plist_debug > 0) { fprintf(stderr, "libplist ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (57:28): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1390|      0|            return PLIST_ERR_UNKNOWN;
 1391|      0|        }
 1392|  77.2k|        r = node_attach((node_t)node, (node_t)item);
 1393|  77.2k|        if (r != NODE_ERR_SUCCESS) {
  ------------------
  |  |   35|  77.2k|#define NODE_ERR_SUCCESS       0
  ------------------
  |  Branch (1393:13): [True: 0, False: 77.2k]
  ------------------
 1394|       |            // rollback key insertion
 1395|      0|            node_detach((node_t)node, (node_t)key_node);
 1396|      0|            plist_free_node((node_t)key_node);
 1397|      0|            PLIST_ERR("%s: failed to attach dict value (err=%d)\n", __func__, r);
  ------------------
  |  |   57|      0|#define PLIST_ERR(...) if (plist_debug > 0) { fprintf(stderr, "libplist ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (57:28): [True: 0, False: 0]
  |  |  ------------------
  ------------------
 1398|      0|            return PLIST_ERR_UNKNOWN;
 1399|      0|        }
 1400|       |
 1401|  77.2k|        if (ht) {
  ------------------
  |  Branch (1401:13): [True: 512, False: 76.7k]
  ------------------
 1402|       |            // store pointer to item in hash table
 1403|    512|            if (hash_table_insert(ht, (plist_data_t)((node_t)key_node)->data, item) < 0) {
  ------------------
  |  Branch (1403:17): [True: 0, False: 512]
  ------------------
 1404|      0|                plist_dict_drop_cache(node);
 1405|      0|                ht = NULL;
 1406|      0|            }
 1407|  76.7k|        } else if (((node_t)node)->count > 500) {
  ------------------
  |  Branch (1407:20): [True: 292, False: 76.4k]
  ------------------
 1408|       |            // make new hash table
 1409|    292|            ht = hash_table_new(dict_key_hash, dict_key_compare, NULL);
 1410|       |            // calculate the hashes for all entries we have so far
 1411|    292|            plist_t current = NULL;
 1412|    292|            for (current = (plist_t)node_first_child((node_t)node);
 1413|  73.5k|                 ht && current;
  ------------------
  |  Branch (1413:18): [True: 73.5k, False: 0]
  |  Branch (1413:24): [True: 73.2k, False: 292]
  ------------------
 1414|  73.2k|                 current = (plist_t)node_next_sibling(node_next_sibling((node_t)current)))
 1415|  73.2k|            {
 1416|  73.2k|                if (hash_table_insert(ht, ((node_t)current)->data, node_next_sibling((node_t)current)) < 0) {
  ------------------
  |  Branch (1416:21): [True: 0, False: 73.2k]
  ------------------
 1417|      0|                    hash_table_destroy(ht);
 1418|      0|                    ht = NULL;
 1419|      0|                }
 1420|  73.2k|            }
 1421|    292|            ((plist_data_t)((node_t)node)->data)->hashtable = ht;
 1422|    292|        }
 1423|  77.2k|    }
 1424|  78.6k|    return PLIST_ERR_SUCCESS;
 1425|  78.6k|}
plist_get_node_type:
 1755|  19.1M|{
 1756|  19.1M|    if (node)
  ------------------
  |  Branch (1756:9): [True: 19.1M, False: 0]
  ------------------
 1757|  19.1M|    {
 1758|  19.1M|        plist_data_t data = plist_get_data(node);
 1759|  19.1M|        if (data)
  ------------------
  |  Branch (1759:13): [True: 19.1M, False: 0]
  ------------------
 1760|  19.1M|            return data->type;
 1761|  19.1M|    }
 1762|      0|    return PLIST_NONE;
 1763|  19.1M|}
plist_get_string_ptr:
 1794|  78.6k|{
 1795|  78.6k|    if (!node)
  ------------------
  |  Branch (1795:9): [True: 0, False: 78.6k]
  ------------------
 1796|      0|        return NULL;
 1797|  78.6k|    plist_type type = plist_get_node_type(node);
 1798|  78.6k|    if (PLIST_STRING != type)
  ------------------
  |  Branch (1798:9): [True: 0, False: 78.6k]
  ------------------
 1799|      0|        return NULL;
 1800|  78.6k|    plist_data_t data = plist_get_data(node);
 1801|  78.6k|    if (length)
  ------------------
  |  Branch (1801:9): [True: 0, False: 78.6k]
  ------------------
 1802|      0|        *length = data->length;
 1803|  78.6k|    return (const char*)data->strval;
 1804|  78.6k|}
plist.c:_plist_free_data:
  400|   298k|{
  401|   298k|    if (!data) return;
  ------------------
  |  Branch (401:9): [True: 0, False: 298k]
  ------------------
  402|   298k|    switch (data->type) {
  403|  77.2k|        case PLIST_KEY:
  ------------------
  |  Branch (403:9): [True: 77.2k, False: 221k]
  ------------------
  404|   265k|        case PLIST_STRING:
  ------------------
  |  Branch (404:9): [True: 187k, False: 110k]
  ------------------
  405|   265k|            free(data->strval);
  406|   265k|            data->strval = NULL;
  407|   265k|            break;
  408|    314|        case PLIST_DATA:
  ------------------
  |  Branch (408:9): [True: 314, False: 298k]
  ------------------
  409|    314|            free(data->buff);
  410|    314|            data->buff = NULL;
  411|    314|            break;
  412|  15.5k|        case PLIST_ARRAY:
  ------------------
  |  Branch (412:9): [True: 15.5k, False: 283k]
  ------------------
  413|  15.5k|            ptr_array_free((ptrarray_t*)data->hashtable);
  414|  15.5k|            data->hashtable = NULL;
  415|  15.5k|            break;
  416|  17.5k|        case PLIST_DICT: {
  ------------------
  |  Branch (416:9): [True: 17.5k, False: 281k]
  ------------------
  417|  17.5k|            hashtable_t *ht = (hashtable_t*)data->hashtable;
  418|       |            // PLIST_DICT hashtables must not own/free values; values are freed via node tree.
  419|  17.5k|            assert(!ht || ht->free_func == NULL);
  ------------------
  |  Branch (419:13): [True: 17.5k, False: 0]
  |  Branch (419:13): [True: 0, False: 0]
  |  Branch (419:13): [True: 17.2k, False: 292]
  |  Branch (419:13): [True: 292, False: 0]
  ------------------
  420|  17.5k|            if (ht) ht->free_func = NULL;
  ------------------
  |  Branch (420:17): [True: 292, False: 17.2k]
  ------------------
  421|  17.5k|            hash_table_destroy(ht);
  422|  17.5k|            data->hashtable = NULL;
  423|  17.5k|            break;
  424|  17.5k|        }
  425|    189|        default:
  ------------------
  |  Branch (425:9): [True: 189, False: 298k]
  ------------------
  426|    189|            break;
  427|   298k|    }
  428|   298k|}
plist.c:plist_new_node_or_free:
  354|  78.1k|{
  355|  78.1k|    plist_t node = plist_new_node(data);
  356|  78.1k|    if (!node) {
  ------------------
  |  Branch (356:9): [True: 0, False: 78.1k]
  ------------------
  357|      0|        plist_free_data(data);
  358|      0|    }
  359|  78.1k|    return node;
  360|  78.1k|}
plist.c:plist_free_node:
  469|  96.8k|{
  470|  96.8k|    if (!root) return NODE_ERR_INVALID_ARG;
  ------------------
  |  |   36|      0|#define NODE_ERR_INVALID_ARG  -1
  ------------------
  |  Branch (470:9): [True: 0, False: 96.8k]
  ------------------
  471|       |
  472|  96.8k|    int root_index = -1;
  473|       |
  474|  96.8k|    if (root->parent) {
  ------------------
  |  Branch (474:9): [True: 0, False: 96.8k]
  ------------------
  475|      0|        root_index = node_detach(root->parent, root);
  476|      0|        if (root_index < 0) {
  ------------------
  |  Branch (476:13): [True: 0, False: 0]
  ------------------
  477|      0|            return root_index;
  478|      0|        }
  479|      0|    }
  480|       |
  481|  96.8k|    int r = plist_free_children(root);
  482|  96.8k|    if (r < 0) {
  ------------------
  |  Branch (482:9): [True: 0, False: 96.8k]
  ------------------
  483|       |        // root is already detached; caller should treat as error.
  484|      0|        return r;
  485|      0|    }
  486|       |
  487|  96.8k|    plist_data_t data = plist_get_data(root);
  488|  96.8k|    plist_free_data(data);
  489|  96.8k|    root->data = NULL;
  490|       |
  491|  96.8k|    node_destroy(root);
  492|       |
  493|  96.8k|    return root_index;
  494|  96.8k|}
plist.c:plist_free_children:
  438|  96.8k|{
  439|  96.8k|    if (!root) return NODE_ERR_INVALID_ARG;
  ------------------
  |  |   36|      0|#define NODE_ERR_INVALID_ARG  -1
  ------------------
  |  Branch (439:9): [True: 0, False: 96.8k]
  ------------------
  440|       |
  441|       |    /* Walk down to the deepest first child, free it and step back up.
  442|       |     * This needs no extra memory, so freeing can't fail with out-of-memory
  443|       |     * (which would leak the whole tree). */
  444|  96.8k|    node_t cur = root;
  445|   500k|    for (;;) {
  446|   500k|        node_t ch = node_first_child(cur);
  447|   500k|        if (ch) {
  ------------------
  |  Branch (447:13): [True: 201k, False: 298k]
  ------------------
  448|   201k|            cur = ch;
  449|   201k|            continue;
  450|   201k|        }
  451|   298k|        if (cur == root) break;
  ------------------
  |  Branch (451:13): [True: 96.8k, False: 201k]
  ------------------
  452|       |
  453|   201k|        node_t parent = (node_t)cur->parent;
  454|   201k|        int di = node_detach(parent, cur);
  455|   201k|        if (di < 0) {
  ------------------
  |  Branch (455:13): [True: 0, False: 201k]
  ------------------
  456|      0|            return di;
  457|      0|        }
  458|   201k|        plist_data_t data = plist_get_data(cur);
  459|   201k|        plist_free_data(data);
  460|   201k|        cur->data = NULL;
  461|   201k|        node_destroy(cur);
  462|   201k|        cur = parent;
  463|   201k|    }
  464|       |
  465|  96.8k|    return NODE_ERR_SUCCESS;
  ------------------
  |  |   35|  96.8k|#define NODE_ERR_SUCCESS       0
  ------------------
  466|  96.8k|}
plist.c:_plist_array_post_insert:
  966|  47.0k|{
  967|  47.0k|    ptrarray_t *pa = (ptrarray_t*)((plist_data_t)((node_t)node)->data)->hashtable;
  968|  47.0k|    if (pa) {
  ------------------
  |  Branch (968:9): [True: 14.9k, False: 32.1k]
  ------------------
  969|       |        /* store pointer to item in array */
  970|  14.9k|        if (ptr_array_insert(pa, item, n) < 0) {
  ------------------
  |  Branch (970:13): [True: 0, False: 14.9k]
  ------------------
  971|       |            /* lookup array would be out of sync, drop it */
  972|      0|            ptr_array_free(pa);
  973|      0|            ((plist_data_t)((node_t)node)->data)->hashtable = NULL;
  974|      0|        }
  975|  14.9k|        return;
  976|  14.9k|    }
  977|       |
  978|  32.1k|    if (((node_t)node)->count > 100) {
  ------------------
  |  Branch (978:9): [True: 162, False: 31.9k]
  ------------------
  979|       |       /* make new lookup array */
  980|    162|       pa = ptr_array_new(128);
  981|    162|       plist_t current = NULL;
  982|    162|       for (current = (plist_t)node_first_child((node_t)node);
  983|  16.5k|            pa && current;
  ------------------
  |  Branch (983:13): [True: 16.5k, False: 0]
  |  Branch (983:19): [True: 16.3k, False: 162]
  ------------------
  984|  16.3k|            current = (plist_t)node_next_sibling((node_t)current))
  985|  16.3k|       {
  986|  16.3k|           if (ptr_array_add(pa, current) < 0) {
  ------------------
  |  Branch (986:16): [True: 0, False: 16.3k]
  ------------------
  987|      0|               ptr_array_free(pa);
  988|       |               pa = NULL;
  989|      0|           }
  990|  16.3k|       }
  991|    162|       ((plist_data_t)((node_t)node)->data)->hashtable = pa;
  992|    162|    }
  993|  32.1k|}
plist.c:plist_new_key:
  520|  77.2k|{
  521|  77.2k|    plist_data_t data = plist_new_plist_data();
  522|  77.2k|    if (!data) {
  ------------------
  |  Branch (522:9): [True: 0, False: 77.2k]
  ------------------
  523|      0|        PLIST_ERR("%s: failed to allocate plist data\n", __func__);
  ------------------
  |  |   57|      0|#define PLIST_ERR(...) if (plist_debug > 0) { fprintf(stderr, "libplist ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (57:28): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  524|      0|        return NULL;
  525|      0|    }
  526|  77.2k|    data->type = PLIST_KEY;
  527|  77.2k|    data->strval = strdup(val);
  528|  77.2k|    if (!data->strval) {
  ------------------
  |  Branch (528:9): [True: 0, False: 77.2k]
  ------------------
  529|      0|        plist_free_data(data);
  530|      0|        PLIST_ERR("%s: strdup failed\n", __func__);
  ------------------
  |  |   57|      0|#define PLIST_ERR(...) if (plist_debug > 0) { fprintf(stderr, "libplist ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (57:28): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  531|      0|        return NULL;
  532|  77.2k|    } else {
  533|  77.2k|        data->length = strlen(val);
  534|  77.2k|    }
  535|  77.2k|    return plist_new_node_or_free(data);
  536|  77.2k|}
plist.c:dict_key_hash:
  375|  75.5k|{
  376|  75.5k|    plist_data_t keydata = (plist_data_t)data;
  377|  75.5k|    unsigned int hash = 5381;
  378|  75.5k|    size_t i;
  379|  75.5k|    char *str = keydata->strval;
  380|   218k|    for (i = 0; i < keydata->length; str++, i++) {
  ------------------
  |  Branch (380:17): [True: 143k, False: 75.5k]
  ------------------
  381|   143k|        hash = ((hash << 5) + hash) + *str;
  382|   143k|    }
  383|  75.5k|    return hash;
  384|  75.5k|}
plist.c:dict_key_compare:
  387|  4.07k|{
  388|  4.07k|    plist_data_t data_a = (plist_data_t)a;
  389|  4.07k|    plist_data_t data_b = (plist_data_t)b;
  390|  4.07k|    if (data_a->strval == NULL || data_b->strval == NULL) {
  ------------------
  |  Branch (390:9): [True: 0, False: 4.07k]
  |  Branch (390:35): [True: 0, False: 4.07k]
  ------------------
  391|      0|        return FALSE;
  ------------------
  |  |   37|      0|#define FALSE 0
  ------------------
  392|      0|    }
  393|  4.07k|    if (data_a->length != data_b->length) {
  ------------------
  |  Branch (393:9): [True: 1.31k, False: 2.76k]
  ------------------
  394|  1.31k|        return FALSE;
  ------------------
  |  |   37|  1.31k|#define FALSE 0
  ------------------
  395|  1.31k|    }
  396|  2.76k|    return (strcmp(data_a->strval, data_b->strval) == 0) ? TRUE : FALSE;
  ------------------
  |  |   33|  1.26k|#define TRUE 1
  ------------------
                  return (strcmp(data_a->strval, data_b->strval) == 0) ? TRUE : FALSE;
  ------------------
  |  |   37|  1.50k|#define FALSE 0
  ------------------
  |  Branch (396:12): [True: 1.26k, False: 1.50k]
  ------------------
  397|  4.07k|}

ptr_array_new:
   27|    162|{
   28|    162|	ptrarray_t *pa;
   29|    162|	if (capacity < 0 || (size_t)capacity > SIZE_MAX / sizeof(void*)) {
  ------------------
  |  Branch (29:6): [True: 0, False: 162]
  |  Branch (29:22): [True: 0, False: 162]
  ------------------
   30|      0|		return NULL;
   31|      0|	}
   32|    162|	pa = (ptrarray_t*)malloc(sizeof(ptrarray_t));
   33|    162|	if (!pa) {
  ------------------
  |  Branch (33:6): [True: 0, False: 162]
  ------------------
   34|      0|		return NULL;
   35|      0|	}
   36|    162|	pa->pdata = (void**)malloc(sizeof(void*) * (size_t)capacity);
   37|    162|	if (!pa->pdata) {
  ------------------
  |  Branch (37:6): [True: 0, False: 162]
  ------------------
   38|      0|		free(pa);
   39|      0|		return NULL;
   40|      0|	}
   41|    162|	pa->capacity = capacity;
   42|    162|	pa->capacity_step = (capacity > 4096) ? 4096 : capacity;
  ------------------
  |  Branch (42:22): [True: 0, False: 162]
  ------------------
   43|    162|	pa->len = 0;
   44|    162|	return pa;
   45|    162|}
ptr_array_free:
   48|  15.5k|{
   49|  15.5k|	if (!pa) return;
  ------------------
  |  Branch (49:6): [True: 15.3k, False: 162]
  ------------------
   50|    162|	if (pa->pdata) {
  ------------------
  |  Branch (50:6): [True: 162, False: 0]
  ------------------
   51|    162|		free(pa->pdata);
   52|    162|	}
   53|    162|	free(pa);
   54|    162|}
ptr_array_insert:
   57|  31.3k|{
   58|  31.3k|	if (!pa || !pa->pdata) return -1;
  ------------------
  |  Branch (58:6): [True: 0, False: 31.3k]
  |  Branch (58:13): [True: 0, False: 31.3k]
  ------------------
   59|  31.3k|	long remaining = pa->capacity-pa->len;
   60|  31.3k|	if (remaining == 0) {
  ------------------
  |  Branch (60:6): [True: 127, False: 31.2k]
  ------------------
   61|    127|		void **newdata;
   62|    127|		if (pa->capacity > INT_MAX - pa->capacity_step ||
  ------------------
  |  Branch (62:7): [True: 0, False: 127]
  ------------------
   63|    127|		    (size_t)(pa->capacity + pa->capacity_step) > SIZE_MAX / sizeof(void*)) {
  ------------------
  |  Branch (63:7): [True: 0, False: 127]
  ------------------
   64|      0|			return -1;
   65|      0|		}
   66|    127|		newdata = (void**)realloc(pa->pdata, sizeof(void*) * (size_t)(pa->capacity + pa->capacity_step));
   67|    127|		if (!newdata) {
  ------------------
  |  Branch (67:7): [True: 0, False: 127]
  ------------------
   68|      0|			return -1;
   69|      0|		}
   70|    127|		pa->pdata = newdata;
   71|    127|		pa->capacity += pa->capacity_step;
   72|    127|	}
   73|  31.3k|	if (array_index < 0 || array_index >= pa->len) {
  ------------------
  |  Branch (73:6): [True: 31.3k, False: 0]
  |  Branch (73:25): [True: 0, False: 0]
  ------------------
   74|  31.3k|		pa->pdata[pa->len] = data;
   75|  31.3k|	} else {
   76|      0|		memmove(&pa->pdata[array_index+1], &pa->pdata[array_index], (pa->len-array_index) * sizeof(void*));
   77|      0|		pa->pdata[array_index] = data;
   78|      0|	}
   79|  31.3k|	pa->len++;
   80|  31.3k|	return 0;
   81|  31.3k|}
ptr_array_add:
   84|  16.3k|{
   85|  16.3k|	return ptr_array_insert(pa, data, -1);
   86|  16.3k|}

plist_xml_init:
   91|      2|{
   92|       |    /* init XML stuff */
   93|      2|#ifdef DEBUG
   94|      2|    char *env_debug = getenv("PLIST_XML_DEBUG");
   95|      2|    if (env_debug && !strcmp(env_debug, "1")) {
  ------------------
  |  Branch (95:9): [True: 0, False: 2]
  |  Branch (95:22): [True: 0, False: 0]
  ------------------
   96|      0|        plist_xml_debug = 1;
   97|      0|    }
   98|      2|#endif
   99|      2|}

