summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-09-01 23:55:07 -0400
committerDavid Robillard <d@drobilla.net>2022-09-02 00:05:26 -0400
commitafc6ef7e54988fd68f33df21ec2a220e6bfc49f4 (patch)
tree6dcef700e8a4a806d71162f56ef0585e4cc19993
parent1a4a2c607782eac013088ea8afb5a899e72b1f22 (diff)
downloadzix-afc6ef7e54988fd68f33df21ec2a220e6bfc49f4.tar.gz
zix-afc6ef7e54988fd68f33df21ec2a220e6bfc49f4.tar.bz2
zix-afc6ef7e54988fd68f33df21ec2a220e6bfc49f4.zip
Improve test coverage
-rw-r--r--src/allocator.c7
-rw-r--r--src/ring.c4
-rw-r--r--test/test_allocator.c1
3 files changed, 7 insertions, 5 deletions
diff --git a/src/allocator.c b/src/allocator.c
index ca91803..af6b8a9 100644
--- a/src/allocator.c
+++ b/src/allocator.c
@@ -60,9 +60,10 @@ zix_default_aligned_alloc(ZixAllocator* const allocator,
#if defined(_WIN32)
return _aligned_malloc(size, alignment);
#elif USE_POSIX_MEMALIGN
- void* ptr = NULL;
- const int ret = posix_memalign(&ptr, alignment, size);
- return ret ? NULL : ptr;
+ // POSIX.1-2008 TC2 says that ptr is not modified on failure
+ void* ptr = NULL;
+ posix_memalign(&ptr, alignment, size);
+ return ptr;
#else
return NULL;
#endif
diff --git a/src/ring.c b/src/ring.c
index 10b31e5..ca957e2 100644
--- a/src/ring.c
+++ b/src/ring.c
@@ -275,10 +275,10 @@ zix_ring_write(ZixRing* const ring, const void* src, const uint32_t size)
{
ZixRingTransaction tx = zix_ring_begin_write(ring);
- if (zix_ring_amend_write(ring, &tx, src, size) ||
- zix_ring_commit_write(ring, &tx)) {
+ if (zix_ring_amend_write(ring, &tx, src, size)) {
return 0;
}
+ zix_ring_commit_write(ring, &tx);
return size;
}
diff --git a/test/test_allocator.c b/test/test_allocator.c
index e146de6..425cc41 100644
--- a/test/test_allocator.c
+++ b/test/test_allocator.c
@@ -83,6 +83,7 @@ test_bump_allocator(void)
assert(!zix_realloc(&allocator.base, malloced, 8)); // Not the top
assert(!zix_realloc(&allocator.base, realloced, 4089)); // No space
+ assert(!zix_calloc(&allocator.base, 4089, 1)); // No space
zix_free(&allocator.base, realloced);