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

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

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

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|}

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

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_from_json:
  918|  2.28k|{
  919|  2.28k|    if (!plist) {
  ------------------
  |  Branch (919:9): [True: 0, False: 2.28k]
  ------------------
  920|      0|        return PLIST_ERR_INVALID_ARG;
  921|      0|    }
  922|  2.28k|    *plist = NULL;
  923|  2.28k|    if (!json || (length == 0)) {
  ------------------
  |  Branch (923:9): [True: 0, False: 2.28k]
  |  Branch (923:18): [True: 0, False: 2.28k]
  ------------------
  924|      0|        return PLIST_ERR_INVALID_ARG;
  925|      0|    }
  926|       |
  927|  2.28k|    jsmn_parser parser;
  928|  2.28k|    jsmn_init(&parser);
  929|  2.28k|    unsigned int maxtoks = 256;
  930|  2.28k|    unsigned int curtoks = 0;
  931|  2.28k|    int r = 0;
  932|  2.28k|    jsmntok_t *tokens = NULL;
  933|       |
  934|  12.8k|    do {
  935|  12.8k|        jsmntok_t* newtokens = (jsmntok_t*)realloc(tokens, sizeof(jsmntok_t)*maxtoks);
  936|  12.8k|        if (!newtokens) {
  ------------------
  |  Branch (936:13): [True: 0, False: 12.8k]
  ------------------
  937|      0|            free(tokens);
  938|      0|            PLIST_JSON_ERR("%s: Out of memory\n", __func__);
  ------------------
  |  |   48|      0|#define PLIST_JSON_ERR(...) if (plist_json_debug) { fprintf(stderr, "libplist[jsonparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (48:33): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  939|      0|            return PLIST_ERR_NO_MEM;
  940|      0|        }
  941|  12.8k|        memset((unsigned char*)newtokens + sizeof(jsmntok_t)*curtoks, '\0', sizeof(jsmntok_t)*(maxtoks-curtoks));
  942|  12.8k|        tokens = newtokens;
  943|  12.8k|        curtoks = maxtoks;
  944|       |
  945|  12.8k|        r = jsmn_parse(&parser, json, length, tokens, maxtoks);
  946|  12.8k|        if (r == JSMN_ERROR_NOMEM) {
  ------------------
  |  Branch (946:13): [True: 10.5k, False: 2.28k]
  ------------------
  947|  10.5k|            if (maxtoks > (unsigned int)INT_MAX - 16) {
  ------------------
  |  Branch (947:17): [True: 0, False: 10.5k]
  ------------------
  948|      0|                free(tokens);
  949|      0|                return PLIST_ERR_NO_MEM;
  950|      0|            }
  951|  10.5k|            maxtoks+=16;
  952|  10.5k|            continue;
  953|  10.5k|        } else if (r < 0) {
  ------------------
  |  Branch (953:20): [True: 367, False: 1.91k]
  ------------------
  954|    367|            break;
  955|    367|        }
  956|  12.8k|    } while (r == JSMN_ERROR_NOMEM);
  ------------------
  |  Branch (956:14): [True: 10.5k, False: 1.91k]
  ------------------
  957|       |
  958|  2.28k|    switch(r) {
  959|      0|        case JSMN_ERROR_NOMEM:
  ------------------
  |  Branch (959:9): [True: 0, False: 2.28k]
  ------------------
  960|      0|            PLIST_JSON_ERR("%s: Out of memory...\n", __func__);
  ------------------
  |  |   48|      0|#define PLIST_JSON_ERR(...) if (plist_json_debug) { fprintf(stderr, "libplist[jsonparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (48:33): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  961|      0|            free(tokens);
  962|      0|            return PLIST_ERR_NO_MEM;
  963|     69|        case JSMN_ERROR_INVAL:
  ------------------
  |  Branch (963:9): [True: 69, False: 2.21k]
  ------------------
  964|     69|            PLIST_JSON_ERR("%s: Invalid character inside JSON string\n", __func__);
  ------------------
  |  |   48|     69|#define PLIST_JSON_ERR(...) if (plist_json_debug) { fprintf(stderr, "libplist[jsonparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (48:33): [True: 0, False: 69]
  |  |  ------------------
  ------------------
  965|     69|            free(tokens);
  966|     69|            return PLIST_ERR_PARSE;
  967|    298|        case JSMN_ERROR_PART:
  ------------------
  |  Branch (967:9): [True: 298, False: 1.98k]
  ------------------
  968|    298|            PLIST_JSON_ERR("%s: Incomplete JSON, more bytes expected\n", __func__);
  ------------------
  |  |   48|    298|#define PLIST_JSON_ERR(...) if (plist_json_debug) { fprintf(stderr, "libplist[jsonparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (48:33): [True: 0, False: 298]
  |  |  ------------------
  ------------------
  969|    298|            free(tokens);
  970|    298|            return PLIST_ERR_PARSE;
  971|      0|        case JSMN_ERROR_LIMIT:
  ------------------
  |  Branch (971:9): [True: 0, False: 2.28k]
  ------------------
  972|      0|            PLIST_JSON_ERR("%s: Input data too large\n", __func__);
  ------------------
  |  |   48|      0|#define PLIST_JSON_ERR(...) if (plist_json_debug) { fprintf(stderr, "libplist[jsonparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (48:33): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  973|      0|            free(tokens);
  974|      0|            return PLIST_ERR_PARSE;
  975|  1.91k|        default:
  ------------------
  |  Branch (975:9): [True: 1.91k, False: 367]
  ------------------
  976|  1.91k|            break;
  977|  2.28k|    }
  978|       |
  979|  1.91k|    int startindex = 0;
  980|  1.91k|    jsmntok_info_t ti = { tokens, parser.toknext, PLIST_ERR_SUCCESS };
  981|  1.91k|    switch (tokens[startindex].type) {
  982|    700|        case JSMN_PRIMITIVE:
  ------------------
  |  Branch (982:9): [True: 700, False: 1.21k]
  ------------------
  983|    700|            *plist = parse_primitive(json, &ti, &startindex);
  984|    700|            break;
  985|    190|        case JSMN_STRING:
  ------------------
  |  Branch (985:9): [True: 190, False: 1.72k]
  ------------------
  986|    190|            *plist = parse_string(json, &ti, &startindex);
  987|    190|            break;
  988|    425|        case JSMN_ARRAY:
  ------------------
  |  Branch (988:9): [True: 425, False: 1.49k]
  ------------------
  989|    425|            *plist = parse_array(json, &ti, &startindex, 0);
  990|    425|            break;
  991|    601|        case JSMN_OBJECT:
  ------------------
  |  Branch (991:9): [True: 601, False: 1.31k]
  ------------------
  992|    601|            *plist = parse_object(json, &ti, &startindex, 0);
  993|    601|            break;
  994|      0|        default:
  ------------------
  |  Branch (994:9): [True: 0, False: 1.91k]
  ------------------
  995|      0|            break;
  996|  1.91k|    }
  997|  1.91k|    free(tokens);
  998|  1.91k|    if (!*plist) {
  ------------------
  |  Branch (998:9): [True: 446, False: 1.47k]
  ------------------
  999|    446|        return (ti.err != PLIST_ERR_SUCCESS) ? ti.err : PLIST_ERR_PARSE;
  ------------------
  |  Branch (999:16): [True: 109, False: 337]
  ------------------
 1000|    446|    }
 1001|  1.47k|    return PLIST_ERR_SUCCESS;
 1002|  1.91k|}
