changeset 21:939fe74cd80a

buf: switch to int from bool
author David Demelier <markand@malikania.fr>
date Wed, 24 Feb 2021 11:39:26 +0100
parents 08a6d4e6012d
children d87e84936795
files CHANGES.md buf-dup.c buf-int.h buf-printf.c buf-putc.c buf-puts.c buf-reserve.c buf-resize.c buf-shrink.c buf-sub.c buf-vprintf.c buf.c buf.h buf_dup.3 buf_printf.3 buf_putc.3 buf_puts.3 buf_reserve.3 buf_resize.3 buf_shrink.3 buf_sub.3 buf_vprintf.3 libbuf.3 test/test-dup.c test/test-printf.c test/test-putc.c test/test-puts.c test/test-reserve.c test/test-resize.c test/test-shrink.c test/test-sub.c
diffstat 31 files changed, 128 insertions(+), 124 deletions(-) [+]
line wrap: on
line diff
--- a/CHANGES.md	Wed Dec 16 16:20:53 2020 +0100
+++ b/CHANGES.md	Wed Feb 24 11:39:26 2021 +0100
@@ -1,6 +1,12 @@
 libbuf CHANGES
 ==============
 
+libbuf 0.3.0 2021-02-24
+-----------------------
+
+- Switch to `int` rather than bool (and return -1 in case of failures) as they
+  are less optimized.
+
 libbuf 0.2.0 2020-12-16
 -----------------------
 
--- a/buf-dup.c	Wed Dec 16 16:20:53 2020 +0100
+++ b/buf-dup.c	Wed Feb 24 11:39:26 2021 +0100
@@ -22,20 +22,20 @@
 
 #include "buf.h"
 
-bool
+int
 buf_dup(struct buf *b, const struct buf *src)
 {
 	assert(b);
 	assert(src);
 
 	if (!src->data)
-		return true;
+		return 0;
 	if (!(b->data = BUF_MALLOC(src->length + 1)))
-		return false;
+		return -1;
 
 	strcpy(b->data, src->data);
 	b->capacity = src->length;
 	b->length = src->length;
 
-	return true;
+	return 0;
 }
--- a/buf-int.h	Wed Dec 16 16:20:53 2020 +0100
+++ b/buf-int.h	Wed Feb 24 11:39:26 2021 +0100
@@ -17,15 +17,14 @@
  */
 
 #include <stddef.h>
-#include <stdbool.h>
 
 struct buf;
 
-bool
+int
 _buf_growdbl(struct buf *, size_t);
 
-bool
+int
 _buf_growmin(struct buf *, size_t);
 
-bool
+int
 _buf_grow(struct buf *, size_t);
--- a/buf-printf.c	Wed Dec 16 16:20:53 2020 +0100
+++ b/buf-printf.c	Wed Feb 24 11:39:26 2021 +0100
@@ -20,14 +20,14 @@
 
 #include "buf.h"
 
