Branch Coverage

src/pdfmake_reader.c
Criterion Covered Total %
branch 192 328 58.5


line true false branch
28 526 1447 if (!obj) return NULL;
29 481 966 if (obj->kind == PDFMAKE_REF) {
38 1848 0 if (!dict || dict->kind != PDFMAKE_DICT) return NULL;
0 1848 if (!dict || dict->kind != PDFMAKE_DICT) return NULL;
40 0 1848 if (key_id == 0) return NULL;
46 265 0 if (!obj || obj->kind != PDFMAKE_NAME) return NULL;
0 265 if (!obj || obj->kind != PDFMAKE_NAME) return NULL;
53 51 0 if (!arr || arr->kind != PDFMAKE_ARRAY) return 0;
0 51 if (!arr || arr->kind != PDFMAKE_ARRAY) return 0;
54 0 51 if (pdfmake_array_len(arr) < 4) return 0;
56 204 51 for (i = 0; i < 4; i++) {
59 0 204 if (!item) return 0;
61 204 0 if (item->kind == PDFMAKE_INT) {
63 0 0 } else if (item->kind == PDFMAKE_REAL) {
98 309 265 for (i = 0; i < cd->count; i++) {
99 0 309 if (cd->visited[i] == node) {
105 96 169 if (cd->count >= cd->cap) {
106 0 96 size_t new_cap = cd->cap ? cd->cap * 2 : 16;
108 0 96 if (!new_visited) return -1; /* Allocation failure */
128 96 73 if (reader->page_count >= reader->page_cap) {
129 0 96 size_t new_cap = reader->page_cap ? reader->page_cap * 2 : 16;
132 0 96 if (!new_pages) {
158 0 265 if (!node) {
165 265 0 if (!node || node->kind != PDFMAKE_DICT) {
0 265 if (!node || node->kind != PDFMAKE_DICT) {
172 0 265 if (cycle_result < 0) {
176 0 265 if (cycle_result > 0) {
186 0 265 if (!type_name) {
191 169 96 if (strcmp(type_name, "Page") == 0) {
194 96 0 } else if (strcmp(type_name, "Pages") == 0) {
199 96 0 if (!kids || kids->kind != PDFMAKE_ARRAY) {
0 96 if (!kids || kids->kind != PDFMAKE_ARRAY) {
205 169 96 for (i = 0; i < kids_len; i++) {
208 0 169 if (err != PDFMAKE_OK) {
244 140 34 while (current) {
246 140 0 if (!current || current->kind != PDFMAKE_DICT) break;
140 0 if (!current || current->kind != PDFMAKE_DICT) break;
250 70 70 if (value) {
278 118 362 if (!src_cat || src_cat->kind != PDFMAKE_DICT) return;
14 104 if (!src_cat || src_cat->kind != PDFMAKE_DICT) return;
287 104 0 : reader->arena;
289 104 0 if (!dest_cat) {
293 0 104 if (!dest_cat) return;
297 104 0 if (cat_key) {
307 177 104 while (pdfmake_dict_iter_next(&iter)) {
308 177 0 if (!pdfmake_dict_has(dest_cat, iter.current_key)) {
325 0 60 if (!merged) return NULL;
330 120 60 while (current && chain_len < 32) {
120 0 while (current && chain_len < 32) {
333 120 0 if (!current || current->kind != PDFMAKE_DICT) break;
120 0 if (!current || current->kind != PDFMAKE_DICT) break;
337 60 60 if (res && res->kind == PDFMAKE_DICT) {
60 0 if (res && res->kind == PDFMAKE_DICT) {
351 60 60 for (i = chain_len; i > 0; i--) {
353 480 60 for (cat = categories; *cat; cat++) {
368 0 96 if (!parser) return NULL;
371 0 96 if (!reader) return NULL;
376 0 96 if (!reader->arena) {
385 0 96 if (!reader) return;
400 96 0 if (!reader || !reader->parser) {
0 96 if (!reader || !reader->parser) {
408 0 96 if (err != PDFMAKE_OK) {
415 0 96 if (reader->parser->root_num == 0) {
423 96 0 if (!reader->catalog || reader->catalog->kind != PDFMAKE_DICT) {
0 96 if (!reader->catalog || reader->catalog->kind != PDFMAKE_DICT) {
430 0 96 if (!pages_ref) {
437 0 96 if (err != PDFMAKE_OK) {
442 25 71 if (reader->parser->encrypt_num > 0) {
449 25 0 if (enc_dict && enc_dict->kind == PDFMAKE_DICT) {
25 0 if (enc_dict && enc_dict->kind == PDFMAKE_DICT) {
463 25 0 int V = (V_obj && V_obj->kind == PDFMAKE_INT) ? (int)V_obj->as.i : 0;
25 0 int V = (V_obj && V_obj->kind == PDFMAKE_INT) ? (int)V_obj->as.i : 0;
464 25 0 int R = (R_obj && R_obj->kind == PDFMAKE_INT) ? (int)R_obj->as.i : 0;
25 0 int R = (R_obj && R_obj->kind == PDFMAKE_INT) ? (int)R_obj->as.i : 0;
465 9 0 int key_length = (len_obj && len_obj->kind == PDFMAKE_INT)
466 9 16 ? (int)len_obj->as.i : 40;
467 25 0 int32_t P = (P_obj && P_obj->kind == PDFMAKE_INT)
468 25 0 ? (int32_t)P_obj->as.i : 0;
478 0 25 if (em_obj && em_obj->kind == PDFMAKE_BOOL && !em_obj->as.b)
0 0 if (em_obj && em_obj->kind == PDFMAKE_BOOL && !em_obj->as.b)
0 0 if (em_obj && em_obj->kind == PDFMAKE_BOOL && !em_obj->as.b)
481 25 0 O = (O_obj && O_obj->kind == PDFMAKE_STR) ? O_obj->as.str.bytes : NULL;
25 0 O = (O_obj && O_obj->kind == PDFMAKE_STR) ? O_obj->as.str.bytes : NULL;
482 25 0 O_len = (O_obj && O_obj->kind == PDFMAKE_STR) ? O_obj->as.str.len : 0;
25 0 O_len = (O_obj && O_obj->kind == PDFMAKE_STR) ? O_obj->as.str.len : 0;
483 25 0 U = (U_obj && U_obj->kind == PDFMAKE_STR) ? U_obj->as.str.bytes : NULL;
25 0 U = (U_obj && U_obj->kind == PDFMAKE_STR) ? U_obj->as.str.bytes : NULL;
484 25 0 U_len = (U_obj && U_obj->kind == PDFMAKE_STR) ? U_obj->as.str.len : 0;
25 0 U_len = (U_obj && U_obj->kind == PDFMAKE_STR) ? U_obj->as.str.len : 0;
486 5 20 if (OE_obj && OE_obj->kind == PDFMAKE_STR) { OE = OE_obj->as.str.bytes; OE_len = OE_obj->as.str.len; }
5 0 if (OE_obj && OE_obj->kind == PDFMAKE_STR) { OE = OE_obj->as.str.bytes; OE_len = OE_obj->as.str.len; }
487 5 20 if (UE_obj && UE_obj->kind == PDFMAKE_STR) { UE = UE_obj->as.str.bytes; UE_len = UE_obj->as.str.len; }
5 0 if (UE_obj && UE_obj->kind == PDFMAKE_STR) { UE = UE_obj->as.str.bytes; UE_len = UE_obj->as.str.len; }
488 5 20 if (Perms_obj && Perms_obj->kind == PDFMAKE_STR) { Perms = Perms_obj->as.str.bytes; Perms_len = Perms_obj->as.str.len; }
5 0 if (Perms_obj && Perms_obj->kind == PDFMAKE_STR) { Perms = Perms_obj->as.str.bytes; Perms_len = Perms_obj->as.str.len; }
490 25 0 if (O && U) {
25 0 if (O && U) {
492 25 0 if (reader->crypt) {
500 25 0 if (rc == 0) {
503 17 8 if (auth >= 0) {
517 8 0 if (!reader || !reader->crypt) return -1;
0 8 if (!reader || !reader->crypt) return -1;
518 8 0 auth = pdfmake_crypt_authenticate(reader->crypt, password ? password : "");
519 7 1 if (auth >= 0) reader->authenticated = 1;
524 83 0 return reader ? reader->encrypted : 0;
528 24 0 return reader ? reader->authenticated : 0;
532 1 0 return reader ? reader->err_msg : "NULL reader";
540 90 0 return reader ? reader->page_count : 0;
544 113 0 if (!reader || idx >= reader->page_count) return NULL;
1 112 if (!reader || idx >= reader->page_count) return NULL;
557 54 0 if (!reader || !page || !out) return PDFMAKE_EINVAL;
54 0 if (!reader || !page || !out) return PDFMAKE_EINVAL;
0 54 if (!reader || !page || !out) return PDFMAKE_EINVAL;
560 3 51 if (page->media_box_set) {
569 0 51 if (!media_box) {
574 0 51 if (!parse_rect(reader, media_box, page->media_box)) {
590 3 0 if (!reader || !page || !out) return PDFMAKE_EINVAL;
3 0 if (!reader || !page || !out) return PDFMAKE_EINVAL;
0 3 if (!reader || !page || !out) return PDFMAKE_EINVAL;
593 0 3 if (page->crop_box_set) {
602 0 3 if (crop_box && parse_rect(reader, crop_box, page->crop_box)) {
0 0 if (crop_box && parse_rect(reader, crop_box, page->crop_box)) {
610 0 3 if (err != PDFMAKE_OK) return err;
621 50 0 if (!reader || !page) return 0;
0 50 if (!reader || !page) return 0;
624 0 50 if (page->rotation_set) {
632 19 31 if (rotate && rotate->kind == PDFMAKE_INT) {
19 0 if (rotate && rotate->kind == PDFMAKE_INT) {
636 1 18 if (r != 0 && r != 90 && r != 180 && r != 270) {
0 1 if (r != 0 && r != 90 && r != 180 && r != 270) {
0 0 if (r != 0 && r != 90 && r != 180 && r != 270) {
0 0 if (r != 0 && r != 90 && r != 180 && r != 270) {
650 60 0 if (!reader || !page) return NULL;
0 60 if (!reader || !page) return NULL;
653 0 60 if (page->resources_set) {
681 181 0 if (!stream_obj || stream_obj->kind != PDFMAKE_STREAM)
0 181 if (!stream_obj || stream_obj->kind != PDFMAKE_STREAM)
687 101 80 if (reader->crypt && reader->authenticated && !stream->filtered) {
101 0 if (reader->crypt && reader->authenticated && !stream->filtered) {
101 0 if (reader->crypt && reader->authenticated && !stream->filtered) {
694 101 0 if (rc >= 0 && decrypted) {
101 0 if (rc >= 0 && decrypted) {
697 101 0 if (arena_copy) {
709 0 181 if (err != PDFMAKE_OK) return err;
721 74 0 if (!reader || !out) return PDFMAKE_EINVAL;
0 74 if (!reader || !out) return PDFMAKE_EINVAL;
725 74 0 if (!obj || obj->kind != PDFMAKE_STREAM) return PDFMAKE_EINVAL;
0 74 if (!obj || obj->kind != PDFMAKE_STREAM) return PDFMAKE_EINVAL;
739 107 0 if (!reader || !page || !out) return PDFMAKE_EINVAL;
107 0 if (!reader || !page || !out) return PDFMAKE_EINVAL;
0 107 if (!reader || !page || !out) return PDFMAKE_EINVAL;
743 2 105 if (!contents_raw) {
749 103 2 if (contents_raw->kind == PDFMAKE_REF) {
755 0 105 if (!contents) {
761 103 2 if (contents->kind == PDFMAKE_STREAM) {
764 0 103 if (err != PDFMAKE_OK) {
769 2 0 } else if (contents->kind == PDFMAKE_ARRAY) {
772 4 2 for (i = 0; i < arr_len; i++) {
779 2 2 if (i > 0)
783 4 0 if (stream_ref && stream_ref->kind == PDFMAKE_REF) {
4 0 if (stream_ref && stream_ref->kind == PDFMAKE_REF) {
789 4 0 if (!stream || stream->kind != PDFMAKE_STREAM) {
0 4 if (!stream || stream->kind != PDFMAKE_STREAM) {
796 0 4 if (err != PDFMAKE_OK) {