jplist.c:parse_primitive:
  563|  29.4k|{
  564|  29.4k|    if (ti->tokens[*index].type != JSMN_PRIMITIVE) {
  ------------------
  |  Branch (564:9): [True: 0, False: 29.4k]
  ------------------
  565|      0|        PLIST_JSON_ERR("%s: token type != JSMN_PRIMITIVE\n", __func__);
  ------------------
  |  |   48|      0|#define PLIST_JSON_ERR(...) if (plist_json_debug) { fprintf(stderr, "libplist[jsonparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (48:33): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  566|      0|        return NULL;
  567|      0|    }
  568|  29.4k|    plist_t val = NULL;
  569|  29.4k|    const char* str_val = js + ti->tokens[*index].start;
  570|  29.4k|    const char* str_end = js + ti->tokens[*index].end;
  571|  29.4k|    size_t str_len = ti->tokens[*index].end - ti->tokens[*index].start;
  572|  29.4k|    if (!strncmp("false", str_val, str_len)) {
  ------------------
  |  Branch (572:9): [True: 3.39k, False: 26.0k]
  ------------------
  573|  3.39k|        val = plist_new_bool(0);
  574|  26.0k|    } else if (!strncmp("true", str_val, str_len)) {
  ------------------
  |  Branch (574:16): [True: 5.14k, False: 20.8k]
  ------------------
  575|  5.14k|        val = plist_new_bool(1);
  576|  20.8k|    } else if (!strncmp("null", str_val, str_len)) {
  ------------------
  |  Branch (576:16): [True: 14.1k, False: 6.72k]
  ------------------
  577|  14.1k|        plist_data_t data = plist_new_plist_data();
  578|  14.1k|        if (!data) {
  ------------------
  |  Branch (578:13): [True: 0, False: 14.1k]
  ------------------
  579|      0|            PLIST_JSON_ERR("%s: failed to allocate plist data\n", __func__);
  ------------------
  |  |   48|      0|#define PLIST_JSON_ERR(...) if (plist_json_debug) { fprintf(stderr, "libplist[jsonparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (48:33): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  580|      0|            return NULL;
  581|      0|        }
  582|  14.1k|        data->type = PLIST_NULL;
  583|  14.1k|        val = plist_new_node(data);
  584|  14.1k|        if (!val) {
  ------------------
  |  Branch (584:13): [True: 0, False: 14.1k]
  ------------------
  585|      0|            plist_free_data(data);
  586|      0|        }
  587|  14.1k|    } else if (isdigit(str_val[0]) || (str_val[0] == '-' && str_val+1 < str_end && isdigit(str_val[1]))) {
  ------------------
  |  Branch (587:16): [True: 5.79k, False: 939]
  |  Branch (587:40): [True: 799, False: 140]
  |  Branch (587:61): [True: 791, False: 8]
  |  Branch (587:84): [True: 781, False: 10]
  ------------------
  588|  6.57k|        char* endp = (char*)str_val;
  589|  6.57k|        int is_neg = (str_val[0] == '-');
  590|  6.57k|        int64_t intpart = parse_decimal(str_val, str_end, &endp);
  591|  6.57k|        if (endp >= str_end) {
  ------------------
  |  Branch (591:13): [True: 4.15k, False: 2.41k]
  ------------------
  592|       |            /* integer */
  593|  4.15k|            if (is_neg || intpart <= INT64_MAX) {
  ------------------
  |  Branch (593:17): [True: 534, False: 3.62k]
  |  Branch (593:27): [True: 3.62k, False: 0]
  ------------------
  594|  4.15k|                val = plist_new_int(intpart);
  595|  4.15k|            } else {
  596|      0|                val = plist_new_uint((uint64_t)intpart);
  597|      0|            }
  598|  4.15k|        } else if ((*endp == '.' && endp+1 < str_end && isdigit(*(endp+1))) || ((*endp == 'e' || *endp == 'E') && endp+1 < str_end && (isdigit(*(endp+1)) || (((*(endp+1) == '-') || (*(endp+1) == '+')) && endp+2 < str_end && isdigit(*(endp+2)))))) {
  ------------------
  |  Branch (598:21): [True: 480, False: 1.93k]
  |  Branch (598:37): [True: 478, False: 2]
  |  Branch (598:57): [True: 477, False: 1]
  |  Branch (598:82): [True: 1.49k, False: 448]
  |  Branch (598:98): [True: 427, False: 21]
  |  Branch (598:115): [True: 1.90k, False: 15]
  |  Branch (598:136): [True: 747, False: 1.15k]
  |  Branch (598:160): [True: 881, False: 274]
  |  Branch (598:182): [True: 265, False: 9]
  |  Branch (598:205): [True: 1.13k, False: 14]
  |  Branch (598:225): [True: 1.13k, False: 1]
  ------------------
  599|       |            /* floating point */
  600|  2.35k|            double dval = (double)intpart;
  601|  2.35k|            char* fendp = endp;
  602|  2.35k|            int err = 0;
  603|  2.35k|            do {
  604|  2.35k|                if (*endp == '.') {
  ------------------
  |  Branch (604:21): [True: 477, False: 1.87k]
  ------------------
  605|    477|                    fendp++;
  606|    477|                    double frac = 0;
  607|    477|                    double p = 0.1;
  608|  1.37k|                    while (fendp < str_end && isdigit(*fendp)) {
  ------------------
  |  Branch (608:28): [True: 937, False: 441]
  |  Branch (608:47): [True: 901, False: 36]
  ------------------
  609|    901|                        frac = frac + (*fendp - '0') * p;
  610|    901|                        p *= 0.1;
  611|    901|                        fendp++;
  612|    901|                    }
  613|    477|                    if (is_neg) {
  ------------------
  |  Branch (613:25): [True: 246, False: 231]
  ------------------
  614|    246|                        dval -= frac;
  615|    246|                    } else {
  616|    231|                        dval += frac;
  617|    231|                    }
  618|    477|                }
  619|  2.35k|                if (fendp >= str_end) {
  ------------------
  |  Branch (619:21): [True: 441, False: 1.91k]
  ------------------
  620|    441|                    break;
  621|    441|                }
  622|  1.91k|                if (fendp+1 < str_end && (*fendp == 'e' || *fendp == 'E') && (isdigit(*(fendp+1)) || (((*(fendp+1) == '-') || (*(fendp+1) == '+')) && fendp+2 < str_end && isdigit(*(fendp+2))))) {
  ------------------
  |  Branch (622:21): [True: 1.91k, False: 2]
  |  Branch (622:43): [True: 1.48k, False: 425]
  |  Branch (622:60): [True: 412, False: 13]
  |  Branch (622:79): [True: 748, False: 1.15k]
  |  Branch (622:104): [True: 875, False: 276]
  |  Branch (622:127): [True: 265, False: 11]
  |  Branch (622:151): [True: 1.13k, False: 2]
  |  Branch (622:172): [True: 1.13k, False: 1]
  ------------------
  623|  1.88k|                    int64_t exp = parse_decimal(fendp+1, str_end, &fendp);
  624|  1.88k|                    dval = dval * pow(10, (double)exp);
  625|  1.88k|                } else {
  626|     29|                    PLIST_JSON_ERR("%s: invalid character at offset %d when parsing floating point value\n", __func__, (int)(fendp - js));
  ------------------
  |  |   48|     29|#define PLIST_JSON_ERR(...) if (plist_json_debug) { fprintf(stderr, "libplist[jsonparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (48:33): [True: 0, False: 29]
  |  |  ------------------
  ------------------
  627|     29|                    err++;
  628|     29|                }
  629|  1.91k|            } while (0);
  ------------------
  |  Branch (629:22): [Folded, False: 1.91k]
  ------------------
  630|  2.35k|            if (!err) {
  ------------------
  |  Branch (630:17): [True: 2.32k, False: 29]
  ------------------
  631|  2.32k|                if (isinf(dval) || isnan(dval)) {
  ------------------
  |  Branch (631:21): [True: 132, False: 2.19k]
  |  Branch (631:36): [True: 20, False: 2.17k]
  ------------------
  632|    152|                   PLIST_JSON_ERR("%s: unrepresentable floating point value at offset %d when parsing numerical value\n", __func__, (int)(str_val - js));
  ------------------
  |  |   48|    152|#define PLIST_JSON_ERR(...) if (plist_json_debug) { fprintf(stderr, "libplist[jsonparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (48:33): [True: 0, False: 152]
  |  |  ------------------
  ------------------
  633|  2.17k|                } else {
  634|  2.17k|                    val = plist_new_real(dval);
  635|  2.17k|                }
  636|  2.32k|            }
  637|  2.35k|        } else {
  638|     60|            PLIST_JSON_ERR("%s: invalid character at offset %d when parsing numerical value\n", __func__, (int)(endp - js));
  ------------------
  |  |   48|     60|#define PLIST_JSON_ERR(...) if (plist_json_debug) { fprintf(stderr, "libplist[jsonparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (48:33): [True: 0, False: 60]
  |  |  ------------------
  ------------------
  639|     60|        }
  640|  6.57k|    } else {
  641|    158|        PLIST_JSON_ERR("%s: invalid primitive value '%.*s' encountered\n", __func__, (int)str_len, str_val);
  ------------------
  |  |   48|    158|#define PLIST_JSON_ERR(...) if (plist_json_debug) { fprintf(stderr, "libplist[jsonparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (48:33): [True: 0, False: 158]
  |  |  ------------------
  ------------------
  642|    158|    }
  643|  29.4k|    if (!val) {
  ------------------
  |  Branch (643:9): [True: 399, False: 29.0k]
  ------------------
  644|    399|        PLIST_JSON_ERR("%s: failed to create node\n", __func__);
  ------------------
  |  |   48|    399|#define PLIST_JSON_ERR(...) if (plist_json_debug) { fprintf(stderr, "libplist[jsonparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (48:33): [True: 0, False: 399]
  |  |  ------------------
  ------------------
  645|    399|        return NULL;
  646|    399|    }
  647|  29.0k|    (*index)++;
  648|  29.0k|    return val;
  649|  29.4k|}
jplist.c:parse_decimal:
  517|  8.45k|{
  518|  8.45k|    const uint64_t po10i_limit = INT64_MAX / 10;
  519|  8.45k|    uint64_t MAX = INT64_MAX;
  520|  8.45k|    uint64_t x = 0;
  521|  8.45k|    int is_neg = 0;
  522|  8.45k|    *endp = (char*)str;
  523|       |
  524|  8.45k|    if (str[0] == '-') {
  ------------------
  |  Branch (524:9): [True: 1.65k, False: 6.80k]
  ------------------
  525|  1.65k|        is_neg = 1;
  526|  1.65k|        (*endp)++;
  527|  6.80k|    } else if (str[0] == '+') {
  ------------------
  |  Branch (527:16): [True: 263, False: 6.53k]
  ------------------
  528|    263|        (*endp)++;
  529|    263|    }
  530|  8.45k|    if (is_neg) {
  ------------------
  |  Branch (530:9): [True: 1.65k, False: 6.80k]
  ------------------
  531|  1.65k|        MAX++;
  532|  1.65k|    }
  533|  41.8k|    while (*endp < str_end && isdigit(**endp)) {
  ------------------
  |  Branch (533:12): [True: 37.0k, False: 4.83k]
  |  Branch (533:31): [True: 34.5k, False: 2.44k]
  ------------------
  534|  34.5k|        if (x > po10i_limit) {
  ------------------
  |  Branch (534:13): [True: 636, False: 33.9k]
  ------------------
  535|    636|            x = MAX;
  536|    636|            break;
  537|    636|        }
  538|  33.9k|        x = x * 10;
  539|  33.9k|        unsigned int add = (**endp - '0');
  540|  33.9k|        if (x + add > MAX) {
  ------------------
  |  Branch (540:13): [True: 534, False: 33.4k]
  ------------------
  541|    534|            x = MAX;
  542|    534|            break;
  543|    534|        }
  544|  33.4k|        x += add;
  545|  33.4k|        (*endp)++;
  546|  33.4k|    }
  547|       |
  548|       |    // swallow the rest of the digits in case we dropped out early
  549|  10.1k|    while (*endp < str_end && isdigit(**endp)) (*endp)++;
  ------------------
  |  Branch (549:12): [True: 4.15k, False: 6.00k]
  |  Branch (549:31): [True: 1.70k, False: 2.45k]
  ------------------
  550|       |
  551|  8.45k|    int64_t result = x;
  552|  8.45k|    if (is_neg) {
  ------------------
  |  Branch (552:9): [True: 1.65k, False: 6.80k]
  ------------------
  553|  1.65k|        if (x == MAX) {
  ------------------
  |  Branch (553:13): [True: 756, False: 899]
  ------------------
  554|    756|            result = INT64_MIN;
  555|    899|        } else {
  556|    899|            result = -(int64_t)x;
  557|    899|        }
  558|  1.65k|    }
  559|  8.45k|    return result;
  560|  8.45k|}
jplist.c:parse_string:
  731|  35.2k|{
  732|  35.2k|    if (ti->tokens[*index].type != JSMN_STRING) {
  ------------------
  |  Branch (732:9): [True: 0, False: 35.2k]
  ------------------
  733|      0|        PLIST_JSON_ERR("%s: token type != JSMN_STRING\n", __func__);
  ------------------
  |  |   48|      0|#define PLIST_JSON_ERR(...) if (plist_json_debug) { fprintf(stderr, "libplist[jsonparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (48:33): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  734|      0|        return NULL;
  735|      0|    }
  736|       |
  737|  35.2k|    size_t str_len = 0; ;
  738|  35.2k|    char* strval = unescape_string(js + ti->tokens[*index].start, ti->tokens[*index].end - ti->tokens[*index].start, &str_len);
  739|  35.2k|    if (!strval) {
  ------------------
  |  Branch (739:9): [True: 19, False: 35.1k]
  ------------------
  740|     19|        return NULL;
  741|     19|    }
  742|  35.1k|    plist_t node;
  743|       |
  744|  35.1k|    plist_data_t data = plist_new_plist_data();
  745|  35.1k|    if (!data) {
  ------------------
  |  Branch (745:9): [True: 0, False: 35.1k]
  ------------------
  746|      0|        free(strval);
  747|      0|        PLIST_JSON_ERR("%s: failed to allocate plist data\n", __func__);
  ------------------
  |  |   48|      0|#define PLIST_JSON_ERR(...) if (plist_json_debug) { fprintf(stderr, "libplist[jsonparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (48:33): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  748|      0|        return NULL;
  749|      0|    }
  750|  35.1k|    data->type = PLIST_STRING;
  751|  35.1k|    data->strval = strval;
  752|  35.1k|    data->length = str_len;
  753|  35.1k|    node = plist_new_node(data);
  754|  35.1k|    if (!node) {
  ------------------
  |  Branch (754:9): [True: 0, False: 35.1k]
  ------------------
  755|      0|        plist_free_data(data);
  756|      0|        PLIST_JSON_ERR("%s: failed to create node\n", __func__);
  ------------------
  |  |   48|      0|#define PLIST_JSON_ERR(...) if (plist_json_debug) { fprintf(stderr, "libplist[jsonparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (48:33): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  757|      0|        return NULL;
  758|      0|    }
  759|       |
  760|  35.1k|    (*index)++;
  761|  35.1k|    return node;
  762|  35.1k|}
