Branch Coverage

bitset.h
Criterion Covered Total %
branch 75 146 51.3


line true false branch
72 1 17 if (word & mask) return 1; /* already set */
73 17 0 if (__atomic_compare_exchange_n(&h->data[widx], &word, word | mask,
87 1 1 if (!(word & mask)) return 0; /* already clear */
88 1 0 if (__atomic_compare_exchange_n(&h->data[widx], &word, word & ~mask,
109 34 11 for (uint32_t i = 0; i < nw; i++) {
118 5 1 for (uint32_t i = 0; i < nw; i++)
119 1 4 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;
192 0 7 if (!h) { munmap(base, ms); return NULL; }
196 2 5 h->path = path ? strdup(path) : NULL;
202 5 0 if (errbuf) errbuf[0] = '\0';
203 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; }
205 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; }
213 3 2 if (anonymous) {
216 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; }
219 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; }
220 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; }
222 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; }
224 1 1 if (is_new && ftruncate(fd, (off_t)total) < 0) {
0 1 if (is_new && ftruncate(fd, (off_t)total) < 0) {
225 0 0 BS_ERR("ftruncate: %s", strerror(errno)); flock(fd, LOCK_UN); close(fd); return NULL;
227 1 1 map_size = is_new ? (size_t)total : (size_t)st.st_size;
229 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; }
230 1 1 if (!is_new) {
232 1 0 if (hdr->magic != BS_MAGIC || hdr->version != BS_VERSION ||
1 0 if (hdr->magic != BS_MAGIC || hdr->version != BS_VERSION ||
233 0 1 hdr->total_size != (uint64_t)st.st_size) {
234 0 0 BS_ERR("invalid bitset file"); munmap(base, map_size); flock(fd, LOCK_UN); close(fd); return NULL;
241 1 3 if (fd >= 0) { flock(fd, LOCK_UN); close(fd); }
246 1 0 if (errbuf) errbuf[0] = '\0';
247 0 1 if (capacity == 0) { BS_ERR("capacity must be > 0"); return NULL; }
0 0 if (capacity == 0) { BS_ERR("capacity must be > 0"); return NULL; }
249 0 1 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; }
251 1 0 int fd = memfd_create(name ? name : "bitset", MFD_CLOEXEC);
252 0 1 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; }
253 0 1 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; }
255 0 1 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; }
261 1 0 if (errbuf) errbuf[0] = '\0';
263 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; }
264 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; }
267 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; }
269 1 0 if (hdr->magic != BS_MAGIC || hdr->version != BS_VERSION ||
1 0 if (hdr->magic != BS_MAGIC || hdr->version != BS_VERSION ||
270 0 1 hdr->total_size != (uint64_t)st.st_size) {
271 0 0 BS_ERR("invalid bitset"); munmap(base, ms); return NULL;
274 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; }
279 0 7 if (!h) return;
280 2 5 if (h->backing_fd >= 0) close(h->backing_fd);
281 7 0 if (h->hdr) munmap(h->hdr, h->mmap_size);