From 459d2cb217e1af053f08d7e30a92b1b6bf61a90a Mon Sep 17 00:00:00 2001 From: Johannes Löthberg Date: Sun, 18 Jan 2015 15:41:09 +0100 Subject: sdsrange: change start/end args to ptrdiff_t MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit An sds string can hold a much bigger value than an int can hold, but since size_t is unsigned it can’t be used for this function. Using ptrdiff_t limits the function to work on roughly 1 Exabyte long strings, but if you need to work with longer ones you probably will have your custom string library already. --- src/sds.c | 3 ++- src/sds.h | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/sds.c b/src/sds.c index 0e62f31..96a6c4c 100644 --- a/src/sds.c +++ b/src/sds.c @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -388,7 +389,7 @@ void sdstrim(sds s, const char *cset) { * s = sdsnew("Hello World"); * sdsrange(s,1,-1); => "ello World" */ -void sdsrange(sds s, int start, int end) { +void sdsrange(sds s, ptrdiff_t start, ptrdiff_t end) { struct sdshdr *sh = sdsheader(s); size_t newlen, len = sdslen(s); diff --git a/src/sds.h b/src/sds.h index 86e2a8c..c0fe90e 100644 --- a/src/sds.h +++ b/src/sds.h @@ -77,7 +77,7 @@ sds sdscatprintf(sds s, const char *fmt, ...); #endif void sdstrim(sds s, const char *cset); -void sdsrange(sds s, int start, int end); +void sdsrange(sds s, ptrdiff_t start, ptrdiff_t end); void sdsupdatelen(sds s); void sdsclear(sds s); int sdscmp(const sds s1, const sds s2); -- cgit v1.2.3-70-g09d2