jplist.c:unescape_string:
  652|   102k|{
  653|   102k|    char* strval = strndup(str_val, str_len);
  654|   102k|    if (!strval) return NULL;
  ------------------
  |  Branch (654:9): [True: 0, False: 102k]
  ------------------
  655|   102k|    size_t i = 0;
  656|   242k|    while (i < str_len) {
  ------------------
  |  Branch (656:12): [True: 139k, False: 102k]
  ------------------
  657|   139k|        if (strval[i] == '\\' && i < str_len-1) {
  ------------------
  |  Branch (657:13): [True: 3.20k, False: 136k]
  |  Branch (657:34): [True: 3.20k, False: 0]
  ------------------
  658|  3.20k|            switch (strval[i+1]) {
  659|  1.20k|                case '\"': case '/' : case '\\' : case 'b' :
  ------------------
  |  Branch (659:17): [True: 212, False: 2.99k]
  |  Branch (659:28): [True: 392, False: 2.81k]
  |  Branch (659:39): [True: 279, False: 2.92k]
  |  Branch (659:51): [True: 320, False: 2.88k]
  ------------------
  660|  2.19k|                case 'f' : case 'r' : case 'n'  : case 't' :
  ------------------
  |  Branch (660:17): [True: 242, False: 2.96k]
  |  Branch (660:28): [True: 250, False: 2.95k]
  |  Branch (660:39): [True: 233, False: 2.97k]
  |  Branch (660:51): [True: 262, False: 2.94k]
  ------------------
  661|  2.19k|                    memmove(strval+i, strval+i+1, str_len - (i+1));
  662|  2.19k|                    str_len--;
  663|  2.19k|                    switch (strval[i]) {
  664|    320|                        case 'b':
  ------------------
  |  Branch (664:25): [True: 320, False: 1.87k]
  ------------------
  665|    320|                            strval[i] = '\b';
  666|    320|                            break;
  667|    242|                        case 'f':
  ------------------
  |  Branch (667:25): [True: 242, False: 1.94k]
  ------------------
  668|    242|                            strval[i] = '\f';
  669|    242|                            break;
  670|    250|                        case 'r':
  ------------------
  |  Branch (670:25): [True: 250, False: 1.94k]
  ------------------
  671|    250|                            strval[i] = '\r';
  672|    250|                            break;
  673|    233|                        case 'n':
  ------------------
  |  Branch (673:25): [True: 233, False: 1.95k]
  ------------------
  674|    233|                            strval[i] = '\n';
  675|    233|                            break;
  676|    262|                        case 't':
  ------------------
  |  Branch (676:25): [True: 262, False: 1.92k]
  ------------------
  677|    262|                            strval[i] = '\t';
  678|    262|                            break;
  679|    883|                        default:
  ------------------
  |  Branch (679:25): [True: 883, False: 1.30k]
  ------------------
  680|    883|                            break;
  681|  2.19k|                    }
  682|  2.19k|                    break;
  683|  2.19k|                case 'u': {
  ------------------
  |  Branch (683:17): [True: 1.01k, False: 2.19k]
  ------------------
  684|  1.01k|                    unsigned int val = 0;
  685|  1.01k|                    if (str_len-(i+2) < 4) {
  ------------------
  |  Branch (685:25): [True: 7, False: 1.00k]
  ------------------
  686|      7|                        PLIST_JSON_ERR("%s: invalid escape sequence '%s' (too short)\n", __func__, strval+i);
  ------------------
  |  |   48|      7|#define PLIST_JSON_ERR(...) if (plist_json_debug) { fprintf(stderr, "libplist[jsonparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (48:33): [True: 0, False: 7]
  |  |  ------------------
  ------------------
  687|      7|                        free(strval);
  688|      7|                        return NULL;
  689|      7|                    }
  690|  1.00k|                    if (!(isxdigit(strval[i+2]) && isxdigit(strval[i+3]) && isxdigit(strval[i+4]) && isxdigit(strval[i+5])) || sscanf(strval+i+2, "%04x", &val) != 1) {
  ------------------
  |  Branch (690:27): [True: 1.00k, False: 4]
  |  Branch (690:52): [True: 1.00k, False: 3]
  |  Branch (690:77): [True: 997, False: 3]
  |  Branch (690:102): [True: 994, False: 3]
  |  Branch (690:128): [True: 0, False: 994]
  ------------------
  691|     13|                        PLIST_JSON_ERR("%s: invalid escape sequence '%.*s'\n", __func__, 6, strval+i);
  ------------------
  |  |   48|     13|#define PLIST_JSON_ERR(...) if (plist_json_debug) { fprintf(stderr, "libplist[jsonparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (48:33): [True: 0, False: 13]
  |  |  ------------------
  ------------------
  692|     13|                        free(strval);
  693|     13|                        return NULL;
  694|     13|                    }
  695|    994|                    int bytelen = 0;
  696|    994|                    if (val >= 0x800) {
  ------------------
  |  Branch (696:25): [True: 247, False: 747]
  ------------------
  697|       |                        /* three bytes */
  698|    247|                        strval[i]   = (char)(0xE0 + ((val >> 12) & 0xF));
  699|    247|                        strval[i+1] = (char)(0x80 + ((val >> 6) & 0x3F));
  700|    247|                        strval[i+2] = (char)(0x80 + (val & 0x3F));
  701|    247|                        bytelen = 3;
  702|    747|                    } else if (val >= 0x80) {
  ------------------
  |  Branch (702:32): [True: 393, False: 354]
  ------------------
  703|       |                        /* two bytes */
  704|    393|                        strval[i]   = (char)(0xC0 + ((val >> 6) & 0x1F));
  705|    393|                        strval[i+1] = (char)(0x80 + (val & 0x3F));
  706|    393|                        bytelen = 2;
  707|    393|                    } else {
  708|       |                        /* one byte */
  709|    354|                        strval[i] = (char)(val & 0x7F);
  710|    354|                        bytelen = 1;
  711|    354|                    }
  712|    994|                    memmove(strval+i+bytelen, strval+i+6, str_len - (i+5));
  713|    994|                    str_len -= (6-bytelen);
  714|    994|                }   break;
  715|      0|                default:
  ------------------
  |  Branch (715:17): [True: 0, False: 3.20k]
  ------------------
  716|      0|                    PLIST_JSON_ERR("%s: invalid escape sequence '%.*s'\n", __func__, 2, strval+i);
  ------------------
  |  |   48|      0|#define PLIST_JSON_ERR(...) if (plist_json_debug) { fprintf(stderr, "libplist[jsonparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (48:33): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  717|      0|                    free(strval);
  718|      0|                    return NULL;
  719|  3.20k|            }
  720|  3.20k|        }
  721|   139k|        i++;
  722|   139k|    }
  723|   102k|    strval[str_len] = '\0';
  724|   102k|    if (new_len) {
  ------------------
  |  Branch (724:9): [True: 35.1k, False: 67.7k]
  ------------------
  725|  35.1k|        *new_len = str_len;
  726|  35.1k|    }
  727|   102k|    return strval;
  728|   102k|}
jplist.c:parse_array:
  767|  53.2k|{
  768|  53.2k|    if (ti->tokens[*index].type != JSMN_ARRAY) {
  ------------------
  |  Branch (768:9): [True: 0, False: 53.2k]
  ------------------
  769|      0|        PLIST_JSON_ERR("%s: token type != JSMN_ARRAY\n", __func__);
  ------------------
  |  |   48|      0|#define PLIST_JSON_ERR(...) if (plist_json_debug) { fprintf(stderr, "libplist[jsonparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (48:33): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  770|      0|        ti->err = PLIST_ERR_PARSE;
  771|      0|        return NULL;
  772|      0|    }
  773|  53.2k|    if (depth > PLIST_MAX_NESTING_DEPTH) {
  ------------------
  |  |   68|  53.2k|#define PLIST_MAX_NESTING_DEPTH NODE_MAX_DEPTH
  |  |  ------------------
  |  |  |  |   32|  53.2k|#define NODE_MAX_DEPTH 512
  |  |  ------------------
  ------------------
  |  Branch (773:9): [True: 1, False: 53.2k]
  ------------------
  774|      1|        PLIST_JSON_ERR("%s: maximum nesting depth (%u) exceeded\n", __func__, (unsigned)PLIST_MAX_NESTING_DEPTH);
  ------------------
  |  |   48|      1|#define PLIST_JSON_ERR(...) if (plist_json_debug) { fprintf(stderr, "libplist[jsonparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (48:33): [True: 0, False: 1]
  |  |  ------------------
  ------------------
  775|      1|        ti->err = PLIST_ERR_MAX_NESTING;
  776|      1|        return NULL;
  777|      1|    }
  778|  53.2k|    plist_t arr = plist_new_array();
  779|  53.2k|    if (!arr) {
  ------------------
  |  Branch (779:9): [True: 0, False: 53.2k]
  ------------------
  780|      0|        PLIST_JSON_ERR("%s: failed to create array node\n", __func__);
  ------------------
  |  |   48|      0|#define PLIST_JSON_ERR(...) if (plist_json_debug) { fprintf(stderr, "libplist[jsonparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (48:33): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  781|      0|        ti->err = PLIST_ERR_NO_MEM;
  782|      0|        return NULL;
  783|      0|    }
  784|  53.2k|    size_t num_tokens = ti->tokens[*index].size;
  785|  53.2k|    size_t num;
  786|  53.2k|    int j = (*index)+1;
  787|   110k|    for (num = 0; num < num_tokens; num++) {
  ------------------
  |  Branch (787:19): [True: 60.2k, False: 50.4k]
  ------------------
  788|  60.2k|        if (j >= ti->count) {
  ------------------
  |  Branch (788:13): [True: 0, False: 60.2k]
  ------------------
  789|      0|            PLIST_JSON_ERR("%s: token index out of valid range\n", __func__);
  ------------------
  |  |   48|      0|#define PLIST_JSON_ERR(...) if (plist_json_debug) { fprintf(stderr, "libplist[jsonparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (48:33): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  790|      0|            plist_free(arr);
  791|      0|            ti->err = PLIST_ERR_PARSE;
  792|      0|            return NULL;
  793|      0|        }
  794|  60.2k|        plist_t val = NULL;
  795|  60.2k|        switch (ti->tokens[j].type) {
  796|    377|            case JSMN_OBJECT:
  ------------------
  |  Branch (796:13): [True: 377, False: 59.8k]
  ------------------
  797|    377|                val = parse_object(js, ti, &j, depth+1);
  798|    377|                break;
  799|  31.7k|            case JSMN_ARRAY:
  ------------------
  |  Branch (799:13): [True: 31.7k, False: 28.4k]
  ------------------
  800|  31.7k|                val = parse_array(js, ti, &j, depth+1);
  801|  31.7k|                break;
  802|  1.25k|            case JSMN_STRING:
  ------------------
  |  Branch (802:13): [True: 1.25k, False: 59.0k]
  ------------------
  803|  1.25k|                val = parse_string(js, ti, &j);
  804|  1.25k|                break;
  805|  26.8k|            case JSMN_PRIMITIVE:
  ------------------
  |  Branch (805:13): [True: 26.8k, False: 33.4k]
  ------------------
  806|  26.8k|                val = parse_primitive(js, ti, &j);
  807|  26.8k|                break;
  808|      0|            default:
  ------------------
  |  Branch (808:13): [True: 0, False: 60.2k]
  ------------------
  809|      0|                break;
  810|  60.2k|        }
  811|  60.2k|        if (val) {
  ------------------
  |  Branch (811:13): [True: 57.4k, False: 2.81k]
  ------------------
  812|  57.4k|            plist_array_append_item(arr, val);
  813|       |            // if append failed, val still has no parent, free it and abort
  814|  57.4k|            if (((node_t)val)->parent == NULL) {
  ------------------
  |  Branch (814:17): [True: 2, False: 57.4k]
  ------------------
  815|      2|                plist_free(val);
  816|      2|                plist_free(arr);
  817|      2|                ti->err = PLIST_ERR_NO_MEM;
  818|      2|                return NULL;
  819|      2|            }
  820|  57.4k|        } else {
  821|  2.81k|            plist_free(arr);
  822|  2.81k|            ti->err = PLIST_ERR_PARSE;
  823|  2.81k|            return NULL;
  824|  2.81k|        }
  825|  60.2k|    }
  826|  50.4k|    *(index) = j;
  827|  50.4k|    return arr;
  828|  53.2k|}