-bool
+int
 buf_printf(struct buf *b, const char *fmt, ...)
 {
 	assert(b);
 	assert(fmt);
 
 	va_list ap;
-	bool ret;
+	int ret;
 
 	va_start(ap, fmt);
 	ret = buf_vprintf(b, fmt, ap);
--- a/buf-putc.c	Wed Dec 16 16:20:53 2020 +0100
+++ b/buf-putc.c	Wed Feb 24 11:39:26 2021 +0100
@@ -21,16 +21,16 @@
 #include "buf.h"
 #include "buf-int.h"
 
-bool
+int
 buf_putc(struct buf *b, char c)
 {
 	assert(b);
 
-	if (!_buf_grow(b, 1))
-		return false;
+	if (_buf_grow(b, 1) < 0)
+		return -1;
 
 	b->data[b->length++] = c;
 	b->data[b->length] = 0;
 
-	return true;
+	return 0;
 }
--- a/buf-puts.c	Wed Dec 16 16:20:53 2020 +0100
+++ b/buf-puts.c	Wed Feb 24 11:39:26 2021 +0100
@@ -22,7 +22,7 @@
 #include "buf.h"
 #include "buf-int.h"
 
-bool
+int
 buf_puts(struct buf *b, const char *s)
 {
 	assert(b);
@@ -30,11 +30,11 @@
 
 	const size_t len = strlen(s);
 
-	if (!_buf_grow(b, len))
-		return false;
+	if (_buf_grow(b, len) < 0)
+		return -1;
 
 	memcpy(&b->data[b->length], s, len + 1);
 	b->length += len;
 
-	return true;
+	return 0;
 }
--- a/buf-reserve.c	Wed Dec 16 16:20:53 2020 +0100
+++ b/buf-reserve.c	Wed Feb 24 11:39:26 2021 +0100
@@ -21,13 +21,13 @@
 #include "buf.h"
 #include "buf-int.h"
 
-bool
+int
 buf_reserve(struct buf *b, size_t amount)
 {
 	assert(b);
 
-	if (!_buf_grow(b, amount))
-		return false;
+	if (_buf_grow(b, amount) < 0)
+		return -1;
 
-	return true;
+	return 0;
 }
--- a/buf-resize.c	Wed Dec 16 16:20:53 2020 +0100
+++ b/buf-resize.c	Wed Feb 24 11:39:26 2021 +0100
@@ -22,7 +22,7 @@
 #include "buf.h"
 #include "buf-int.h"
 
-bool
+int
 buf_resize(struct buf *b, size_t size, char ch)
 {
 	assert(b);
@@ -30,16 +30,16 @@
 	/* New size is smaller than curren't length, just update it. */
 	if (size < b->length) {
 		b->data[b->length = size] = 0;
-		return true;
+		return 0;
 	}
 
 	/* New size is bigger, data may be reallocated. */
-	if (!_buf_grow(b, size - b->length))
-		return false;
+	if (_buf_grow(b, size - b->length) < 0)
+		return -1;
 
 	memset(&b->data[b->length], ch, size - b->length);
 	b->length = size;
 	b->data[b->length] = 0;
 
-	return true;
+	return 0;
 }
--- a/buf-shrink.c	Wed Dec 16 16:20:53 2020 +0100
+++ b/buf-shrink.c	Wed Feb 24 11:39:26 2021 +0100
@@ -21,7 +21,7 @@
 
 #include "buf.h"
 
-bool
+int
 buf_shrink(struct buf *b)
 {
 	assert(b);
@@ -32,14 +32,14 @@
 		free(b->data);
 		b->data = NULL;
 		b->length = b->capacity = 0;
-		return true;
+		return 0;
 	}
 
 	if (!(newptr = BUF_REALLOC(b->data, b->length + 1)))
-		return false;
+		return -1;
 
 	b->data = newptr;
 	b->capacity = b->length;
 
-	return true;
+	return 0;
 }
--- a/buf-sub.c	Wed Dec 16 16:20:53 2020 +0100
+++ b/buf-sub.c	Wed Feb 24 11:39:26 2021 +0100
@@ -22,7 +22,7 @@
 
 #include "buf.h"
 
-bool
+int
 buf_sub(struct buf *b, const struct buf *src, size_t pos, size_t count)
 {
 	assert(b);
@@ -32,12 +32,12 @@
 	if (count >= src->length)
 		count = src->length - pos;
 	if (!(b->data = BUF_MALLOC(count + 1)))
-		return false;
+		return -1;
 
 	strncpy(b->data, &src->data[pos], count);
 	b->length = count;
 	b->capacity = count;
 	b->data[b->length] = 0;
 
-	return true;
+	return 0;
 }
--- a/buf-vprintf.c	Wed Dec 16 16:20:53 2020 +0100
+++ b/buf-vprintf.c	Wed Feb 24 11:39:26 2021 +0100
@@ -22,7 +22,7 @@
 #include "buf.h"
 #include "buf-int.h"
 
-bool
+int
 buf_vprintf(struct buf *b, const char *fmt, va_list args)
 {
 	assert(b);
@@ -37,20 +37,20 @@
 	va_end(ap);
 
 	if (amount < 0)
-		return false;
+		return -1;
 
 	/* Do actual copy. */
-	if (!_buf_grow(b, amount))
-		return false;
+	if (_buf_grow(b, amount) < 0)
+		return -1;
 
 	va_copy(ap, args);
 	amount = vsprintf(&b->data[b->length], fmt, ap);
 	va_end(ap);
 
 	if (amount < 0)
-		return false;
+		return -1;
 
 	b->length += amount;
 
-	return true;
+	return 0;
 }
