Branch Coverage

_rhash.c
Criterion Covered Total %
branch 123 306 40.2


line true false branch
93 0 6 if (count < 1) {
97 2 4 if (count == 1 && hash_ids[0] == RHASH_ALL_HASHES)
0 2 if (count == 1 && hash_ids[0] == RHASH_ALL_HASHES)
99 68 6 for (i = 0; i < count; i++) {
101 68 0 if (!IS_VALID_HASH_ID(hash_ids[i])) {
68 0 if (!IS_VALID_HASH_ID(hash_ids[i])) {
0 68 if (!IS_VALID_HASH_ID(hash_ids[i])) {
107 0 68 assert(hash_index < RHASH_HASH_COUNT); /* correct until extended hash_ids are supported */
116 0 6 if (rctx == NULL)
128 0 6 assert(phash_ctx >= (char*)&rctx->vector[count]);
129 0 6 assert(phash_ctx < ((char*)&rctx->vector[count] + DEFAULT_ALIGNMENT));
131 68 6 for (i = 0; i < count; i++) {
134 0 68 assert(info->context_size > 0);
135 0 68 assert(info->init != NULL);
136 0 68 assert(IS_PTR_ALIGNED_BY(phash_ctx, DEFAULT_ALIGNMENT)); /* hash context is aligned */
142 2 66 if ((hash_ids[i] & RHASH_BTIH) != 0)
147 68 0 if (need_init)
161 0 1 if (hash_id == RHASH_ALL_HASHES) {
166 1 0 if (!IS_VALID_HASH_MASK(hash_id)) {
0 1 if (!IS_VALID_HASH_MASK(hash_id)) {
170 1 0 if (HAS_ZERO_OR_ONE_BIT(hash_id)) {
177 0 0 for (count = 0; id <= hash_id; id = id << 1) {
178 0 0 assert(id != 0);
179 0 0 if (hash_id & id)
182 0 0 assert(count > 1);
192 0 4 if (ctx == 0) return;
196 35 4 for (i = 0; i < ectx->hash_vector_size; i++) {
198 2 33 if (info->cleanup != 0) {
210 0 3 assert(ectx->hash_vector_size > 0);
211 0 3 assert(ectx->hash_vector_size <= RHASH_HASH_COUNT);
214 4 3 for (i = 0; i < ectx->hash_vector_size; i++) {
216 0 4 if (info->cleanup != 0) {
220 0 4 assert(info->init != NULL);
233 0 8 assert(ectx->hash_vector_size <= RHASH_HASH_COUNT);
234 0 8 if (ectx->state != STATE_ACTIVE) return 0; /* do nothing if canceled */
239 70 8 for (i = 0; i < ectx->hash_vector_size; i++) {
241 0 70 assert(info->update != 0);
251 8 1 unsigned char* out = (first_result ? first_result : buffer);
253 0 9 assert(ectx->hash_vector_size <= RHASH_HASH_COUNT);
256 0 9 if ((ectx->flags & RCTX_FINALIZED_MASK) ==
260 72 9 for (i = 0; i < ectx->hash_vector_size; i++) {
262 0 72 assert(info->final != 0);
263 0 72 assert(info->info->digest_size < sizeof(buffer));
312 0 0 if (!ctx || (out && size < sizeof(export_header)) || IS_BAD_STATE(ectx->state))
0 0 if (!ctx || (out && size < sizeof(export_header)) || IS_BAD_STATE(ectx->state))
0 0 if (!ctx || (out && size < sizeof(export_header)) || IS_BAD_STATE(ectx->state))
0 0 if (!ctx || (out && size < sizeof(export_header)) || IS_BAD_STATE(ectx->state))
0 0 if (!ctx || (out && size < sizeof(export_header)) || IS_BAD_STATE(ectx->state))
315 0 0 if (out != NULL) {
323 0 0 for (i = 0; i < ectx->hash_vector_size; i++) {
328 0 0 if (out != NULL) {
329 0 0 if (size <= export_size)
332 0 0 if (is_special) {
340 0 0 if (!item_size)
345 0 0 if (size < (export_size + item_size))
350 0 0 if (is_special) {
359 0 0 if (export_size < size)
376 0 0 if (!header || IS_BAD_STATE(header->state) || size < sizeof(export_header))
0 0 if (!header || IS_BAD_STATE(header->state) || size < sizeof(export_header))
0 0 if (!header || IS_BAD_STATE(header->state) || size < sizeof(export_header))
0 0 if (!header || IS_BAD_STATE(header->state) || size < sizeof(export_header))
379 0 0 if (!header->hash_vector_size || size < imported_size)
0 0 if (!header->hash_vector_size || size < imported_size)
383 0 0 if (!ectx)
389 0 0 for (i = 0; i < ectx->hash_vector_size; i++) {
395 0 0 if (is_special) {
400 0 0 assert(size >= imported_size);
403 0 0 if (!item_size || size < imported_size) {
0 0 if (!item_size || size < imported_size) {
412 0 0 if (size < imported_size) {
436 0 61 assert(ectx);
437 61 0 assert(ectx->hash_vector_size > 0 && ectx->hash_vector_size <= RHASH_HASH_COUNT);
61 0 assert(ectx->hash_vector_size > 0 && ectx->hash_vector_size <= RHASH_HASH_COUNT);
439 5 56 if (hash_id == 0) {
444 577 0 for (i = 0; i < ectx->hash_vector_size; i++) {
446 0 577 assert(item->hash_info != NULL);
447 0 577 assert(item->hash_info->info != NULL);
448 56 521 if (item->hash_info->info->hash_id == hash_id)
466 10 42 if (info->info->flags & F_SWAP32) {
467 0 10 assert((info->info->digest_size & 3) == 0);
470 3 39 } else if (info->info->flags & F_SWAP64) {
489 0 1 if (ctx == NULL) return -1;
503 0 0 if (ectx->state != STATE_ACTIVE)
505 0 0 if (ctx == NULL) {
510 0 0 if (!buffer)
513 0 0 while (!feof(fd)) {
514 0 0 if (ectx->state != STATE_ACTIVE)
518 0 0 if (ferror(fd)) {
521 0 0 } else if (length) {
524 0 0 if (ectx->callback) {
546 0 0 if (!ctx) {
550 0 0 if (!fd) {
556 0 0 if (res >= 0)
600 2 0 if (hash_id == 0 || (hash_id & (hash_id - 1)) != 0) return -1;
0 2 if (hash_id == 0 || (hash_id & (hash_id - 1)) != 0) return -1;
607 1 0 return (int)(info ? (info->flags & F_BS32 ?
0 1 return (int)(info ? (info->flags & F_BS32 ?
614 1 0 return (info ? info->name : 0);
620 18 0 return (info ? info->magnet_name : 0);
630 4 0 if ((flags & RHPR_NO_MAGNET) == 0) {
634 4 0 if ((flags & RHPR_FILESIZE) != 0) {
638 0 4 if (num == 0) size++;
640 4 4 for (; num; num /= 10, size++);
644 2 2 if (filepath) {
647 0 4 if (!hash_mask) {
652 10 4 for (bit = hash_mask & -(int)hash_mask; bit <= hash_mask; bit <<= 1) {
654 1 9 if ((bit & hash_mask) == 0) continue;
655 0 9 if ((name = rhash_get_magnet_name(bit)) == 0) continue;
659 1 8 (bit & RHASH_SHA1 ? RHPR_BASE32 : 0));
672 8 0 if (!IS_EXTENDED_RHASH_ID(ectx->rc.hash_id | hash_mask)) {
676 4 4 if (output == NULL)
680 4 0 if ((flags & RHPR_NO_MAGNET) == 0) {
685 4 0 if ((flags & RHPR_FILESIZE) != 0) {
693 2 2 if (filepath) {
700 8 4 for (i = 0; i <= 1; i++) {
703 4 4 unsigned hash = (!i ? hash_mask & print_first : hash_mask & ~print_first);
704 3 5 if (!hash)
708 9 5 for (bit = hash & -(int)hash; bit <= hash; bit <<= 1) {
710 0 9 if ((bit & hash) == 0) continue;
711 0 9 if (!(name = rhash_get_magnet_name(bit))) continue;
719 1 8 (bit & RHASH_SHA1 ? flags | RHPR_BASE32 : flags));
750 0 1 if (flags & RHPR_URLENCODE) {
769 61 0 if (!item || !item->hash_info || !item->hash_info->info) return 0;
61 0 if (!item || !item->hash_info || !item->hash_info->info) return 0;
0 61 if (!item || !item->hash_info || !item->hash_info->info) return 0;
773 0 61 assert(digest_size <= 64);
776 53 8 if ((flags & RHPR_FORMAT) == 0) {
778 7 46 flags |= (info->flags & RHASH_INFO_BASE32 ? RHPR_BASE32 : RHPR_HEX);
781 9 52 if (output == NULL) {
782 0 9 size_t multiplier = (flags & RHPR_URLENCODE ? 3 : 1);
796 5 47 if ((ectx->flags & RCTX_FINALIZED_MASK) == RCTX_AUTO_FINAL) {
802 1 51 if ((flags & ~RHPR_UPPERCASE) == (RHPR_REVERSE | RHPR_HEX)) {
807 8 1 for (; p < r; p++, r--) {
844 0 0 if (count != 0 && data != 0) {
0 0 if (count != 0 && data != 0) {
845 0 0 ENSURE_THAT(ctx->hash_vector_size <= count);
846 0 0 for (i = 0; i < ctx->hash_vector_size; i++)
857 0 0 if (count > 0 && data != 0) {
0 0 if (count > 0 && data != 0) {
859 0 0 ENSURE_THAT(bits_count <= count);
860 0 0 for (unsigned bit = 1; bit <= bitmask; bit = bit << 1) {
861 0 0 if ((bitmask & bit) != 0)
864 0 0 ENSURE_THAT(bits_count == index);
888 0 0 ENSURE_THAT(data);
889 0 0 for (i = 0; i < ctx->hash_vector_size; i++) {
891 0 0 if (info->info->hash_id == (unsigned)size) {
908 0 0 if (size)
913 0 0 if (data && size) {
0 0 if (data && size) {
915 0 0 ENSURE_THAT(size >= RHASH_HASH_COUNT);
921 0 0 ENSURE_THAT(ctx);
934 0 0 ENSURE_THAT(data || !size);
0 0 ENSURE_THAT(data || !size);