jplist.c:parse_object:
  831|  12.0k|{
  832|  12.0k|    if (ti->tokens[*index].type != JSMN_OBJECT) {
  ------------------
  |  Branch (832:9): [True: 0, False: 12.0k]
  ------------------
  833|      0|        PLIST_JSON_ERR("%s: token type != JSMN_OBJECT\n", __func__);
  ------------------
  |  |   48|      0|#define PLIST_JSON_ERR(...) if (plist_json_debug) { fprintf(stderr, "libplist[jsonparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (48:33): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  834|      0|        ti->err = PLIST_ERR_PARSE;
  835|      0|        return NULL;
  836|      0|    }
  837|  12.0k|    if (depth > PLIST_MAX_NESTING_DEPTH) {
  ------------------
  |  |   68|  12.0k|#define PLIST_MAX_NESTING_DEPTH NODE_MAX_DEPTH
  |  |  ------------------
  |  |  |  |   32|  12.0k|#define NODE_MAX_DEPTH 512
  |  |  ------------------
  ------------------
  |  Branch (837:9): [True: 1, False: 12.0k]
  ------------------
  838|      1|        PLIST_JSON_ERR("%s: maximum nesting depth (%u) exceeded\n", __func__, (unsigned)PLIST_MAX_NESTING_DEPTH);
  ------------------
  |  |   48|      1|#define PLIST_JSON_ERR(...) if (plist_json_debug) { fprintf(stderr, "libplist[jsonparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (48:33): [True: 0, False: 1]
  |  |  ------------------
  ------------------
  839|      1|        ti->err = PLIST_ERR_MAX_NESTING;
  840|      1|        return NULL;
  841|      1|    }
  842|  12.0k|    size_t num_tokens = ti->tokens[*index].size;
  843|  12.0k|    size_t num;
  844|  12.0k|    int j = (*index)+1;
  845|  12.0k|    if (num_tokens % 2 != 0) {
  ------------------
  |  Branch (845:9): [True: 14, False: 12.0k]
  ------------------
  846|     14|        PLIST_JSON_ERR("%s: number of children must be even\n", __func__);
  ------------------
  |  |   48|     14|#define PLIST_JSON_ERR(...) if (plist_json_debug) { fprintf(stderr, "libplist[jsonparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (48:33): [True: 0, False: 14]
  |  |  ------------------
  ------------------
  847|     14|        ti->err = PLIST_ERR_PARSE;
  848|     14|        return NULL;
  849|     14|    }
  850|  12.0k|    plist_t obj = plist_new_dict();
  851|  12.0k|    if (!obj) {
  ------------------
  |  Branch (851:9): [True: 0, False: 12.0k]
  ------------------
  852|      0|        PLIST_JSON_ERR("%s: failed to create dict node\n", __func__);
  ------------------
  |  |   48|      0|#define PLIST_JSON_ERR(...) if (plist_json_debug) { fprintf(stderr, "libplist[jsonparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (48:33): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  853|      0|        ti->err = PLIST_ERR_NO_MEM;
  854|      0|        return NULL;
  855|      0|    }
  856|  79.5k|    for (num = 0; num < num_tokens; num++) {
  ------------------
  |  Branch (856:19): [True: 67.7k, False: 11.8k]
  ------------------
  857|  67.7k|        if (j+1 >= ti->count) {
  ------------------
  |  Branch (857:13): [True: 0, False: 67.7k]
  ------------------
  858|      0|            PLIST_JSON_ERR("%s: token index out of valid range\n", __func__);
  ------------------
  |  |   48|      0|#define PLIST_JSON_ERR(...) if (plist_json_debug) { fprintf(stderr, "libplist[jsonparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (48:33): [True: 0, False: 0]
  |  |  ------------------
  ------------------
  859|      0|            plist_free(obj);
  860|      0|            ti->err = PLIST_ERR_PARSE;
  861|      0|            return NULL;
  862|      0|        }
  863|  67.7k|        if (ti->tokens[j].type == JSMN_STRING) {
  ------------------
  |  Branch (863:13): [True: 67.7k, False: 5]
  ------------------
  864|  67.7k|            char* key = unescape_string(js + ti->tokens[j].start, ti->tokens[j].end - ti->tokens[j].start, NULL);
  865|  67.7k|            if (!key) {
  ------------------
  |  Branch (865:17): [True: 1, False: 67.7k]
  ------------------
  866|      1|                plist_free(obj);
  867|      1|                ti->err = PLIST_ERR_PARSE;
  868|      1|                return NULL;
  869|      1|            }
  870|  67.7k|            plist_t val = NULL;
  871|  67.7k|            j++;
  872|  67.7k|            num++;
  873|  67.7k|            switch (ti->tokens[j].type) {
  874|  11.0k|                case JSMN_OBJECT:
  ------------------
  |  Branch (874:17): [True: 11.0k, False: 56.6k]
  ------------------
  875|  11.0k|                    val = parse_object(js, ti, &j, depth+1);
  876|  11.0k|                    break;
  877|  21.0k|                case JSMN_ARRAY:
  ------------------
  |  Branch (877:17): [True: 21.0k, False: 46.7k]
  ------------------
  878|  21.0k|                    val = parse_array(js, ti, &j, depth+1);
  879|  21.0k|                    break;
  880|  33.7k|                case JSMN_STRING:
  ------------------
  |  Branch (880:17): [True: 33.7k, False: 33.9k]
  ------------------
  881|  33.7k|                    val = parse_string(js, ti, &j);
  882|  33.7k|                    break;
  883|  1.86k|                case JSMN_PRIMITIVE:
  ------------------
  |  Branch (883:17): [True: 1.86k, False: 65.8k]
  ------------------
  884|  1.86k|                    val = parse_primitive(js, ti, &j);
  885|  1.86k|                    break;
  886|      0|                default:
  ------------------
  |  Branch (886:17): [True: 0, False: 67.7k]
  ------------------
  887|      0|                    break;
  888|  67.7k|            }
  889|  67.7k|            if (val) {
  ------------------
  |  Branch (889:17): [True: 67.5k, False: 202]
  ------------------
  890|  67.5k|                plist_dict_set_item(obj, key, val);
  891|       |                // if set failed, val still has no parent, free it and abort
  892|  67.5k|                if (((node_t)val)->parent == NULL) {
  ------------------
  |  Branch (892:21): [True: 4, False: 67.5k]
  ------------------
  893|      4|                    plist_free(val);
  894|      4|                    free(key);
  895|      4|                    plist_free(obj);
  896|      4|                    ti->err = PLIST_ERR_NO_MEM;
  897|      4|                    return NULL;
  898|      4|                }
  899|  67.5k|            } else {
  900|    202|                free(key);
  901|    202|                plist_free(obj);
  902|    202|                ti->err = PLIST_ERR_PARSE;
  903|    202|                return NULL;
  904|    202|            }
  905|  67.5k|            free(key);
  906|  67.5k|        } else {
  907|      5|            PLIST_JSON_ERR("%s: keys must be of type STRING\n", __func__);
  ------------------
  |  |   48|      5|#define PLIST_JSON_ERR(...) if (plist_json_debug) { fprintf(stderr, "libplist[jsonparser] ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (48:33): [True: 0, False: 5]
  |  |  ------------------
  ------------------
  908|      5|            plist_free(obj);
  909|      5|            ti->err = PLIST_ERR_PARSE;
  910|      5|            return NULL;
  911|      5|        }
  912|  67.7k|    }
  913|  11.8k|    (*index) = j;
  914|  11.8k|    return obj;
  915|  12.0k|}

