summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2021-12-14 23:14:08 +0100
committerTyge Løvset <[email protected]>2021-12-14 23:14:08 +0100
commita2671650430bf12304bead0bc9f23903f03db8a6 (patch)
treeee30476d64d645789a3524a1690d78aed8e050f0 /include
parent8f5c9a16cae3dcf53be7deb49f4c589ca1ffe6a1 (diff)
downloadSTC-modified-a2671650430bf12304bead0bc9f23903f03db8a6.tar.gz
STC-modified-a2671650430bf12304bead0bc9f23903f03db8a6.zip
Fixed bug in cbits_to_str().
Diffstat (limited to 'include')
-rw-r--r--include/stc/cbits.h12
1 files changed, 8 insertions, 4 deletions
diff --git a/include/stc/cbits.h b/include/stc/cbits.h
index 1816f41a..b3a70edc 100644
--- a/include/stc/cbits.h
+++ b/include/stc/cbits.h
@@ -196,13 +196,17 @@ STC_DEF cbits cbits_with_values(size_t size, uint64_t pattern) {
}
STC_DEF cbits cbits_from_n(const char* str, size_t n) {
cbits set = cbits_with_size(n, false);
- for (size_t i=0; i<set.size; ++i) if (str[i] == '1') cbits_set(&set, i);
+ for (size_t i=0; i<set.size; ++i)
+ if (str[i] == '1') cbits_set(&set, i);
return set;
}
STC_DEF char* cbits_to_str(cbits set, char* out, size_t start, intptr_t stop) {
- size_t end = stop < 0 ? set.size : stop;
- for (size_t i=start; i<end; ++i) out[i] = cbits_test(set, i) ? '1' : '0';
- out[end] = '\0'; return out;
+ if (stop < 0) stop = set.size;
+ memset(out, '0', stop - start);
+ for (intptr_t i=start; i<stop; ++i)
+ if (cbits_test(set, i)) out[i - start] = '1';
+ out[stop - start] = '\0';
+ return out;
}
STC_DEF cbits cbits_clone(cbits other) {
size_t bytes = ((other.size + 63) >> 6) * 8;