diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2020-09-17 23:31:28 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2020-09-17 23:31:28 +0000 |
commit | 24f08a61e6456fb2bdf1382000a0b4b3bf910d45 (patch) | |
tree | 8394f915dba6343116c15cc2dd80249bacf0286f /src | |
parent | 8c16e68dda72032e81a624360b1abb1006e33481 (diff) | |
download | skalibs-24f08a61e6456fb2bdf1382000a0b4b3bf910d45.tar.xz |
Add stralloc_readyplus_tuned, fix overflow on stralloc_readyplus
Diffstat (limited to 'src')
-rw-r--r-- | src/include/skalibs/stralloc.h | 3 | ||||
-rw-r--r-- | src/libstddjb/stralloc_readyplus_tuned.c | 12 |
2 files changed, 14 insertions, 1 deletions
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) ; +} |