jsmn_parse:
  173|  12.8k|		unsigned int num_tokens) {
  174|  12.8k|	jsmnerr_t r;
  175|  12.8k|	int i;
  176|  12.8k|	jsmntok_t *token;
  177|       |
  178|  12.8k|	parser->end = length;
  179|       |
  180|  12.8k|	if (num_tokens >= INT_MAX) {
  ------------------
  |  Branch (180:6): [True: 0, False: 12.8k]
  ------------------
  181|      0|		return JSMN_ERROR_LIMIT;
  182|      0|	}
  183|  12.8k|	if (length > SIZE_MAX / 2) {
  ------------------
  |  Branch (183:6): [True: 0, False: 12.8k]
  ------------------
  184|      0|		return JSMN_ERROR_LIMIT;
  185|      0|	}
  186|       |
  187|   421k|	for (; (parser->end > 0 && parser->pos < parser->end) && js[parser->pos] != '\0'; parser->pos++) {
  ------------------
  |  Branch (187:10): [True: 421k, False: 0]
  |  Branch (187:29): [True: 419k, False: 2.09k]
  |  Branch (187:59): [True: 419k, False: 4]
  ------------------
  188|   419k|		char c;
  189|   419k|		jsmntype_t type;
  190|       |
  191|   419k|		c = js[parser->pos];
  192|   419k|		switch (c) {
  193|   164k|			case '{': case '[':
  ------------------
  |  Branch (193:4): [True: 51.7k, False: 367k]
  |  Branch (193:14): [True: 112k, False: 306k]
  ------------------
  194|   164k|				token = jsmn_alloc_token(parser, tokens, num_tokens);
  195|   164k|				if (token == NULL)
  ------------------
  |  Branch (195:9): [True: 6.87k, False: 157k]
  ------------------
  196|  6.87k|					return JSMN_ERROR_NOMEM;
  197|   157k|				if (parser->toksuper != -1) {
  ------------------
  |  Branch (197:9): [True: 151k, False: 6.61k]
  ------------------
  198|   151k|					tokens[parser->toksuper].size++;
  199|       |#ifdef JSMN_PARENT_LINKS
  200|       |					token->parent = parser->toksuper;
  201|       |#endif
  202|   151k|				}
  203|   157k|				token->type = (c == '{' ? JSMN_OBJECT : JSMN_ARRAY);
  ------------------
  |  Branch (203:20): [True: 48.9k, False: 108k]
  ------------------
  204|   157k|				token->start = parser->pos;
  205|   157k|				parser->toksuper = parser->toknext - 1;
  206|   157k|				break;
  207|  72.1k|			case '}': case ']':
  ------------------
  |  Branch (207:4): [True: 17.5k, False: 402k]
  |  Branch (207:14): [True: 54.6k, False: 364k]
  ------------------
  208|  72.1k|				type = (c == '}' ? JSMN_OBJECT : JSMN_ARRAY);
  ------------------
  |  Branch (208:13): [True: 17.5k, False: 54.6k]
  ------------------
  209|       |#ifdef JSMN_PARENT_LINKS
  210|       |				if (parser->toknext < 1) {
  211|       |					return JSMN_ERROR_INVAL;
  212|       |				}
  213|       |				token = &tokens[parser->toknext - 1];
  214|       |				for (;;) {
  215|       |					if (token->start != JSMN_POS_INVALID && token->end == JSMN_POS_INVALID) {
  216|       |						if (token->type != type) {
  217|       |							return JSMN_ERROR_INVAL;
  218|       |						}
  219|       |						if (parser->pos == SIZE_MAX) {
  220|       |							return JSMN_ERROR_INVAL;
  221|       |						}
  222|       |						token->end = parser->pos + 1;
  223|       |						parser->toksuper = token->parent;
  224|       |						break;
  225|       |					}
  226|       |					if (token->parent == -1) {
  227|       |						break;
  228|       |					}
  229|       |					token = &tokens[token->parent];
  230|       |				}
  231|       |#else
  232|  6.18M|				for (i = parser->toknext - 1; i >= 0; i--) {
  ------------------
  |  Branch (232:35): [True: 6.18M, False: 38]
  ------------------
  233|  6.18M|					token = &tokens[i];
  234|  6.18M|					if (token->start != JSMN_POS_INVALID && token->end == JSMN_POS_INVALID) {
  ------------------
  |  |   35|  12.3M|#define JSMN_POS_INVALID ((size_t)SIZE_MAX)
  ------------------
              					if (token->start != JSMN_POS_INVALID && token->end == JSMN_POS_INVALID) {
  ------------------
  |  |   35|  6.18M|#define JSMN_POS_INVALID ((size_t)SIZE_MAX)
  ------------------
  |  Branch (234:10): [True: 6.18M, False: 0]
  |  Branch (234:46): [True: 72.1k, False: 6.10M]
  ------------------
  235|  72.1k|						if (token->type != type) {
  ------------------
  |  Branch (235:11): [True: 2, False: 72.1k]
  ------------------
  236|      2|							return JSMN_ERROR_INVAL;
  237|      2|						}
  238|  72.1k|						parser->toksuper = -1;
  239|  72.1k|						token->end = parser->pos + 1;
  240|  72.1k|						break;
  241|  72.1k|					}
  242|  6.18M|				}
  243|       |				/* Error if unmatched closing bracket */
  244|  72.1k|				if (i == -1) return JSMN_ERROR_INVAL;
  ------------------
  |  Branch (244:9): [True: 38, False: 72.1k]
  ------------------
  245|  26.7M|				for (; i >= 0; i--) {
  ------------------
  |  Branch (245:12): [True: 26.7M, False: 6.40k]
  ------------------
  246|  26.7M|					token = &tokens[i];
  247|  26.7M|					if (token->start != JSMN_POS_INVALID && token->end == JSMN_POS_INVALID) {
  ------------------
  |  |   35|  53.4M|#define JSMN_POS_INVALID ((size_t)SIZE_MAX)
  ------------------
              					if (token->start != JSMN_POS_INVALID && token->end == JSMN_POS_INVALID) {
  ------------------
  |  |   35|  26.7M|#define JSMN_POS_INVALID ((size_t)SIZE_MAX)
  ------------------
  |  Branch (247:10): [True: 26.7M, False: 0]
  |  Branch (247:46): [True: 65.7k, False: 26.6M]
  ------------------
  248|  65.7k|						parser->toksuper = i;
  249|  65.7k|						break;
  250|  65.7k|					}
  251|  26.7M|				}
  252|  72.1k|#endif
  253|  72.1k|				break;
  254|   114k|			case '\"':
  ------------------
  |  Branch (254:4): [True: 114k, False: 304k]
  ------------------
  255|   114k|				r = jsmn_parse_string(parser, js, tokens, num_tokens);
  256|   114k|				if (r < 0) return r;
  ------------------
  |  Branch (256:9): [True: 2.62k, False: 112k]
  ------------------
  257|   112k|				if (parser->toksuper != -1)
  ------------------
  |  Branch (257:9): [True: 111k, False: 413]
  ------------------
  258|   111k|					tokens[parser->toksuper].size++;
  259|   112k|				break;
  260|  34.6k|			case '\t' : case '\r' : case '\n' : case ':' : case ',': case ' ':
  ------------------
  |  Branch (260:4): [True: 1.36k, False: 418k]
  |  Branch (260:16): [True: 2.93k, False: 416k]
  |  Branch (260:28): [True: 12.6k, False: 406k]
  |  Branch (260:40): [True: 12.9k, False: 406k]
  |  Branch (260:51): [True: 3.70k, False: 415k]
  |  Branch (260:61): [True: 985, False: 418k]
  ------------------
  261|  34.6k|				break;
  262|       |#ifdef JSMN_STRICT
  263|       |			/* In strict mode primitives are: numbers and booleans */
  264|       |			case '-': case '0': case '1' : case '2': case '3' : case '4':
  265|       |			case '5': case '6': case '7' : case '8': case '9':
  266|       |			case 't': case 'f': case 'n' :
  267|       |#else
  268|       |			/* In non-strict mode every unquoted value is a primitive */
  269|  33.5k|			default:
  ------------------
  |  Branch (269:4): [True: 33.5k, False: 386k]
  ------------------
  270|  33.5k|#endif
  271|  33.5k|				r = jsmn_parse_primitive(parser, js, tokens, num_tokens);
  272|  33.5k|				if (r < 0) return r;
  ------------------
  |  Branch (272:9): [True: 1.20k, False: 32.3k]
  ------------------
  273|  32.3k|				if (parser->toksuper != -1)
  ------------------
  |  Branch (273:9): [True: 30.4k, False: 1.85k]
  ------------------
  274|  30.4k|					tokens[parser->toksuper].size++;
  275|  32.3k|				break;
  276|       |
  277|       |#ifdef JSMN_STRICT
  278|       |			/* Unexpected char in strict mode */
  279|       |			default:
  280|       |				return JSMN_ERROR_INVAL;
  281|       |#endif
  282|       |
  283|   419k|		}
  284|   419k|	}
  285|       |
  286|   213k|	for (i = parser->toknext - 1; i >= 0; i--) {
  ------------------
  |  Branch (286:32): [True: 211k, False: 1.91k]
  ------------------
  287|       |		/* Unmatched opened object or array */
  288|   211k|		if (tokens[i].start != JSMN_POS_INVALID && tokens[i].end == JSMN_POS_INVALID) {
  ------------------
  |  |   35|   422k|#define JSMN_POS_INVALID ((size_t)SIZE_MAX)
  ------------------
              		if (tokens[i].start != JSMN_POS_INVALID && tokens[i].end == JSMN_POS_INVALID) {
  ------------------
  |  |   35|   211k|#define JSMN_POS_INVALID ((size_t)SIZE_MAX)
  ------------------
  |  Branch (288:7): [True: 211k, False: 0]
  |  Branch (288:46): [True: 179, False: 211k]
  ------------------
  289|    179|			return JSMN_ERROR_PART;
  290|    179|		}
  291|   211k|	}
  292|       |
  293|  1.91k|	return JSMN_SUCCESS;
  294|  2.09k|}
jsmn_init:
  300|  2.28k|void jsmn_init(jsmn_parser *parser) {
  301|  2.28k|	parser->pos = 0;
  302|  2.28k|	parser->end = 0;
  303|  2.28k|	parser->toknext = 0;
  304|  2.28k|	parser->toksuper = -1;
  305|  2.28k|}
jsmn.c:jsmn_alloc_token:
   41|   312k|		jsmntok_t *tokens, unsigned int num_tokens) {
   42|   312k|	jsmntok_t *tok;
   43|   312k|	if ((unsigned int)parser->toknext >= num_tokens) {
  ------------------
  |  Branch (43:6): [True: 10.5k, False: 302k]
  ------------------
   44|  10.5k|		return NULL;
   45|  10.5k|	}
   46|   302k|	tok = &tokens[parser->toknext++];
   47|   302k|	tok->start = tok->end = JSMN_POS_INVALID;
  ------------------
  |  |   35|   302k|#define JSMN_POS_INVALID ((size_t)SIZE_MAX)
  ------------------
   48|   302k|	tok->size = 0;
   49|       |#ifdef JSMN_PARENT_LINKS
   50|       |	tok->parent = -1;
   51|       |#endif
   52|   302k|	return tok;
   53|   312k|}
jsmn.c:jsmn_parse_string:
  117|   114k|		jsmntok_t *tokens, unsigned int num_tokens) {
  118|   114k|	jsmntok_t *token;
  119|       |
  120|   114k|	size_t start = parser->pos;
  121|       |
  122|   114k|	parser->pos++;
  123|       |
  124|       |	/* Skip starting quote */
  125|   310k|	for (; (parser->end > 0 && parser->pos < parser->end) && js[parser->pos] != '\0'; parser->pos++) {
  ------------------
  |  Branch (125:10): [True: 310k, False: 0]
  |  Branch (125:29): [True: 310k, False: 117]
  |  Branch (125:59): [True: 310k, False: 2]
  ------------------
  126|   310k|		char c = js[parser->pos];
  127|       |
  128|       |		/* Quote: end of string */
  129|   310k|		if (c == '\"') {
  ------------------
  |  Branch (129:7): [True: 114k, False: 195k]
  ------------------
  130|   114k|			token = jsmn_alloc_token(parser, tokens, num_tokens);
  131|   114k|			if (token == NULL) {
  ------------------
  |  Branch (131:8): [True: 2.50k, False: 112k]
  ------------------
  132|  2.50k|				parser->pos = start;
  133|  2.50k|				return JSMN_ERROR_NOMEM;
  134|  2.50k|			}
  135|   112k|			jsmn_fill_token(token, JSMN_STRING, start+1, parser->pos);
  136|       |#ifdef JSMN_PARENT_LINKS
  137|       |			token->parent = parser->toksuper;
  138|       |#endif
  139|   112k|			return JSMN_SUCCESS;
  140|   114k|		}
  141|       |
  142|       |		/* Backslash: Quoted symbol expected */
  143|   195k|		if (c == '\\') {
  ------------------
  |  Branch (143:7): [True: 25.1k, False: 170k]
  ------------------
  144|  25.1k|			parser->pos++;
  145|  25.1k|			if (parser->end > 0 && parser->pos >= parser->end) {
  ------------------
  |  Branch (145:8): [True: 25.1k, False: 0]
  |  Branch (145:27): [True: 3, False: 25.1k]
  ------------------
  146|      3|				parser->pos = start;
  147|      3|				return JSMN_ERROR_INVAL;
  148|      3|			}
  149|  25.1k|			switch (js[parser->pos]) {
  150|       |				/* Allowed escaped symbols */
  151|  6.95k|				case '\"': case '/' : case '\\' : case 'b' :
  ------------------
  |  Branch (151:5): [True: 653, False: 24.5k]
  |  Branch (151:16): [True: 675, False: 24.4k]
  |  Branch (151:27): [True: 5.10k, False: 20.0k]
  |  Branch (151:39): [True: 524, False: 24.6k]
  ------------------
  152|  23.7k|				case 'f' : case 'r' : case 'n'  : case 't' :
  ------------------
  |  Branch (152:5): [True: 597, False: 24.5k]
  |  Branch (152:16): [True: 554, False: 24.6k]
  |  Branch (152:27): [True: 14.8k, False: 10.2k]
  |  Branch (152:39): [True: 715, False: 24.4k]
  ------------------
  153|  23.7k|					break;
  154|       |				/* Allows escaped symbol \uXXXX */
  155|  1.46k|				case 'u':
  ------------------
  |  Branch (155:5): [True: 1.46k, False: 23.7k]
  ------------------
  156|       |					/* TODO */
  157|  1.46k|					break;
  158|       |				/* Unexpected symbol */
  159|      2|				default:
  ------------------
  |  Branch (159:5): [True: 2, False: 25.1k]
  ------------------
  160|      2|					parser->pos = start;
  161|      2|					return JSMN_ERROR_INVAL;
  162|  25.1k|			}
  163|  25.1k|		}
  164|   195k|	}
  165|    119|	parser->pos = start;
  166|    119|	return JSMN_ERROR_PART;
  167|   114k|}
jsmn.c:jsmn_fill_token:
   59|   144k|                            size_t start, size_t end) {
   60|   144k|	token->type = type;
   61|   144k|	token->start = start;
   62|   144k|	token->end = end;
   63|   144k|	token->size = 0;
   64|   144k|}
