Branch Coverage

bitset.h
Criterion Covered Total %
branch 82 160 51.2


line true false branch
72 2 85 if (word & mask) return 1; /* already set */
73 85 0 if (__atomic_compare_exchange_n(&h->data[widx], &word, word | mask,
87 2 4 if (!(word & mask)) return 0; /* already clear */
88 4 0 if (__atomic_compare_exchange_n(&h->data[widx], &word, word & ~mask,
109 46 16 for (uint32_t i = 0; i < nw; i++) {
118 7 2 for (uint32_t i = 0; i < nw; i++)
119 2 5 if (__atomic_load_n(&h->data[i], __ATOMIC_RELAXED)) return 1;
129 7 3 for (uint32_t i = 0; i < nw; i++) {
130 1 2 uint64_t valid = (i == nw - 1 && cap % 64)
131 3 4 ? ((uint64_t)1 << (cap % 64)) - 1 : ~(uint64_t)0;
139 16 4 for (uint32_t i = 0; i < nw; i++)
147 6 1 for (uint32_t i = 0; i < nw; i++) {
149 2 4 if (word) {
151 2 0 return bit < cap ? (int64_t)bit : -1;
161 7 1 for (uint32_t i = 0; i < nw; i++) {
163 2 5 if (word != ~(uint64_t)0) {
165 1 1 return bit < cap ? (int64_t)bit : -1;
191 0 2 if (hdr->magic != BS_MAGIC) return 0;
192 0 2 if (hdr->version != BS_VERSION) return 0;
193 0 2 if (hdr->capacity == 0) return 0;
194 0 2 if (hdr->capacity > (uint64_t)(UINT32_MAX - 63) * 64) return 0;
195 0 2 if (hdr->total_size != file_size) return 0;
196 0 2 if (hdr->data_off != sizeof(BsHeader)) return 0;
198 0 2 if (hdr->num_words != exp_nw) return 0;
200 0 2 if (hdr->total_size != exp_total) return 0;
207 0 13 if (!h) { munmap(base, ms); return NULL; }
211 2 11 h->path = path ? strdup(path) : NULL;
217 5 0 if (errbuf) errbuf[0] = '\0';
218 0 5 if (capacity == 0) { BS_ERR("capacity must be > 0"); return NULL; }
0 0 if (capacity == 0) { BS_ERR("capacity must be > 0"); return NULL; }
220 0 5 if (capacity > (uint64_t)(UINT32_MAX - 63) * 64) { BS_ERR("capacity too large"); return NULL; }
0 0 if (capacity > (uint64_t)(UINT32_MAX - 63) * 64) { BS_ERR("capacity too large"); return NULL; }
228 3 2 if (anonymous) {
231 0 3 if (base == MAP_FAILED) { BS_ERR("mmap: %s", strerror(errno)); return NULL; }
0 0 if (base == MAP_FAILED) { BS_ERR("mmap: %s", strerror(errno)); return NULL; }
234 0 2 if (fd < 0) { BS_ERR("open: %s", strerror(errno)); return NULL; }
0 0 if (fd < 0) { BS_ERR("open: %s", strerror(errno)); return NULL; }
235 0 2 if (flock(fd, LOCK_EX) < 0) { BS_ERR("flock: %s", strerror(errno)); close(fd); return NULL; }
0 0 if (flock(fd, LOCK_EX) < 0) { BS_ERR("flock: %s", strerror(errno)); close(fd); return NULL; }
237 0 2 if (fstat(fd, &st) < 0) { BS_ERR("fstat: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; }
0 0 if (fstat(fd, &st) < 0) { BS_ERR("fstat: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; }
239 1 1 if (!is_new && (uint64_t)st.st_size < sizeof(BsHeader)) {
0 1 if (!is_new && (uint64_t)st.st_size < sizeof(BsHeader)) {
240 0 0 BS_ERR("%s: file too small (%lld)", path, (long long)st.st_size);
243 1 1 if (is_new && ftruncate(fd, (off_t)total) < 0) {
0 1 if (is_new && ftruncate(fd, (off_t)total) < 0) {
244 0 0 BS_ERR("ftruncate: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL;
246 1 1 map_size = is_new ? (size_t)total : (size_t)st.st_size;
248 0 2 if (base == MAP_FAILED) { BS_ERR("mmap: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; }
0 0 if (base == MAP_FAILED) { BS_ERR("mmap: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL; }
249 1 1 if (!is_new) {
250 0 1 if (!bs_validate_header((BsHeader *)base, (uint64_t)st.st_size)) {
251 0 0 BS_ERR("invalid bitset file"); munmap(base, map_size); flock(fd, LOCK_UN); close(fd); return NULL;
258 1 3 if (fd >= 0) { flock(fd, LOCK_UN); close(fd); }
263 7 0 if (errbuf) errbuf[0] = '\0';
264 0 7 if (capacity == 0) { BS_ERR("capacity must be > 0"); return NULL; }
0 0 if (capacity == 0) { BS_ERR("capacity must be > 0"); return NULL; }
266 0 7 if (capacity > (uint64_t)(UINT32_MAX - 63) * 64) { BS_ERR("capacity too large"); return NULL; }
0 0 if (capacity > (uint64_t)(UINT32_MAX - 63) * 64) { BS_ERR("capacity too large"); return NULL; }
268 7 0 int fd = memfd_create(name ? name : "bitset", MFD_CLOEXEC | MFD_ALLOW_SEALING);
269 0 7 if (fd < 0) { BS_ERR("memfd_create: %s", strerror(errno)); return NULL; }
0 0 if (fd < 0) { BS_ERR("memfd_create: %s", strerror(errno)); return NULL; }
270 0 7 if (ftruncate(fd, (off_t)total) < 0) { BS_ERR("ftruncate: %s", strerror(errno)); close(fd); return NULL; }
0 0 if (ftruncate(fd, (off_t)total) < 0) { BS_ERR("ftruncate: %s", strerror(errno)); close(fd); return NULL; }
273 0 7 if (base == MAP_FAILED) { BS_ERR("mmap: %s", strerror(errno)); close(fd); return NULL; }
0 0 if (base == MAP_FAILED) { BS_ERR("mmap: %s", strerror(errno)); close(fd); return NULL; }
279 1 0 if (errbuf) errbuf[0] = '\0';
281 0 1 if (fstat(fd, &st) < 0) { BS_ERR("fstat: %s", strerror(errno)); return NULL; }
0 0 if (fstat(fd, &st) < 0) { BS_ERR("fstat: %s", strerror(errno)); return NULL; }
282 0 1 if ((uint64_t)st.st_size < sizeof(BsHeader)) { BS_ERR("too small"); return NULL; }
0 0 if ((uint64_t)st.st_size < sizeof(BsHeader)) { BS_ERR("too small"); return NULL; }
285 0 1 if (base == MAP_FAILED) { BS_ERR("mmap: %s", strerror(errno)); return NULL; }
0 0 if (base == MAP_FAILED) { BS_ERR("mmap: %s", strerror(errno)); return NULL; }
286 0 1 if (!bs_validate_header((BsHeader *)base, (uint64_t)st.st_size)) {
287 0 0 BS_ERR("invalid bitset"); munmap(base, ms); return NULL;
290 0 1 if (myfd < 0) { BS_ERR("fcntl: %s", strerror(errno)); munmap(base, ms); return NULL; }
0 0 if (myfd < 0) { BS_ERR("fcntl: %s", strerror(errno)); munmap(base, ms); return NULL; }
295 0 13 if (!h) return;
296 8 5 if (h->backing_fd >= 0) close(h->backing_fd);
297 13 0 if (h->hdr) munmap(h->hdr, h->mmap_size);