--- a/buf.c	Wed Dec 16 16:20:53 2020 +0100
+++ b/buf.c	Wed Feb 24 11:39:26 2021 +0100
@@ -27,10 +27,10 @@
  * Try to increase the buffer length by a power of two until we have enough
  * space to fit `desired'.
  *
- * Detects overflow and return false if happened or reallocation could not
+ * Detects overflow and return -1 if happened or reallocation could not
  * occur.
  */
-bool
+int
 _buf_growdbl(struct buf *b, size_t desired)
 {
 	size_t newcap = b->capacity;
@@ -44,7 +44,7 @@
 #if defined(ENOMEM)
 			errno = ENOMEM;
 #endif
-			return false;
+			return -1;
 		}
 
 		newcap = r;
@@ -58,16 +58,16 @@
 #if defined(ENOMEM)
 		errno = ENOMEM;
 #endif
-		return false;
+		return -1;
 	}
 
 	if (!(newptr = BUF_REALLOC(b->data, newcap + 1)))
-		return false;
+		return -1;
 
 	b->data = newptr;
 	b->capacity = newcap;
 
-	return true;
+	return 0;
 }
 
 /*
@@ -75,9 +75,9 @@
  * only used when the buffer is already too large but hasn't reached SIZE_MAX
  * yet.
  *
- * Returns false if allocation failed.
+ * Returns -1 if allocation failed.
  */
-bool
+int
 _buf_growmin(struct buf *b, size_t desired)
 {
 	size_t newcap;
@@ -87,7 +87,7 @@
 #if defined(ENOMEM)
 		errno = ENOMEM;
 #endif
-		return false;
+		return -1;
 	}
 
 	/* Don't forget to keep what's remaining between capacity and length. */
@@ -95,33 +95,33 @@
 
 	/* Try to reallocate. */
 	if (!(newptr = BUF_REALLOC(b->data, newcap + 1)))
-		return false;
+		return -1;
 
 	b->data = newptr;
 	b->capacity = newcap;
 
-	return true;
+	return 0;
 }
 
 /*
  * Entry point for reallocating data. Will try to allocate twice until we have
  * enough room and then only the minimal amount.
  */
-bool
+int
 _buf_grow(struct buf *b, size_t desired)
 {
 	const size_t avail = b->capacity - b->length;
 
 	if (avail >= desired)
-		return true;
+		return 0;
 
 	if (!b->capacity) {
 		if (!(b->data = BUF_MALLOC(desired + 1)))
-			return false;
+			return -1;
 
 		b->capacity = desired;
-	} else if (!_buf_growdbl(b, desired) && !_buf_growmin(b, desired))
-		return false;
+	} else if (_buf_growdbl(b, desired) < 0 && _buf_growmin(b, desired) < 0)
+		return -1;
 
-	return true;
+	return 0;
 }
--- a/buf.h	Wed Dec 16 16:20:53 2020 +0100
+++ b/buf.h	Wed Feb 24 11:39:26 2021 +0100
@@ -20,7 +20,6 @@
 #define BUF_H
 
 #include <stdarg.h>
-#include <stdbool.h>
 #include <stddef.h>
 
 #if !defined(BUF_MALLOC)
@@ -48,34 +47,34 @@
 void
 buf_init(struct buf *b);
 
-bool
+int
 buf_reserve(struct buf *b, size_t desired);
 
-bool
+int
 buf_resize(struct buf *b, size_t size, char c);
 
-bool
+int
 buf_shrink(struct buf *b);
 
 void
 buf_erase(struct buf *b, size_t pos, size_t count);
 
-bool
+int
 buf_putc(struct buf *b, char c);
 
-bool
+int
 buf_puts(struct buf *b, const char *s);
 
-bool
+int
 buf_printf(struct buf *b, const char *fmt, ...);
 
-bool
+int
 buf_vprintf(struct buf *b, const char *fmt, va_list ap);
 
-bool
+int
 buf_sub(struct buf *b, const struct buf *src, size_t pos, size_t count);
 
-bool
+int
 buf_dup(struct buf *b, const struct buf *src);
 
 void
--- a/buf_dup.3	Wed Dec 16 16:20:53 2020 +0100
+++ b/buf_dup.3	Wed Feb 24 11:39:26 2021 +0100
@@ -25,7 +25,7 @@
 .\" SYNOPSIS
 .Sh SYNOPSIS
 .In buf.h
-.Ft bool
+.Ft int
 .Fn buf_dup "struct buf *b" "const struct buf *src"
 .\" DESCRIPTION
 .Sh DESCRIPTION
@@ -40,11 +40,11 @@
 buffer isn't initialized (and contains a NULL data field) the destination
 buffer
 .Fa b
-is unchanged but the function returns true.
+is unchanged but the function returns 0.
 .Pp
 Otherwise the
 .Fn buf_dup
-function returns false in case of error and
+function returns -1 in case of error and
 .Va errno
 is set to indicate the error.
 .\" ERRORS
--- a/buf_printf.3	Wed Dec 16 16:20:53 2020 +0100
+++ b/buf_printf.3	Wed Feb 24 11:39:26 2021 +0100
@@ -25,7 +25,7 @@
 .\" SYNOPSIS
 .Sh SYNOPSIS
 .In buf.h
-.Ft bool
+.Ft int
 .Fn buf_printf "struct buf *b" "const char *fmt" "..."
 .\" DESCRIPTION
 .Sh DESCRIPTION
@@ -42,7 +42,7 @@
 .Sh RETURN VALUE
 The
 .Fn buf_printf
-function returns false in case of error and
+function returns -1 in case of error and
 .Va errno
 is set to indicate the error.
 .\" ERRORS
--- a/buf_putc.3	Wed Dec 16 16:20:53 2020 +0100
+++ b/buf_putc.3	Wed Feb 24 11:39:26 2021 +0100
@@ -25,7 +25,7 @@
 .\" SYNOPSIS
 .Sh SYNOPSIS
 .In buf.h
-.Ft bool
+.Ft int
 .Fn buf_putc "struct buf *b" "char c"
 .\" DESCRIPTION
 .Sh DESCRIPTION
@@ -44,7 +44,7 @@
 .Sh RETURN VALUE
 The
 .Fn buf_putc
-function returns false in case of error and
+function returns -1 in case of error and
 .Va errno
 is set to indicate the error.
 .\" ERRORS
--- a/buf_puts.3	Wed Dec 16 16:20:53 2020 +0100
+++ b/buf_puts.3	Wed Feb 24 11:39:26 2021 +0100
@@ -25,7 +25,7 @@
 .\" SYNOPSIS
 .Sh SYNOPSIS
 .In buf.h
-.Ft bool
+.Ft int
 .Fn buf_puts "struct buf *b" "const char *src"
 .\" DESCRIPTION
 .Sh DESCRIPTION
@@ -41,7 +41,7 @@
 .Sh RETURN VALUE
 The
 .Fn buf_puts
-function returns false in case of error and
+function returns -1 in case of error and
 .Va errno
 is set to indicate the error.
 .\" ERRORS
--- a/buf_reserve.3	Wed Dec 16 16:20:53 2020 +0100
+++ b/buf_reserve.3	Wed Feb 24 11:39:26 2021 +0100
@@ -25,7 +25,7 @@
 .\" SYNOPSIS
 .Sh SYNOPSIS
 .In buf.h
-.Ft bool
+.Ft int
 .Fn buf_reserve "struct buf *b" "size_t desired"
 .\" DESCRIPTION
 .Sh DESCRIPTION
@@ -48,7 +48,7 @@
 .Sh RETURN VALUE
 The
 .Fn buf_reserve
-function returns false in case of error and
+function returns -1 in case of error and
 .Va errno
 is set to indicate the error.
 .\" ERRORS
--- a/buf_resize.3	Wed Dec 16 16:20:53 2020 +0100
+++ b/buf_resize.3	Wed Feb 24 11:39:26 2021 +0100
@@ -25,7 +25,7 @@
 .\" SYNOPSIS
 .Sh SYNOPSIS
 .In buf.h
-.Ft bool
+.Ft int
 .Fn buf_resize "struct buf *b" "size_t size" "char c"
 .\" DESCRIPTION
 .Sh DESCRIPTION
@@ -56,7 +56,7 @@
 .Sh RETURN VALUE
 The
 .Fn buf_resize
-function returns false in case of error and
+function returns -1 in case of error and
 .Va errno
 is set to indicate the error.
 .\" ERRORS
--- a/buf_shrink.3	Wed Dec 16 16:20:53 2020 +0100
+++ b/buf_shrink.3	Wed Feb 24 11:39:26 2021 +0100
@@ -25,7 +25,7 @@
 .\" SYNOPSIS
 .Sh SYNOPSIS
 .In buf.h
-.Ft bool
+.Ft int
 .Fn buf_shrink "struct buf *b"
 .\" DESCRIPTION
 .Sh DESCRIPTION
@@ -43,11 +43,11 @@
 .\" RETURN VALUE
 .Sh RETURN VALUE
 If the buffer's length is 0, the function simply frees the underlying data and
-return true.
+return 0.
 .Pp
 Otherwise the
 .Fn buf_shrink
-function returns false in case of error and
+function returns -1 in case of error and
 .Va errno
 is set to indicate the error.
 .\" ERRORS
--- a/buf_sub.3	Wed Dec 16 16:20:53 2020 +0100
+++ b/buf_sub.3	Wed Feb 24 11:39:26 2021 +0100
@@ -25,7 +25,7 @@
 .\" SYNOPSIS
 .Sh SYNOPSIS
 .In buf.h
-.Ft bool
+.Ft int
 .Fn buf_sub "struct buf *b" "const struct buf *src" "size_t pos" "size_t count"
 .\" DESCRIPTION
 .Sh DESCRIPTION
@@ -56,7 +56,7 @@
 .Sh RETURN VALUE
 The
 .Fn buf_sub
-function returns false in case of error and
+function returns -1 in case of error and
 .Va errno
 is set to indicate the error.
 .\" ERRORS
--- a/buf_vprintf.3	Wed Dec 16 16:20:53 2020 +0100
+++ b/buf_vprintf.3	Wed Feb 24 11:39:26 2021 +0100
@@ -25,7 +25,7 @@
 .\" SYNOPSIS
 .Sh SYNOPSIS
 .In buf.h
-.Ft bool
+.Ft int
 .Fn buf_vprintf "struct buf *b" "const char *fmt" "va_list ap"
 .\" DESCRIPTION
 .Sh DESCRIPTION
@@ -42,7 +42,7 @@
 .Sh RETURN VALUE
 The
 .Fn buf_vprintf
-function returns false in case of error and
+function returns -1 in case of error and
 .Va errno
 is set to indicate the error.
 .\" ERRORS
--- a/libbuf.3	Wed Dec 16 16:20:53 2020 +0100
+++ b/libbuf.3	Wed Feb 24 11:39:26 2021 +0100
@@ -30,29 +30,29 @@
 .In buf.h
 .Ft void
 .Fn buf_clear "struct buf *b"
-.Ft bool
+.Ft int
 .Fn buf_dup "struct buf *b" "const struct buf *src"
 .Ft void
 .Fn buf_erase "struct buf *b" "size_t pos" "size_t count"
 .Ft void
 .Fn buf_finish "struct buf *b"
-.Ft bool
+.Ft int
 .Fn buf_init "struct buf *b"
-.Ft bool
+.Ft int
 .Fn buf_printf "struct buf *b" "const char *fmt" "..."
-.Ft bool
+.Ft int
 .Fn buf_putc "struct buf *b" "char c"
-.Ft bool
+.Ft int
 .Fn buf_puts "struct buf *b" "const char *s"
-.Ft bool
+.Ft int
 .Fn buf_reserve "struct buf *b" "size_t desired"
-.Ft bool
+.Ft int
 .Fn buf_resize "struct buf *b" "size_t desired" "char c"
-.Ft bool
+.Ft int
 .Fn buf_shrink "struct buf *b"
-.Ft bool
+.Ft int
 .Fn buf_sub "struct buf *b" "const struct buf *src" "size_t pos" "size_t count"
-.Ft bool
+.Ft int
 .Fn buf_vprintf "struct buf *b" "const char *fmt" "va_list ap"
 .\" DESCRIPTION
 .Sh DESCRIPTION
--- a/test/test-dup.c	Wed Dec 16 16:20:53 2020 +0100
+++ b/test/test-dup.c	Wed Feb 24 11:39:26 2021 +0100
@@ -27,8 +27,8 @@
 	struct buf b = {0};
 	struct buf d = {0};
 
-	buf_puts(&b, "0123456789");
-	buf_dup(&d, &b);
+	GREATEST_ASSERT_EQ(0, buf_puts(&b, "0123456789"));
+	GREATEST_ASSERT_EQ(0, buf_dup(&d, &b));
 	GREATEST_ASSERT(b.data != d.data);
 	GREATEST_ASSERT_STR_EQ(d.data, "0123456789");
 	GREATEST_ASSERT_EQ(d.length, 10U);
@@ -44,7 +44,7 @@
 	struct buf b = {0};
 	struct buf d = {0};
 
-	buf_dup(&d, &b);
+	GREATEST_ASSERT_EQ(0, buf_dup(&d, &b));
 	GREATEST_ASSERT(!d.data);
 	GREATEST_ASSERT_EQ(d.length, 0U);
 	GREATEST_ASSERT_EQ(d.capacity, 0U);
--- a/test/test-printf.c	Wed Dec 16 16:20:53 2020 +0100
+++ b/test/test-printf.c	Wed Feb 24 11:39:26 2021 +0100
@@ -27,13 +27,13 @@
 	struct buf b = {0};
 
 	/* This will allocate string of 6 characters. */
-	buf_printf(&b, "%d%d", 123, 456);
+	GREATEST_ASSERT_EQ(0, buf_printf(&b, "%d%d", 123, 456));
 	GREATEST_ASSERT_STR_EQ(b.data, "123456");
 	GREATEST_ASSERT_EQ(b.length, 6U);
 	GREATEST_ASSERT_EQ(b.capacity, 6U);
 
 	/* This will multiply the capacity to 12 and increase length to 10. */
-	buf_printf(&b, "%s", "hoho");
+	GREATEST_ASSERT_EQ(0, buf_printf(&b, "%s", "hoho"));
 	GREATEST_ASSERT_STR_EQ(b.data, "123456hoho");
 	GREATEST_ASSERT_EQ(b.length, 10U);
 	GREATEST_ASSERT_EQ(b.capacity, 12U);
--- a/test/test-putc.c	Wed Dec 16 16:20:53 2020 +0100
+++ b/test/test-putc.c	Wed Feb 24 11:39:26 2021 +0100
@@ -27,29 +27,29 @@
 	struct buf b = {0};
 
 	/* This will allocate one byte and then increase by power of two. */
-	buf_putc(&b, 'a');
+	GREATEST_ASSERT_EQ(0, buf_putc(&b, 'a'));
 	GREATEST_ASSERT_STR_EQ(b.data, "a");
 	GREATEST_ASSERT_EQ(b.length, 1U);
 	GREATEST_ASSERT_EQ(b.capacity, 1U);
 
-	buf_putc(&b, 'b');
+	GREATEST_ASSERT_EQ(0, buf_putc(&b, 'b'));
 	GREATEST_ASSERT_STR_EQ(b.data, "ab");
 	GREATEST_ASSERT_EQ(b.length, 2U);
 	GREATEST_ASSERT_EQ(b.capacity, 2U);
 
-	buf_putc(&b, 'c');
+	GREATEST_ASSERT_EQ(0, buf_putc(&b, 'c'));
 	GREATEST_ASSERT_STR_EQ(b.data, "abc");
 	GREATEST_ASSERT_EQ(b.length, 3U);
 	GREATEST_ASSERT_EQ(b.capacity, 4U);
 
 	/* No reallocation since there is still one byte left. */
-	buf_putc(&b, 'd');
+	GREATEST_ASSERT_EQ(0, buf_putc(&b, 'd'));
 	GREATEST_ASSERT_STR_EQ(b.data, "abcd");
 	GREATEST_ASSERT_EQ(b.length, 4U);
 	GREATEST_ASSERT_EQ(b.capacity, 4U);
 
 	/* New reallocation here. */
-	buf_putc(&b, 'e');
+	GREATEST_ASSERT_EQ(0, buf_putc(&b, 'e'));
 	GREATEST_ASSERT_STR_EQ(b.data, "abcde");
 	GREATEST_ASSERT_EQ(b.length, 5U);
 	GREATEST_ASSERT_EQ(b.capacity, 8U);
--- a/test/test-puts.c	Wed Dec 16 16:20:53 2020 +0100
+++ b/test/test-puts.c	Wed Feb 24 11:39:26 2021 +0100
@@ -27,13 +27,13 @@
 	struct buf b = {0};
 
 	/* This will allocate an initial buffer of 10. */
-	buf_puts(&b, "abcdefghij");
+	GREATEST_ASSERT_EQ(0, buf_puts(&b, "abcdefghij"));
 	GREATEST_ASSERT_STR_EQ(b.data, "abcdefghij");
 	GREATEST_ASSERT_EQ(b.length, 10U);
 	GREATEST_ASSERT_EQ(b.capacity, 10U);
 
 	/* This will multiply the capacity to 20 and increase length to 14. */
-	buf_puts(&b, "klmn");
+	GREATEST_ASSERT_EQ(0, buf_puts(&b, "klmn"));
 	GREATEST_ASSERT_STR_EQ(b.data, "abcdefghijklmn");
 	GREATEST_ASSERT_EQ(b.length, 14U);
 	GREATEST_ASSERT_EQ(b.capacity, 20U);
--- a/test/test-reserve.c	Wed Dec 16 16:20:53 2020 +0100
+++ b/test/test-reserve.c	Wed Feb 24 11:39:26 2021 +0100
@@ -27,7 +27,7 @@
 	struct buf b = {0};
 
 	/* Reserve allocates but does not change length. */
-	buf_reserve(&b, 100U);
+	GREATEST_ASSERT_EQ(0, buf_reserve(&b, 100U));
 	GREATEST_ASSERT(b.data);
 	GREATEST_ASSERT_EQ(b.length, 0U);
 	GREATEST_ASSERT_EQ(b.capacity, 100U);
@@ -36,13 +36,13 @@
 	 * Now we have a capacity of 100, if I request 100 again it should not
 	 * change capacity.
 	 */
-	buf_reserve(&b, 100U);
+	GREATEST_ASSERT_EQ(0, buf_reserve(&b, 100U));
 	GREATEST_ASSERT(b.data);
 	GREATEST_ASSERT_EQ(b.length, 0U);
 	GREATEST_ASSERT_EQ(b.capacity, 100U);
 
 	/* But if I reserve more, it should. */
-	buf_reserve(&b, 200U);
+	GREATEST_ASSERT_EQ(0, buf_reserve(&b, 200U));
 	GREATEST_ASSERT(b.data);
 	GREATEST_ASSERT_EQ(b.length, 0U);
 	GREATEST_ASSERT_EQ(b.capacity, 200U);
--- a/test/test-resize.c	Wed Dec 16 16:20:53 2020 +0100
+++ b/test/test-resize.c	Wed Feb 24 11:39:26 2021 +0100
@@ -27,13 +27,13 @@
 	struct buf b = {0};
 
 	/* Resize actually change the length with the specified character. */
-	buf_resize(&b, 10, 'a');
+	GREATEST_ASSERT_EQ(0, buf_resize(&b, 10, 'a'));
 	GREATEST_ASSERT_STR_EQ(b.data, "aaaaaaaaaa");
 	GREATEST_ASSERT_EQ(b.length, 10U);
 	GREATEST_ASSERT_EQ(b.capacity, 10U);
 
 	/* Add some more letters. */
-	buf_resize(&b, b.length + 5, 'b');
+	GREATEST_ASSERT_EQ(0, buf_resize(&b, b.length + 5, 'b'));
 	GREATEST_ASSERT_STR_EQ(b.data, "aaaaaaaaaabbbbb");
 	GREATEST_ASSERT_EQ(b.length, 15U);
 	GREATEST_ASSERT_EQ(b.capacity, 20U);
@@ -48,13 +48,13 @@
 {
 	struct buf b = {0};
 
-	buf_resize(&b, 10, 'a');
+	GREATEST_ASSERT_EQ(0, buf_resize(&b, 10, 'a'));
 	GREATEST_ASSERT_STR_EQ(b.data, "aaaaaaaaaa");
 	GREATEST_ASSERT_EQ(b.length, 10U);
 	GREATEST_ASSERT_EQ(b.capacity, 10U);
 
 	/* Resize smaller, the letter 'b' should not even appear. */
-	buf_resize(&b, 5, 'b');
+	GREATEST_ASSERT_EQ(0, buf_resize(&b, 5, 'b'));
 	GREATEST_ASSERT_STR_EQ(b.data, "aaaaa");
 	GREATEST_ASSERT_EQ(b.length, 5U);
 	GREATEST_ASSERT_EQ(b.capacity, 10U);
--- a/test/test-shrink.c	Wed Dec 16 16:20:53 2020 +0100
+++ b/test/test-shrink.c	Wed Feb 24 11:39:26 2021 +0100
@@ -27,9 +27,9 @@
 	struct buf b = {0};
 
 	/* Reserve 10 but write 5 character, shrink should set a capacity of 5. */
-	buf_reserve(&b, 10U);
-	buf_puts(&b, "abcde");
-	buf_shrink(&b);
+	GREATEST_ASSERT_EQ(0, buf_reserve(&b, 10U));
+	GREATEST_ASSERT_EQ(0, buf_puts(&b, "abcde"));
+	GREATEST_ASSERT_EQ(0, buf_shrink(&b));
 	GREATEST_ASSERT_STR_EQ(b.data, "abcde");
 	GREATEST_ASSERT_EQ(b.length, 5U);
 	GREATEST_ASSERT_EQ(b.capacity, 5U);
@@ -47,8 +47,8 @@
 	 * Reserve 10, the data should be allocated but since we have a null
 	 * length it should be completely free'd.
 	 */
-	buf_reserve(&b, 10U);
-	buf_shrink(&b);
+	GREATEST_ASSERT_EQ(0, buf_reserve(&b, 10U));
+	GREATEST_ASSERT_EQ(0, buf_shrink(&b));
 	GREATEST_ASSERT(!b.data);
 	GREATEST_ASSERT_EQ(b.length, 0U);
 	GREATEST_ASSERT_EQ(b.capacity, 0U);
@@ -62,7 +62,7 @@
 {
 	struct buf b = {0};
 
-	buf_shrink(&b);
+	GREATEST_ASSERT_EQ(0, buf_shrink(&b));
 	GREATEST_ASSERT(!b.data);
 	GREATEST_ASSERT_EQ(b.length, 0U);
 	GREATEST_ASSERT_EQ(b.capacity, 0U);
--- a/test/test-sub.c	Wed Dec 16 16:20:53 2020 +0100
+++ b/test/test-sub.c	Wed Feb 24 11:39:26 2021 +0100
@@ -30,14 +30,14 @@
 	buf_puts(&b, "0123456789");
 
 	/* Copy only the portion from 1 to 3. */
-	GREATEST_ASSERT(buf_sub(&s1, &b, 1, 3));
+	GREATEST_ASSERT_EQ(0, buf_sub(&s1, &b, 1, 3));
 	GREATEST_ASSERT_STR_EQ(s1.data, "123");
 	GREATEST_ASSERT_EQ(s1.length, 3U);
 	GREATEST_ASSERT_EQ(s1.capacity, 3U);
 	buf_finish(&s1);
 
 	/* Copy whole string starting from 4. */
-	GREATEST_ASSERT(buf_sub(&s2, &b, 4, -1));
+	GREATEST_ASSERT_EQ(0, buf_sub(&s2, &b, 4, -1));
 	GREATEST_ASSERT_STR_EQ(s2.data, "456789");
 	GREATEST_ASSERT_EQ(s2.length, 6U);
 	GREATEST_ASSERT_EQ(s2.capacity, 6U);