jsmn.c:jsmn_parse_primitive:
   70|  33.5k|		jsmntok_t *tokens, unsigned int num_tokens) {
   71|  33.5k|	jsmntok_t *token;
   72|  33.5k|	size_t start;
   73|       |
   74|  33.5k|	start = parser->pos;
   75|       |
   76|   102k|	for (; (parser->end > 0 && parser->pos < parser->end) && js[parser->pos] != '\0'; parser->pos++) {
  ------------------
  |  Branch (76:10): [True: 102k, False: 0]
  |  Branch (76:29): [True: 102k, False: 665]
  |  Branch (76:59): [True: 102k, False: 1]
  ------------------
   77|   102k|		switch (js[parser->pos]) {
   78|      0|#ifndef JSMN_STRICT
   79|       |			/* In strict mode primitive must be followed by "," or "}" or "]" */
   80|  5.69k|			case ':':
  ------------------
  |  Branch (80:4): [True: 5.69k, False: 96.4k]
  ------------------
   81|  5.69k|#endif
   82|  22.7k|			case '\t' : case '\r' : case '\n' : case ' ' :
  ------------------
  |  Branch (82:4): [True: 621, False: 101k]
  |  Branch (82:16): [True: 2.74k, False: 99.4k]
  |  Branch (82:28): [True: 12.9k, False: 89.2k]
  |  Branch (82:40): [True: 783, False: 101k]
  ------------------
   83|  32.8k|			case ','  : case ']'  : case '}' :
  ------------------
  |  Branch (83:4): [True: 3.52k, False: 98.6k]
  |  Branch (83:16): [True: 5.60k, False: 96.5k]
  |  Branch (83:28): [True: 951, False: 101k]
  ------------------
   84|  32.8k|				goto found;
   85|  69.3k|			default:
  ------------------
  |  Branch (85:4): [True: 69.3k, False: 32.8k]
  ------------------
   86|  69.3k|				break;
   87|   102k|		}
   88|  69.3k|		if (js[parser->pos] < 32 || js[parser->pos] >= 127) {
  ------------------
  |  Branch (88:7): [True: 23, False: 69.3k]
  |  Branch (88:31): [True: 1, False: 69.3k]
  ------------------
   89|     24|			parser->pos = start;
   90|     24|			return JSMN_ERROR_INVAL;
   91|     24|		}
   92|  69.3k|	}
   93|       |#ifdef JSMN_STRICT
   94|       |	/* In strict mode primitive must be followed by a comma/object/array */
   95|       |	parser->pos = start;
   96|       |	return JSMN_ERROR_PART;
   97|       |#endif
   98|       |
   99|  33.4k|found:
  100|  33.4k|	token = jsmn_alloc_token(parser, tokens, num_tokens);
  101|  33.4k|	if (token == NULL) {
  ------------------
  |  Branch (101:6): [True: 1.18k, False: 32.3k]
  ------------------
  102|  1.18k|		parser->pos = start;
  103|  1.18k|		return JSMN_ERROR_NOMEM;
  104|  1.18k|	}
  105|  32.3k|	jsmn_fill_token(token, JSMN_PRIMITIVE, start, parser->pos);
  106|       |#ifdef JSMN_PARENT_LINKS
  107|       |	token->parent = parser->toksuper;
  108|       |#endif
  109|  32.3k|	parser->pos--;
  110|  32.3k|	return JSMN_SUCCESS;
  111|  33.4k|}

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.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|   192k|{
  349|       |    return (plist_t) node_create(NULL, data);
  350|   192k|}
plist_get_data:
  363|  23.2M|{
  364|  23.2M|    if (!node)
  ------------------
  |  Branch (364:9): [True: 0, False: 23.2M]
  ------------------
  365|      0|        return NULL;
  366|  23.2M|    return (plist_data_t)((node_t)node)->data;
  367|  23.2M|}
plist_new_plist_data:
  370|   192k|{
  371|   192k|    return (plist_data_t) calloc(1, sizeof(struct plist_data_s));
  372|   192k|}
plist_free_data:
  431|   192k|{
  432|   192k|    if (!data) return;
  ------------------
  |  Branch (432:9): [True: 0, False: 192k]
  ------------------
  433|   192k|    _plist_free_data(data);
  434|   192k|    free(data);
  435|   192k|}
plist_new_dict:
  497|  12.0k|{
  498|  12.0k|    plist_data_t data = plist_new_plist_data();
  499|  12.0k|    if (!data) {
  ------------------
  |  Branch (499:9): [True: 0, False: 12.0k]
  ------------------
  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|  12.0k|    data->type = PLIST_DICT;
  504|  12.0k|    return plist_new_node_or_free(data);
  505|  12.0k|}
plist_new_array:
  508|  53.2k|{
  509|  53.2k|    plist_data_t data = plist_new_plist_data();
  510|  53.2k|    if (!data) {
  ------------------
  |  Branch (510:9): [True: 0, False: 53.2k]
  ------------------
  511|      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]
  |  |  ------------------
  ------------------
  512|      0|        return NULL;
  513|      0|    }
  514|  53.2k|    data->type = PLIST_ARRAY;
  515|  53.2k|    return plist_new_node_or_free(data);
  516|  53.2k|}
plist_new_bool:
  558|  8.54k|{
  559|  8.54k|    plist_data_t data = plist_new_plist_data();
  560|  8.54k|    if (!data) {
  ------------------
  |  Branch (560:9): [True: 0, False: 8.54k]
  ------------------
  561|      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]
  |  |  ------------------
  ------------------
  562|      0|        return NULL;
  563|      0|    }
  564|  8.54k|    data->type = PLIST_BOOLEAN;
  565|  8.54k|    data->boolval = val;
  566|  8.54k|    data->length = sizeof(uint8_t);
  567|  8.54k|    return plist_new_node_or_free(data);
  568|  8.54k|}
plist_new_int:
  584|  4.15k|{
  585|  4.15k|    plist_data_t data = plist_new_plist_data();
  586|  4.15k|    if (!data) {
  ------------------
  |  Branch (586:9): [True: 0, False: 4.15k]
  ------------------
  587|      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]
  |  |  ------------------
  ------------------
  588|      0|        return NULL;
  589|      0|    }
  590|  4.15k|    data->type = PLIST_INT;
  591|  4.15k|    data->intval = val;
  592|  4.15k|    data->length = sizeof(uint64_t);
  593|  4.15k|    return plist_new_node_or_free(data);
  594|  4.15k|}
plist_new_real:
  610|  2.17k|{
  611|  2.17k|    plist_data_t data = plist_new_plist_data();
  612|  2.17k|    if (!data) {
  ------------------
  |  Branch (612:9): [True: 0, False: 2.17k]
  ------------------
  613|      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]
  |  |  ------------------
  ------------------
  614|      0|        return NULL;
  615|      0|    }
  616|  2.17k|    data->type = PLIST_REAL;
  617|  2.17k|    data->realval = val;
  618|  2.17k|    data->length = sizeof(double);
  619|  2.17k|    return plist_new_node_or_free(data);
  620|  2.17k|}
plist_free:
  682|  5.31k|{
  683|  5.31k|    if (plist)
  ------------------
  |  Branch (683:9): [True: 4.50k, False: 813]
  ------------------
  684|  4.50k|    {
  685|  4.50k|        plist_free_node((node_t)plist);
  686|  4.50k|    }
  687|  5.31k|}
