summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--package/deps.mak1
-rw-r--r--src/include/skalibs/stralloc.h3
-rw-r--r--src/libstddjb/stralloc_readyplus_tuned.c12
3 files changed, 15 insertions, 1 deletions
diff --git a/package/deps.mak b/package/deps.mak
index 8d89640..3f1bc4f 100644
--- a/package/deps.mak
+++ b/package/deps.mak
@@ -581,6 +581,7 @@ src/libstddjb/stralloc_copyb.o src/libstddjb/stralloc_copyb.lo: src/libstddjb/st
src/libstddjb/stralloc_free.o src/libstddjb/stralloc_free.lo: src/libstddjb/stralloc_free.c src/include/skalibs/alloc.h src/include/skalibs/stralloc.h
src/libstddjb/stralloc_insertb.o src/libstddjb/stralloc_insertb.lo: src/libstddjb/stralloc_insertb.c src/include/skalibs/stralloc.h
src/libstddjb/stralloc_ready_tuned.o src/libstddjb/stralloc_ready_tuned.lo: src/libstddjb/stralloc_ready_tuned.c src/include/skalibs/alloc.h src/include/skalibs/stralloc.h
+src/libstddjb/stralloc_readyplus_tuned.o src/libstddjb/stralloc_readyplus_tuned.lo: src/libstddjb/stralloc_readyplus_tuned.c src/include/skalibs/stralloc.h
src/libstddjb/stralloc_reverse.o src/libstddjb/stralloc_reverse.lo: src/libstddjb/stralloc_reverse.c src/include/skalibs/stralloc.h
src/libstddjb/stralloc_reverse_blocks.o src/libstddjb/stralloc_reverse_blocks.lo: src/libstddjb/stralloc_reverse_blocks.c src/include/skalibs/stralloc.h
src/libstddjb/stralloc_shrink.o src/libstddjb/stralloc_shrink.lo: src/libstddjb/stralloc_shrink.c src/include/skalibs/alloc.h src/include/skalibs/stralloc.h
diff --git a/src/include/skalibs/stralloc.h b/src/include/skalibs/stralloc.h
index b5f89ca..9572251 100644
--- a/src/include/skalibs/stralloc.h
+++ b/src/include/skalibs/stralloc.h
@@ -18,8 +18,9 @@ struct stralloc_s
extern stralloc const stralloc_zero ;
extern int stralloc_ready_tuned (stralloc *, size_t, size_t, size_t, size_t) ;
+extern int stralloc_readyplus_tuned (stralloc *, size_t, size_t, size_t, size_t) ;
#define stralloc_ready(sa, n) stralloc_ready_tuned(sa, (n), 8, 1, 8)
-#define stralloc_readyplus(sa, n) stralloc_ready(sa, (sa)->len + (n))
+#define stralloc_readyplus(sa, n) stralloc_readyplus_tuned(sa, (n), 8, 1, 8)
extern void stralloc_free (stralloc *) ;
extern int stralloc_shrink (stralloc *) ;
extern int stralloc_copyb (stralloc *, char const *, size_t) ;
diff --git a/src/libstddjb/stralloc_readyplus_tuned.c b/src/libstddjb/stralloc_readyplus_tuned.c
new file mode 100644
index 0000000..f00813f
--- /dev/null
+++ b/src/libstddjb/stralloc_readyplus_tuned.c
@@ -0,0 +1,12 @@
+/* ISC license. */
+
+#include <errno.h>
+#include <skalibs/stralloc.h>
+
+int stralloc_readyplus_tuned (stralloc *sa, size_t n, size_t base, size_t a, size_t b)
+{
+ size_t newlen = sa->len + n ;
+ return newlen < sa->len ?
+ (errno = ERANGE, 0) :
+ stralloc_ready_tuned(sa, newlen, base, a, b) ;
+}