Branch Coverage

bson/bson.c
Criterion Covered Total %
branch 161 556 28.9


line true false branch
113 1917 65 if (((size_t)impl->len + size) <= sizeof impl->data) {
119 65 0 if (req <= INT32_MAX) {
170 1164 24 if (req <= *impl->buflen) {
176 24 0 if ((req <= INT32_MAX) && impl->realloc) {
24 0 if ((req <= INT32_MAX) && impl->realloc) {
207 1982 1188 if ((bson->flags & BSON_FLAG_INLINE)) {
235 5947 9022 if ((bson->flags & BSON_FLAG_INLINE)) {
312 0 3109 BSON_ASSERT (!(bson->flags & BSON_FLAG_IN_CHILD));
313 0 3109 BSON_ASSERT (!(bson->flags & BSON_FLAG_RDONLY));
315 0 3109 if (BSON_UNLIKELY (!_bson_grow (bson, n_bytes))) {
330 9664 3109 if (n_pairs) {
331 3107 6557 data_len = va_arg (args, uint32_t);
332 0 9664 data = va_arg (args, const uint8_t *);
334 9664 3109 } while (n_pairs);
380 0 3109 BSON_ASSERT (n_pairs);
381 0 3109 BSON_ASSERT (first_len);
382 0 3109 BSON_ASSERT (first_data);
389 0 3109 if (BSON_UNLIKELY (n_bytes > (BSON_MAX_SIZE - bson->len))) {
435 0 962 BSON_ASSERT (!(bson->flags & BSON_FLAG_RDONLY));
436 0 962 BSON_ASSERT (!(bson->flags & BSON_FLAG_IN_CHILD));
437 0 962 BSON_ASSERT (key);
438 17 945 BSON_ASSERT ((child_type == BSON_TYPE_DOCUMENT) ||
0 17 BSON_ASSERT ((child_type == BSON_TYPE_DOCUMENT) ||
440 0 962 BSON_ASSERT (child);
442 962 0 if (key_length < 0) {
452 61 901 if ((bson->flags & BSON_FLAG_INLINE)) {
453 0 61 BSON_ASSERT (bson->len <= 120);
454 0 61 if (!_bson_grow (bson, 128 - bson->len)) {
457 0 61 BSON_ASSERT (!(bson->flags & BSON_FLAG_INLINE));
463 0 962 if (!_bson_append (bson, 4,
486 895 67 if ((bson->flags & BSON_FLAG_CHILD)) {
527 0 756 BSON_ASSERT (bson);
528 0 756 BSON_ASSERT ((bson->flags & BSON_FLAG_IN_CHILD));
529 0 756 BSON_ASSERT (!(child->flags & BSON_FLAG_IN_CHILD));
584 0 17 BSON_ASSERT (bson);
585 0 17 BSON_ASSERT (key);
586 0 17 BSON_ASSERT (child);
616 0 16 BSON_ASSERT (bson);
617 0 16 BSON_ASSERT (child);
653 0 945 BSON_ASSERT (bson);
654 0 945 BSON_ASSERT (key);
655 0 945 BSON_ASSERT (child);
685 0 740 BSON_ASSERT (bson);
686 0 740 BSON_ASSERT (child);
719 0 0 BSON_ASSERT (bson);
720 0 0 BSON_ASSERT (key);
721 0 0 BSON_ASSERT (array);
723 0 0 if (key_length < 0) {
732 0 0 if (array && !bson_empty (array)) {
0 0 if (array && !bson_empty (array)) {
0 0 if (array && !bson_empty (array)) {
735 0 0 if (bson_iter_init (&iter, array) && bson_iter_next (&iter)) {
0 0 if (bson_iter_init (&iter, array) && bson_iter_next (&iter)) {
736 0 0 if (0 != strcmp ("0", bson_iter_key (&iter))) {
790 0 27 BSON_ASSERT (bson);
791 0 27 BSON_ASSERT (key);
792 0 27 BSON_ASSERT (binary);
794 27 0 if (key_length < 0) {
800 2 25 if (subtype == BSON_SUBTYPE_BINARY_DEPRECATED) {
854 0 18 BSON_ASSERT (bson);
855 0 18 BSON_ASSERT (key);
857 18 0 if (key_length < 0) {
902 0 9 BSON_ASSERT (bson);
903 0 9 BSON_ASSERT (key);
904 0 9 BSON_ASSERT (javascript);
906 9 0 if (key_length < 0) {
953 0 13 BSON_ASSERT (bson);
954 0 13 BSON_ASSERT (key);
955 0 13 BSON_ASSERT (javascript);
957 13 0 if (key_length < 0) {
1008 0 0 BSON_ASSERT (bson);
1009 0 0 BSON_ASSERT (key);
1010 0 0 BSON_ASSERT (collection);
1011 0 0 BSON_ASSERT (oid);
1013 0 0 if (key_length < 0) {
1061 0 104 BSON_ASSERT (bson);
1062 0 104 BSON_ASSERT (key);
1063 0 104 BSON_ASSERT (value);
1065 104 0 if (key_length < 0) {
1086 0 46 BSON_ASSERT (bson);
1087 0 46 BSON_ASSERT (key);
1089 46 0 if (key_length < 0) {
1115 0 167 BSON_ASSERT (bson);
1116 0 167 BSON_ASSERT (key);
1118 167 0 if (key_length < 0) {
1142 0 20 BSON_ASSERT (bson);
1143 0 20 BSON_ASSERT (key);
1145 20 0 if (key_length < 0) {
1169 0 1512 BSON_ASSERT (bson);
1170 0 1512 BSON_ASSERT (key);
1171 0 1512 BSON_ASSERT (value);
1173 1512 0 if (key_length < 0) {
1197 0 0 BSON_ASSERT (bson);
1198 0 0 BSON_ASSERT (iter);
1200 0 0 if (!key) {
1228 0 0 if (bson_init_static (&doc, buf, len)) {
1242 0 0 if (bson_init_static (&doc, buf, len)) {
1322 0 0 if (bson_init_static (&doc, scope, scope_len)) {
1348 0 0 if (!bson_iter_decimal128 (iter, &dec)) {
1376 0 6 BSON_ASSERT (bson);
1377 0 6 BSON_ASSERT (key);
1379 6 0 if (key_length < 0) {
1398 0 6 BSON_ASSERT (bson);
1399 0 6 BSON_ASSERT (key);
1401 6 0 if (key_length < 0) {
1420 0 16 BSON_ASSERT (bson);
1421 0 16 BSON_ASSERT (key);
1423 16 0 if (key_length < 0) {
1443 0 27 BSON_ASSERT (bson);
1444 0 27 BSON_ASSERT (key);
1445 0 27 BSON_ASSERT (value);
1447 27 0 if (key_length < 0) {
1471 0 25 BSON_ASSERT (bson);
1472 0 25 BSON_ASSERT (key);
1474 25 0 if (key_length < 0) {
1478 0 25 if (!regex) {
1482 0 25 if (!options) {
1509 0 121 BSON_ASSERT (bson);
1510 0 121 BSON_ASSERT (key);
1512 0 121 if (BSON_UNLIKELY (!value)) {
1516 121 0 if (BSON_UNLIKELY (key_length < 0)) {
1520 0 121 if (BSON_UNLIKELY (length < 0)) {
1547 0 0 BSON_ASSERT (bson);
1548 0 0 BSON_ASSERT (key);
1550 0 0 if (!value) {
1554 0 0 if (key_length < 0) {
1558 0 0 if (length < 0) {
1587 0 0 BSON_ASSERT (bson);
1588 0 0 BSON_ASSERT (key);
1604 0 10 BSON_ASSERT (bson);
1605 0 10 BSON_ASSERT (key);
1607 10 0 if (key_length < 0) {
1628 0 0 BSON_ASSERT (bson);
1629 0 0 BSON_ASSERT (key);
1630 0 0 BSON_ASSERT (key_length >= -1);
1645 0 18 BSON_ASSERT (bson);
1646 0 18 BSON_ASSERT (key);
1648 18 0 if (key_length < 0) {
1671 0 0 BSON_ASSERT (bson);
1672 0 0 BSON_ASSERT (key);
1673 0 0 BSON_ASSERT (value);
1688 0 0 BSON_ASSERT (bson);
1689 0 0 BSON_ASSERT (key);
1691 0 0 if (key_length < 0) {
1712 0 0 BSON_ASSERT (bson);
1713 0 0 BSON_ASSERT (key);
1714 0 0 BSON_ASSERT (value);
1727 0 0 if (bson_init_static (&local,
1735 0 0 if (bson_init_static (&local,
1784 0 0 if (bson_init_static (&local,
1828 0 106 BSON_ASSERT (bson);
1845 0 0 BSON_ASSERT (bson);
1867 0 1908 BSON_ASSERT (bson);
1868 0 1908 BSON_ASSERT (data);
1870 1907 1 if ((length < 5) || (length > INT_MAX)) {
0 1907 if ((length < 5) || (length > INT_MAX)) {
1876 10 1897 if ((size_t)BSON_UINT32_FROM_LE (len_le) != length) {
1880 5 1892 if (data[length - 1]) {
1928 0 106 BSON_ASSERT (size <= INT32_MAX);
1934 106 0 if (size <= sizeof impl_i->data) {
1967 0 106 BSON_ASSERT (data);
1969 106 0 if ((length < 5) || (length > INT_MAX) || data [length - 1]) {
106 0 if ((length < 5) || (length > INT_MAX) || data [length - 1]) {
0 106 if ((length < 5) || (length > INT_MAX) || data [length - 1]) {
1975 0 106 if (length != (size_t)BSON_UINT32_FROM_LE (len_le)) {
1998 0 0 BSON_ASSERT (buf);
1999 0 0 BSON_ASSERT (buf_len);
2001 0 0 if (!realloc_func) {
2008 0 0 if (!*buf) {
2016 0 0 if ((*buf_len < 5) || (*buf_len > INT_MAX)) {
0 0 if ((*buf_len < 5) || (*buf_len > INT_MAX)) {
2025 0 0 if ((*buf)[length - 1]) {
2046 0 0 BSON_ASSERT (bson);
2061 0 0 BSON_ASSERT (src);
2062 0 0 BSON_ASSERT (dst);
2064 0 0 if ((src->flags & BSON_FLAG_INLINE)) {
2101 0 0 if (!strcmp (name, exclude)) {
2105 0 0 } while ((exclude = va_arg (args_copy, const char *)));
0 0 } while ((exclude = va_arg (args_copy, const char *)));
2121 0 0 if (bson_iter_init (&iter, src)) {
2122 0 0 while (bson_iter_next (&iter)) {
2123 0 0 if (!should_ignore (first_exclude, args, bson_iter_key (&iter))) {
2124 0 0 if (!bson_append_iter (dst, NULL, 0, &iter)) {
2146 0 0 BSON_ASSERT (src);
2147 0 0 BSON_ASSERT (dst);
2148 0 0 BSON_ASSERT (first_exclude);
2165 0 0 BSON_ASSERT (src);
2166 0 0 BSON_ASSERT (dst);
2167 0 0 BSON_ASSERT (first_exclude);
2178 0 2064 BSON_ASSERT (bson);
2180 59 2005 if (!(bson->flags &
2185 2064 0 if (!(bson->flags & BSON_FLAG_STATIC)) {
2199 0 0 BSON_ASSERT (dst);
2200 0 0 BSON_ASSERT (src);
2204 0 0 if (src->flags & (BSON_FLAG_CHILD | BSON_FLAG_IN_CHILD | BSON_FLAG_RDONLY)) {
2208 0 0 if (src->flags & BSON_FLAG_INLINE) {
2224 0 0 if (!(src->flags & BSON_FLAG_STATIC)) {
2242 0 0 BSON_ASSERT (bson);
2244 0 0 if (length) {
2248 0 0 if (!steal) {
2253 0 0 if ((bson->flags & (BSON_FLAG_CHILD |
2257 0 0 } else if ((bson->flags & BSON_FLAG_INLINE)) {
2280 0 7014 BSON_ASSERT (bson);
2292 0 0 BSON_ASSERT (bson);
2294 0 0 if (bson_iter_init (&iter, bson)) {
2295 0 0 while (bson_iter_next (&iter)) {
2311 0 0 BSON_ASSERT (bson);
2312 0 0 BSON_ASSERT (key);
2314 0 0 if (NULL != strchr (key, '.')) {
2339 0 0 if (len1 == len2) {
2345 0 0 if (ret == 0) {
2349 0 0 return (ret < 0) ? -1 : (ret > 0);
2373 0 0 if (escaped) {
2532 0 0 bson_string_append (state->str, v_bool ? "true" : "false");
2607 0 0 if (v_oid) {
2656 0 0 if (state->count) {
2660 0 0 if (state->keys) {
2662 0 0 if (escaped) {
2690 0 0 if (escaped) {
2732 0 0 if (escaped) {
2783 0 0 if (state->depth >= BSON_MAX_RECURSION) {
2788 0 0 if (bson_iter_init (&child, v_document)) {
2811 0 0 if (state->depth >= BSON_MAX_RECURSION) {
2816 0 0 if (bson_iter_init (&child, v_array)) {
2836 0 0 BSON_ASSERT (bson);
2838 0 0 if (length) {
2842 0 0 if (bson_empty0 (bson)) {
0 0 if (bson_empty0 (bson)) {
0 0 if (bson_empty0 (bson)) {
2843 0 0 if (length) {
2850 0 0 if (!bson_iter_init (&iter, bson)) {
2859 0 0 if (bson_iter_visit_all (&iter, &bson_as_json_visitors, &state) ||
0 0 if (bson_iter_visit_all (&iter, &bson_as_json_visitors, &state) ||
2865 0 0 if (length) {
2873 0 0 if (length) {
2888 0 0 BSON_ASSERT (bson);
2890 0 0 if (length) {
2894 0 0 if (bson_empty0 (bson)) {
0 0 if (bson_empty0 (bson)) {
0 0 if (bson_empty0 (bson)) {
2895 0 0 if (length) {
2902 0 0 if (!bson_iter_init (&iter, bson)) {
2912 0 0 if (bson_iter_visit_all (&iter, &bson_as_json_visitors, &state) ||
0 0 if (bson_iter_visit_all (&iter, &bson_as_json_visitors, &state) ||
2918 0 0 if (length) {
2926 0 0 if (length) {
2944 0 97 if ((state->flags & BSON_VALIDATE_UTF8)) {
2947 0 0 if (!bson_utf8_validate (v_utf8, v_utf8_len, allow_null)) {
2953 0 97 if ((state->flags & BSON_VALIDATE_DOLLAR_KEYS)) {
2954 0 0 if (state->phase == BSON_VALIDATE_PHASE_LF_REF_UTF8) {
2956 0 0 } else if (state->phase == BSON_VALIDATE_PHASE_LF_DB_UTF8) {
2982 0 1873 if ((state->flags & BSON_VALIDATE_DOLLAR_KEYS)) {
2983 0 0 if (key[0] == '$') {
2984 0 0 if (state->phase == BSON_VALIDATE_PHASE_LF_REF_KEY &&
0 0 if (state->phase == BSON_VALIDATE_PHASE_LF_REF_KEY &&
2987 0 0 } else if (state->phase == BSON_VALIDATE_PHASE_LF_ID_KEY &&
0 0 } else if (state->phase == BSON_VALIDATE_PHASE_LF_ID_KEY &&
2990 0 0 } else if (state->phase == BSON_VALIDATE_PHASE_LF_DB_KEY &&
0 0 } else if (state->phase == BSON_VALIDATE_PHASE_LF_DB_KEY &&
2997 0 0 } else if (state->phase == BSON_VALIDATE_PHASE_LF_ID_KEY ||
0 0 } else if (state->phase == BSON_VALIDATE_PHASE_LF_ID_KEY ||
2998 0 0 state->phase == BSON_VALIDATE_PHASE_LF_REF_UTF8 ||
3007 0 1873 if ((state->flags & BSON_VALIDATE_DOT_KEYS)) {
3008 0 0 if (strstr (key, ".")) {
3029 1 13 if (!bson_validate (v_scope, state->flags, &offset, NULL, NULL)) {
3094 0 1879 if (!bson_iter_init (&child, v_document)) {
3099 1621 258 if (state->phase == BSON_VALIDATE_PHASE_START) {
3107 1879 0 if (state->phase == BSON_VALIDATE_PHASE_LF_ID_KEY ||
1879 0 if (state->phase == BSON_VALIDATE_PHASE_LF_ID_KEY ||
3108 0 1879 state->phase == BSON_VALIDATE_PHASE_LF_REF_UTF8 ||
3130 0 1621 if (!bson_iter_init (&iter, bson)) {
3139 1621 0 if (offset) {
3142 1607 14 if (invalid_key) {
3145 1607 14 if (invalid_type) {
3157 0 2 BSON_ASSERT (dst);
3158 0 2 BSON_ASSERT (src);
3160 2 0 if (!bson_empty (src)) {
2 0 if (!bson_empty (src)) {