plist_array_append_item:
 1067|  57.4k|{
 1068|  57.4k|    if (!PLIST_IS_ARRAY(node) || !item) {
  ------------------
  |  | 1246|  57.4k|    #define PLIST_IS_ARRAY(__plist)   _PLIST_IS_TYPE(__plist, ARRAY)
  |  |  ------------------
  |  |  |  | 1234|   114k|    #define _PLIST_IS_TYPE(__plist, __plist_type) (__plist && (plist_get_node_type(__plist) == PLIST_##__plist_type))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1234:52): [True: 57.4k, False: 0]
  |  |  |  |  |  Branch (1234:63): [True: 57.4k, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (1068:34): [True: 0, False: 57.4k]
  ------------------
 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|  57.4k|    node_t it = (node_t)item;
 1073|  57.4k|    if (it->parent != NULL) {
  ------------------
  |  Branch (1073:9): [True: 0, False: 57.4k]
  ------------------
 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|  57.4k|    int r = node_attach((node_t)node, (node_t)item);
 1080|  57.4k|    if (r != NODE_ERR_SUCCESS) {
  ------------------
  |  |   35|  57.4k|#define NODE_ERR_SUCCESS       0
  ------------------
  |  Branch (1080:9): [True: 2, False: 57.4k]
  ------------------
 1081|      2|        PLIST_ERR("%s: failed to append item (err=%d)\n", __func__, r);
  ------------------
  |  |   57|      2|#define PLIST_ERR(...) if (plist_debug > 0) { fprintf(stderr, "libplist ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (57:28): [True: 0, False: 2]
  |  |  ------------------
  ------------------
 1082|      2|        return PLIST_ERR_UNKNOWN;
 1083|      2|    }
 1084|  57.4k|    _plist_array_post_insert(node, item, -1);
 1085|       |
 1086|  57.4k|    return PLIST_ERR_SUCCESS;
 1087|  57.4k|}
plist_dict_get_item:
 1268|  67.5k|{
 1269|  67.5k|    plist_t ret = NULL;
 1270|  67.5k|    if (!PLIST_IS_DICT(node) || !key) {
  ------------------
  |  | 1248|  67.5k|    #define PLIST_IS_DICT(__plist)    _PLIST_IS_TYPE(__plist, DICT)
  |  |  ------------------
  |  |  |  | 1234|   135k|    #define _PLIST_IS_TYPE(__plist, __plist_type) (__plist && (plist_get_node_type(__plist) == PLIST_##__plist_type))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1234:52): [True: 67.5k, False: 0]
  |  |  |  |  |  Branch (1234:63): [True: 67.5k, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (1270:33): [True: 0, False: 67.5k]
  ------------------
 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|  67.5k|    plist_data_t data = plist_get_data(node);
 1275|  67.5k|    if (!data) {
  ------------------
  |  Branch (1275:9): [True: 0, False: 67.5k]
  ------------------
 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|  67.5k|    size_t keylen = strlen(key);
 1280|  67.5k|    hashtable_t *ht = (hashtable_t*)data->hashtable;
 1281|  67.5k|    if (ht) {
  ------------------
  |  Branch (1281:9): [True: 1.24k, False: 66.2k]
  ------------------
 1282|  1.24k|        struct plist_data_s sdata = { 0 };
 1283|  1.24k|        sdata.strval = (char*)key;
 1284|  1.24k|        sdata.length = keylen;
 1285|  1.24k|        return (plist_t)hash_table_lookup(ht, &sdata);
 1286|  66.2k|    } else {
 1287|  66.2k|        plist_t k = NULL;
 1288|  7.65M|        for (k = (plist_t)node_first_child((node_t)node); k; ) {
  ------------------
  |  Branch (1288:59): [True: 7.59M, False: 62.7k]
  ------------------
 1289|  7.59M|            plist_t v = (plist_t)node_next_sibling(k);
 1290|  7.59M|            if (!v) break;
  ------------------
  |  Branch (1290:17): [True: 0, False: 7.59M]
  ------------------
 1291|  7.59M|            data = plist_get_data(k);
 1292|  7.59M|            assert(PLIST_IS_KEY(k));
  ------------------
  |  Branch (1292:13): [True: 0, False: 7.59M]
  |  Branch (1292:13): [True: 0, False: 0]
  |  Branch (1292:13): [True: 7.59M, False: 0]
  |  Branch (1292:13): [True: 7.59M, False: 0]
  ------------------
 1293|  7.59M|            if (!PLIST_IS_KEY(k) || !data || !data->strval) {
  ------------------
  |  | 1254|  7.59M|    #define PLIST_IS_KEY(__plist)     _PLIST_IS_TYPE(__plist, KEY)
  |  |  ------------------
  |  |  |  | 1234|  15.1M|    #define _PLIST_IS_TYPE(__plist, __plist_type) (__plist && (plist_get_node_type(__plist) == PLIST_##__plist_type))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1234:52): [True: 7.59M, False: 0]
  |  |  |  |  |  Branch (1234:63): [True: 7.59M, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (1293:37): [True: 0, False: 7.59M]
  |  Branch (1293:46): [True: 0, False: 7.59M]
  ------------------
 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|  7.59M|            if (data->length == keylen && !memcmp(key, data->strval, keylen+1)) {
  ------------------
  |  Branch (1297:17): [True: 4.08M, False: 3.51M]
  |  Branch (1297:43): [True: 3.57k, False: 4.08M]
  ------------------
 1298|  3.57k|                ret = v;
 1299|  3.57k|                break;
 1300|  3.57k|            }
 1301|  7.59M|            k = node_next_sibling(v);
 1302|  7.59M|        }
 1303|  66.2k|    }
 1304|  66.2k|    return ret;
 1305|  67.5k|}
plist_dict_set_item:
 1318|  67.5k|{
 1319|  67.5k|    if (!PLIST_IS_DICT(node) || !key || !item) {
  ------------------
  |  | 1248|  67.5k|    #define PLIST_IS_DICT(__plist)    _PLIST_IS_TYPE(__plist, DICT)
  |  |  ------------------
  |  |  |  | 1234|   135k|    #define _PLIST_IS_TYPE(__plist, __plist_type) (__plist && (plist_get_node_type(__plist) == PLIST_##__plist_type))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1234:52): [True: 67.5k, False: 0]
  |  |  |  |  |  Branch (1234:63): [True: 67.5k, False: 0]
  |  |  |  |  ------------------
  |  |  ------------------
  ------------------
  |  Branch (1319:33): [True: 0, False: 67.5k]
  |  Branch (1319:41): [True: 0, False: 67.5k]
  ------------------
 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|  67.5k|    node_t it = (node_t)item;
 1324|  67.5k|    if (it->parent != NULL) {
  ------------------
  |  Branch (1324:9): [True: 0, False: 67.5k]
  ------------------
 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|  67.5k|    hashtable_t *ht = (hashtable_t*)((plist_data_t)((node_t)node)->data)->hashtable;
 1331|       |
 1332|  67.5k|    plist_t old_item = plist_dict_get_item(node, key);
 1333|  67.5k|    plist_t key_node = NULL;
 1334|       |
 1335|  67.5k|    if (old_item) {
  ------------------
  |  Branch (1335:9): [True: 4.37k, False: 63.1k]
  ------------------
 1336|       |        // --- REPLACE EXISTING VALUE ---
 1337|  4.37k|        node_t old_val = (node_t)old_item;
 1338|  4.37k|        node_t old_key = node_prev_sibling(old_val);
 1339|  4.37k|        if (!old_key) {
  ------------------
  |  Branch (1339:13): [True: 0, False: 4.37k]
  ------------------
 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|  4.37k|        if (!PLIST_IS_KEY((plist_t)old_key)) {
  ------------------
  |  | 1254|  4.37k|    #define PLIST_IS_KEY(__plist)     _PLIST_IS_TYPE(__plist, KEY)
  |  |  ------------------
  |  |  |  | 1234|  4.37k|    #define _PLIST_IS_TYPE(__plist, __plist_type) (__plist && (plist_get_node_type(__plist) == PLIST_##__plist_type))
  |  |  |  |  ------------------
  |  |  |  |  |  Branch (1234:52): [True: 4.37k, False: 0]
  |  |  |  |  |  Branch (1234:63): [True: 4.37k, 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|  4.37k|        int idx = node_detach((node_t)node, old_val);
 1350|  4.37k|        if (idx < 0) {
  ------------------
  |  Branch (1350:13): [True: 0, False: 4.37k]
  ------------------
 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|  4.37k|        int r = node_insert((node_t)node, (unsigned)idx, (node_t)item);
 1357|  4.37k|        if (r != NODE_ERR_SUCCESS) {
  ------------------
  |  |   35|  4.37k|#define NODE_ERR_SUCCESS       0
  ------------------
  |  Branch (1357:13): [True: 2, False: 4.37k]
  ------------------
 1358|       |            // rollback: reinsert old value
 1359|      2|            int rb = node_insert((node_t)node, (unsigned)idx, old_val);
 1360|      2|            if (rb == NODE_ERR_SUCCESS && ht) {
  ------------------
  |  |   35|      4|#define NODE_ERR_SUCCESS       0
  ------------------
  |  Branch (1360:17): [True: 2, False: 0]
  |  Branch (1360:43): [True: 1, False: 1]
  ------------------
 1361|      1|                if (hash_table_insert(ht, ((node_t)old_key)->data, old_item) < 0) {
  ------------------
  |  Branch (1361:21): [True: 0, False: 1]
  ------------------
 1362|      0|                    plist_dict_drop_cache(node);
 1363|      0|                    ht = NULL;
 1364|      0|                }
 1365|      1|            }
 1366|      2|            PLIST_ERR("%s: failed to replace dict value (err=%d)\n", __func__, r);
  ------------------
  |  |   57|      2|#define PLIST_ERR(...) if (plist_debug > 0) { fprintf(stderr, "libplist ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (57:28): [True: 0, False: 2]
  |  |  ------------------
  ------------------
 1367|      2|            return PLIST_ERR_UNKNOWN;
 1368|      2|        }
 1369|  4.37k|        key_node = old_key;
 1370|       |
 1371|       |        // update hash table
 1372|  4.37k|        if (ht) {
  ------------------
  |  Branch (1372:13): [True: 796, False: 3.57k]
  ------------------
 1373|    796|            if (hash_table_insert(ht, (plist_data_t)((node_t)key_node)->data, item) < 0) {
  ------------------
  |  Branch (1373:17): [True: 0, False: 796]
  ------------------
 1374|      0|                plist_dict_drop_cache(node);
 1375|      0|                ht = NULL;
 1376|      0|            }
 1377|    796|        }
 1378|       |
 1379|       |        // now it’s safe to free old value
 1380|  4.37k|        plist_free_node(old_val);
 1381|  63.1k|    } else {
 1382|       |        // --- INSERT NEW KEY/VALUE PAIR ---
 1383|  63.1k|        key_node = plist_new_key(key);
 1384|  63.1k|        if (!key_node) return PLIST_ERR_NO_MEM;
  ------------------
  |  Branch (1384:13): [True: 0, False: 63.1k]
  ------------------
 1385|       |
 1386|  63.1k|        int r = node_attach((node_t)node, (node_t)key_node);
 1387|  63.1k|        if (r != NODE_ERR_SUCCESS) {
  ------------------
  |  |   35|  63.1k|#define NODE_ERR_SUCCESS       0
  ------------------
  |  Branch (1387:13): [True: 0, False: 63.1k]
  ------------------
 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|  63.1k|        r = node_attach((node_t)node, (node_t)item);
 1393|  63.1k|        if (r != NODE_ERR_SUCCESS) {
  ------------------
  |  |   35|  63.1k|#define NODE_ERR_SUCCESS       0
  ------------------
  |  Branch (1393:13): [True: 2, False: 63.1k]
  ------------------
 1394|       |            // rollback key insertion
 1395|      2|            node_detach((node_t)node, (node_t)key_node);
 1396|      2|            plist_free_node((node_t)key_node);
 1397|      2|            PLIST_ERR("%s: failed to attach dict value (err=%d)\n", __func__, r);
  ------------------
  |  |   57|      2|#define PLIST_ERR(...) if (plist_debug > 0) { fprintf(stderr, "libplist ERROR: " __VA_ARGS__); }
  |  |  ------------------
  |  |  |  Branch (57:28): [True: 0, False: 2]
  |  |  ------------------
  ------------------
 1398|      2|            return PLIST_ERR_UNKNOWN;
 1399|      2|        }
 1400|       |
 1401|  63.1k|        if (ht) {
  ------------------
  |  Branch (1401:13): [True: 444, False: 62.7k]
  ------------------
 1402|       |            // store pointer to item in hash table
 1403|    444|            if (hash_table_insert(ht, (plist_data_t)((node_t)key_node)->data, item) < 0) {
  ------------------
  |  Branch (1403:17): [True: 0, False: 444]
  ------------------
 1404|      0|                plist_dict_drop_cache(node);
 1405|      0|                ht = NULL;
 1406|      0|            }
 1407|  62.7k|        } else if (((node_t)node)->count > 500) {
  ------------------
  |  Branch (1407:20): [True: 234, False: 62.4k]
  ------------------
 1408|       |            // make new hash table
 1409|    234|            ht = hash_table_new(dict_key_hash, dict_key_compare, NULL);
 1410|       |            // calculate the hashes for all entries we have so far
 1411|    234|            plist_t current = NULL;
 1412|    234|            for (current = (plist_t)node_first_child((node_t)node);
 1413|  58.9k|                 ht && current;
  ------------------
  |  Branch (1413:18): [True: 58.9k, False: 0]
  |  Branch (1413:24): [True: 58.7k, False: 234]
  ------------------
 1414|  58.7k|                 current = (plist_t)node_next_sibling(node_next_sibling((node_t)current)))
 1415|  58.7k|            {
 1416|  58.7k|                if (hash_table_insert(ht, ((node_t)current)->data, node_next_sibling((node_t)current)) < 0) {
  ------------------
  |  Branch (1416:21): [True: 0, False: 58.7k]
  ------------------
 1417|      0|                    hash_table_destroy(ht);
 1418|      0|                    ht = NULL;
 1419|      0|                }
 1420|  58.7k|            }
 1421|    234|            ((plist_data_t)((node_t)node)->data)->hashtable = ht;
 1422|    234|        }
 1423|  63.1k|    }
 1424|  67.5k|    return PLIST_ERR_SUCCESS;
 1425|  67.5k|}
plist_get_node_type:
 1755|  15.3M|{
 1756|  15.3M|    if (node)
  ------------------
  |  Branch (1756:9): [True: 15.3M, False: 0]
  ------------------
 1757|  15.3M|    {
 1758|  15.3M|        plist_data_t data = plist_get_data(node);
 1759|  15.3M|        if (data)
  ------------------
  |  Branch (1759:13): [True: 15.3M, False: 0]
  ------------------
 1760|  15.3M|            return data->type;
 1761|  15.3M|    }
 1762|      0|    return PLIST_NONE;
 1763|  15.3M|}
plist.c:_plist_free_data:
  400|   192k|{
  401|   192k|    if (!data) return;
  ------------------
  |  Branch (401:9): [True: 0, False: 192k]
  ------------------
  402|   192k|    switch (data->type) {
  403|  63.1k|        case PLIST_KEY:
  ------------------
  |  Branch (403:9): [True: 63.1k, False: 129k]
  ------------------
  404|  98.3k|        case PLIST_STRING:
  ------------------
  |  Branch (404:9): [True: 35.1k, False: 157k]
  ------------------
  405|  98.3k|            free(data->strval);
  406|  98.3k|            data->strval = NULL;
  407|  98.3k|            break;
  408|      0|        case PLIST_DATA:
  ------------------
  |  Branch (408:9): [True: 0, False: 192k]
  ------------------
  409|      0|            free(data->buff);
  410|      0|            data->buff = NULL;
  411|      0|            break;
  412|  53.2k|        case PLIST_ARRAY:
  ------------------
  |  Branch (412:9): [True: 53.2k, False: 139k]
  ------------------
  413|  53.2k|            ptr_array_free((ptrarray_t*)data->hashtable);
  414|  53.2k|            data->hashtable = NULL;
  415|  53.2k|            break;
  416|  12.0k|        case PLIST_DICT: {
  ------------------
  |  Branch (416:9): [True: 12.0k, False: 180k]
  ------------------
  417|  12.0k|            hashtable_t *ht = (hashtable_t*)data->hashtable;
  418|       |            // PLIST_DICT hashtables must not own/free values; values are freed via node tree.
  419|  12.0k|            assert(!ht || ht->free_func == NULL);
  ------------------
  |  Branch (419:13): [True: 12.0k, False: 0]
  |  Branch (419:13): [True: 0, False: 0]
  |  Branch (419:13): [True: 11.8k, False: 234]
  |  Branch (419:13): [True: 234, False: 0]
  ------------------
  420|  12.0k|            if (ht) ht->free_func = NULL;
  ------------------
  |  Branch (420:17): [True: 234, False: 11.8k]
  ------------------
  421|  12.0k|            hash_table_destroy(ht);
  422|  12.0k|            data->hashtable = NULL;
  423|  12.0k|            break;
  424|  12.0k|        }
  425|  29.0k|        default:
  ------------------
  |  Branch (425:9): [True: 29.0k, False: 163k]
  ------------------
  426|  29.0k|            break;
  427|   192k|    }
  428|   192k|}
plist.c:plist_new_node_or_free:
  354|   143k|{
  355|   143k|    plist_t node = plist_new_node(data);
  356|   143k|    if (!node) {
  ------------------
  |  Branch (356:9): [True: 0, False: 143k]
  ------------------
  357|      0|        plist_free_data(data);
  358|      0|    }
  359|   143k|    return node;
  360|   143k|}
plist.c:plist_free_node:
  469|  8.87k|{
  470|  8.87k|    if (!root) return NODE_ERR_INVALID_ARG;
  ------------------
  |  |   36|      0|#define NODE_ERR_INVALID_ARG  -1
  ------------------
  |  Branch (470:9): [True: 0, False: 8.87k]
  ------------------
  471|       |
  472|  8.87k|    int root_index = -1;
  473|       |
  474|  8.87k|    if (root->parent) {
  ------------------
  |  Branch (474:9): [True: 0, False: 8.87k]
  ------------------
  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|  8.87k|    int r = plist_free_children(root);
  482|  8.87k|    if (r < 0) {
  ------------------
  |  Branch (482:9): [True: 0, False: 8.87k]
  ------------------
  483|       |        // root is already detached; caller should treat as error.
  484|      0|        return r;
  485|      0|    }
  486|       |
  487|  8.87k|    plist_data_t data = plist_get_data(root);
  488|  8.87k|    plist_free_data(data);
  489|  8.87k|    root->data = NULL;
  490|       |
  491|  8.87k|    node_destroy(root);
  492|       |
  493|  8.87k|    return root_index;
  494|  8.87k|}
plist.c:plist_free_children:
  438|  8.87k|{
  439|  8.87k|    if (!root) return NODE_ERR_INVALID_ARG;
  ------------------
  |  |   36|      0|#define NODE_ERR_INVALID_ARG  -1
  ------------------
  |  Branch (439:9): [True: 0, False: 8.87k]
  ------------------
  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|  8.87k|    node_t cur = root;
  445|   376k|    for (;;) {
  446|   376k|        node_t ch = node_first_child(cur);
  447|   376k|        if (ch) {
  ------------------
  |  Branch (447:13): [True: 183k, False: 192k]
  ------------------
  448|   183k|            cur = ch;
  449|   183k|            continue;
  450|   183k|        }
  451|   192k|        if (cur == root) break;
  ------------------
  |  Branch (451:13): [True: 8.87k, False: 183k]
  ------------------
  452|       |
  453|   183k|        node_t parent = (node_t)cur->parent;
  454|   183k|        int di = node_detach(parent, cur);
  455|   183k|        if (di < 0) {
  ------------------
  |  Branch (455:13): [True: 0, False: 183k]
  ------------------
  456|      0|            return di;
  457|      0|        }
  458|   183k|        plist_data_t data = plist_get_data(cur);
  459|   183k|        plist_free_data(data);
  460|   183k|        cur->data = NULL;
  461|   183k|        node_destroy(cur);
  462|   183k|        cur = parent;
  463|   183k|    }
  464|       |
  465|  8.87k|    return NODE_ERR_SUCCESS;
  ------------------
  |  |   35|  8.87k|#define NODE_ERR_SUCCESS       0
  ------------------
  466|  8.87k|}
plist.c:_plist_array_post_insert:
  966|  57.4k|{
  967|  57.4k|    ptrarray_t *pa = (ptrarray_t*)((plist_data_t)((node_t)node)->data)->hashtable;
  968|  57.4k|    if (pa) {
  ------------------
  |  Branch (968:9): [True: 11.9k, False: 45.5k]
  ------------------
  969|       |        /* store pointer to item in array */
  970|  11.9k|        if (ptr_array_insert(pa, item, n) < 0) {
  ------------------
  |  Branch (970:13): [True: 0, False: 11.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|  11.9k|        return;
  976|  11.9k|    }
  977|       |
  978|  45.5k|    if (((node_t)node)->count > 100) {
  ------------------
  |  Branch (978:9): [True: 111, False: 45.4k]
  ------------------
  979|       |       /* make new lookup array */
  980|    111|       pa = ptr_array_new(128);
  981|    111|       plist_t current = NULL;
  982|    111|       for (current = (plist_t)node_first_child((node_t)node);
  983|  11.3k|            pa && current;
  ------------------
  |  Branch (983:13): [True: 11.3k, False: 0]
  |  Branch (983:19): [True: 11.2k, False: 111]
  ------------------
  984|  11.2k|            current = (plist_t)node_next_sibling((node_t)current))
  985|  11.2k|       {
  986|  11.2k|           if (ptr_array_add(pa, current) < 0) {
  ------------------
  |  Branch (986:16): [True: 0, False: 11.2k]
  ------------------
  987|      0|               ptr_array_free(pa);
  988|       |               pa = NULL;
  989|      0|           }
  990|  11.2k|       }
  991|    111|       ((plist_data_t)((node_t)node)->data)->hashtable = pa;
  992|    111|    }
  993|  45.5k|}
plist.c:plist_new_key:
  520|  63.1k|{
  521|  63.1k|    plist_data_t data = plist_new_plist_data();
  522|  63.1k|    if (!data) {
  ------------------
  |  Branch (522:9): [True: 0, False: 63.1k]
  ------------------
  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|  63.1k|    data->type = PLIST_KEY;
  527|  63.1k|    data->strval = strdup(val);
  528|  63.1k|    if (!data->strval) {
  ------------------
  |  Branch (528:9): [True: 0, False: 63.1k]
  ------------------
  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|  63.1k|    } else {
  533|  63.1k|        data->length = strlen(val);
  534|  63.1k|    }
  535|  63.1k|    return plist_new_node_or_free(data);
  536|  63.1k|}
plist.c:dict_key_hash:
  375|  61.2k|{
  376|  61.2k|    plist_data_t keydata = (plist_data_t)data;
  377|  61.2k|    unsigned int hash = 5381;
  378|  61.2k|    size_t i;
  379|  61.2k|    char *str = keydata->strval;
  380|   158k|    for (i = 0; i < keydata->length; str++, i++) {
  ------------------
  |  Branch (380:17): [True: 96.9k, False: 61.2k]
  ------------------
  381|  96.9k|        hash = ((hash << 5) + hash) + *str;
  382|  96.9k|    }
  383|  61.2k|    return hash;
  384|  61.2k|}
plist.c:dict_key_compare:
  387|  4.00k|{
  388|  4.00k|    plist_data_t data_a = (plist_data_t)a;
  389|  4.00k|    plist_data_t data_b = (plist_data_t)b;
  390|  4.00k|    if (data_a->strval == NULL || data_b->strval == NULL) {
  ------------------
  |  Branch (390:9): [True: 0, False: 4.00k]
  |  Branch (390:35): [True: 0, False: 4.00k]
  ------------------
  391|      0|        return FALSE;
  ------------------
  |  |   37|      0|#define FALSE 0
  ------------------
  392|      0|    }
  393|  4.00k|    if (data_a->length != data_b->length) {
  ------------------
  |  Branch (393:9): [True: 1.78k, False: 2.22k]
  ------------------
  394|  1.78k|        return FALSE;
  ------------------
  |  |   37|  1.78k|#define FALSE 0
  ------------------
  395|  1.78k|    }
  396|  2.22k|    return (strcmp(data_a->strval, data_b->strval) == 0) ? TRUE : FALSE;
  ------------------
  |  |   33|  1.59k|#define TRUE 1
  ------------------
                  return (strcmp(data_a->strval, data_b->strval) == 0) ? TRUE : FALSE;
  ------------------
  |  |   37|    627|#define FALSE 0
  ------------------
  |  Branch (396:12): [True: 1.59k, False: 627]
  ------------------
  397|  4.00k|}

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

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|}

