86a1ed3
From edb7fc727a29f4ae8dcd6fee02fb5c08286808c5 Mon Sep 17 00:00:00 2001
86a1ed3
From: "Richard W.M. Jones" <rjones@redhat.com>
86a1ed3
Date: Thu, 9 Mar 2017 13:25:33 +0000
86a1ed3
Subject: [PATCH 09/26] common/strbuf.c: Use size_t and ssize_t.
86a1ed3
86a1ed3
On 64 bit machines, strings can be longer than 2^32 characters.
86a1ed3
size_t or ssize_t should be used to handle all offsets and lengths of
86a1ed3
such strings to avoid overflow.
86a1ed3
86a1ed3
This makes the fairly mechanical change int32_t -> ssize_t and
86a1ed3
uint32_t -> size_t.
86a1ed3
86a1ed3
Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
86a1ed3
---
86a1ed3
 common/strbuf.c | 80 ++++++++++++++++++++++++++++-----------------------------
86a1ed3
 common/strbuf.h | 50 ++++++++++++++++++------------------
86a1ed3
 2 files changed, 65 insertions(+), 65 deletions(-)
86a1ed3
86a1ed3
diff --git a/common/strbuf.c b/common/strbuf.c
86a1ed3
index 5c42873..cf90d5a 100644
86a1ed3
--- a/common/strbuf.c
86a1ed3
+++ b/common/strbuf.c
86a1ed3
@@ -36,12 +36,12 @@
86a1ed3
 
86a1ed3
 #define DEFAULT_STRBUF_CAPACITY 16
86a1ed3
 
86a1ed3
-#define SWAP_INT32(a,b) { int32_t _t = (a); (a) = (b); (b) = _t; }
86a1ed3
+#define SWAP_SSIZE_T(a,b) { ssize_t _t = (a); (a) = (b); (b) = _t; }
86a1ed3
 
86a1ed3
-static int32_t
86a1ed3
-normalize_strbuf_pos(StrBuf *sb, int32_t pos)
86a1ed3
+static ssize_t
86a1ed3
+normalize_strbuf_pos(StrBuf *sb, ssize_t pos)
86a1ed3
 {
86a1ed3
-    if (pos >= sb->len)
86a1ed3
+    if (pos >= (ssize_t) sb->len)
86a1ed3
         return sb->len;
86a1ed3
     if (pos >= 0)
86a1ed3
         return pos;
86a1ed3
@@ -51,8 +51,8 @@ normalize_strbuf_pos(StrBuf *sb, int32_t pos)
86a1ed3
     return 0;
86a1ed3
 }
86a1ed3
 
86a1ed3
-static int32_t
86a1ed3
-normalize_str_pos(const char *str, int32_t pos)
86a1ed3
+static ssize_t
86a1ed3
+normalize_str_pos(const char *str, ssize_t pos)
86a1ed3
 {
86a1ed3
     if (str == NULL)
86a1ed3
         return 0;
86a1ed3
@@ -70,13 +70,13 @@ strbuf_buffer(StrBuf *sb)
86a1ed3
     return sb->buf;
86a1ed3
 }
86a1ed3
 
86a1ed3
-uint32_t
86a1ed3
+size_t
86a1ed3
 strbuf_length(StrBuf *sb)
86a1ed3
 {
86a1ed3
     return sb->len;
86a1ed3
 }
86a1ed3
 
86a1ed3
-uint32_t
86a1ed3
+size_t
86a1ed3
 strbuf_capacity(StrBuf *sb)
86a1ed3
 {
86a1ed3
     return sb->capacity;
86a1ed3
@@ -89,7 +89,7 @@ strbuf_new(void)
86a1ed3
 }
86a1ed3
 
86a1ed3
 StrBuf *
86a1ed3
-strbuf_new_with_capacity(uint32_t capacity)
86a1ed3
+strbuf_new_with_capacity(size_t capacity)
86a1ed3
 {
86a1ed3
     StrBuf *sb;
86a1ed3
     sb = xmalloc(sizeof(StrBuf));
86a1ed3
@@ -102,24 +102,24 @@ strbuf_new_with_capacity(uint32_t capacity)
86a1ed3
 }
86a1ed3
 
86a1ed3
 StrBuf *
86a1ed3
-strbuf_new_from_char_n(uint32_t times, char ch)
86a1ed3
+strbuf_new_from_char_n(size_t times, char ch)
86a1ed3
 {
86a1ed3
     return strbuf_new_from_substring_n(times, &ch, 0, 1);
86a1ed3
 }
86a1ed3
 
86a1ed3
 StrBuf *
86a1ed3
-strbuf_new_from_substring_n(uint32_t times, const char *substr, int32_t subsp, int32_t subep)
86a1ed3
+strbuf_new_from_substring_n(size_t times, const char *substr, ssize_t subsp, ssize_t subep)
86a1ed3
 {
86a1ed3
     subsp = normalize_str_pos(substr, subsp);
86a1ed3
     subep = normalize_str_pos(substr, subep);
86a1ed3
     if (subsp > subep)
86a1ed3
-    	SWAP_INT32(subsp, subep);
86a1ed3
+    	SWAP_SSIZE_T(subsp, subep);
86a1ed3
 
86a1ed3
     return strbuf_new_from_data_n(times, substr+subsp, subep-subsp);
86a1ed3
 }
86a1ed3
 
86a1ed3
 StrBuf *
86a1ed3
-strbuf_new_from_data_n(uint32_t times, const void *mem, uint32_t len)
86a1ed3
+strbuf_new_from_data_n(size_t times, const void *mem, size_t len)
86a1ed3
 {
86a1ed3
     StrBuf *sb;
86a1ed3
 
86a1ed3
@@ -133,7 +133,7 @@ strbuf_new_from_data_n(uint32_t times, const void *mem, uint32_t len)
86a1ed3
 }
86a1ed3
 
86a1ed3
 StrBuf *
86a1ed3
-strbuf_newf_n(uint32_t times, const char *fmt, ...)
86a1ed3
+strbuf_newf_n(size_t times, const char *fmt, ...)
86a1ed3
 {
86a1ed3
     va_list ap;
86a1ed3
     StrBuf *buf;
86a1ed3
@@ -146,7 +146,7 @@ strbuf_newf_n(uint32_t times, const char *fmt, ...)
86a1ed3
 }
86a1ed3
 
86a1ed3
 StrBuf *
86a1ed3
-strbuf_vnewf_n(uint32_t times, const char *fmt, va_list ap)
86a1ed3
+strbuf_vnewf_n(size_t times, const char *fmt, va_list ap)
86a1ed3
 {
86a1ed3
     char *str;
86a1ed3
     int len;
86a1ed3
@@ -171,7 +171,7 @@ strbuf_free(StrBuf *sb)
86a1ed3
 }
86a1ed3
 
86a1ed3
 char *
86a1ed3
-strbuf_free_to_substring(StrBuf *sb, int32_t sp, int32_t ep)
86a1ed3
+strbuf_free_to_substring(StrBuf *sb, ssize_t sp, ssize_t ep)
86a1ed3
 {
86a1ed3
     char *buf;
86a1ed3
 
86a1ed3
@@ -182,7 +182,7 @@ strbuf_free_to_substring(StrBuf *sb, int32_t sp, int32_t ep)
86a1ed3
     sb->buf[ep-sp] = '\0';
86a1ed3
 
86a1ed3
     /* Call realloc so that unused memory can be used for other purpose. */
86a1ed3
-    if (sp == 0 && ep == sb->len)
86a1ed3
+    if (sp == 0 && ep == (ssize_t) sb->len)
86a1ed3
 	buf = sb->buf;
86a1ed3
     else
86a1ed3
 	buf = xrealloc(sb->buf, ep-sp+1);
86a1ed3
@@ -191,21 +191,21 @@ strbuf_free_to_substring(StrBuf *sb, int32_t sp, int32_t ep)
86a1ed3
 }
86a1ed3
 
86a1ed3
 void
86a1ed3
-strbuf_replace_char_n(StrBuf *sb, int32_t sp, int32_t ep, uint32_t times, char ch)
86a1ed3
+strbuf_replace_char_n(StrBuf *sb, ssize_t sp, ssize_t ep, size_t times, char ch)
86a1ed3
 {
86a1ed3
     strbuf_replace_substring_n(sb, sp, ep, times, &ch, 0, 1);
86a1ed3
 }
86a1ed3
 
86a1ed3
 void
86a1ed3
-strbuf_replace_data_n(StrBuf *sb, int32_t sp, int32_t ep, uint32_t times, const void *mem, uint32_t len)
86a1ed3
+strbuf_replace_data_n(StrBuf *sb, ssize_t sp, ssize_t ep, size_t times, const void *mem, size_t len)
86a1ed3
 {
86a1ed3
-    uint32_t addlen;
86a1ed3
-    uint32_t dellen;
86a1ed3
+    size_t addlen;
86a1ed3
+    size_t dellen;
86a1ed3
 
86a1ed3
     sp = normalize_strbuf_pos(sb, sp);
86a1ed3
     ep = normalize_strbuf_pos(sb, ep);
86a1ed3
     if (sp > ep)
86a1ed3
-    	SWAP_INT32(sp, ep);
86a1ed3
+    	SWAP_SSIZE_T(sp, ep);
86a1ed3
 
86a1ed3
     addlen = len * times;
86a1ed3
     dellen = ep-sp;
86a1ed3
@@ -223,18 +223,18 @@ strbuf_replace_data_n(StrBuf *sb, int32_t sp, int32_t ep, uint32_t times, const
86a1ed3
 }
86a1ed3
 
86a1ed3
 void
86a1ed3
-strbuf_replace_substring_n(StrBuf *sb, int32_t sp, int32_t ep, uint32_t times, const char *substr, int32_t subsp, int32_t subep)
86a1ed3
+strbuf_replace_substring_n(StrBuf *sb, ssize_t sp, ssize_t ep, size_t times, const char *substr, ssize_t subsp, ssize_t subep)
86a1ed3
 {
86a1ed3
     subsp = normalize_str_pos(substr, subsp);
86a1ed3
     subep = normalize_str_pos(substr, subep);
86a1ed3
     if (subsp > subep)
86a1ed3
-    	SWAP_INT32(subsp, subep);
86a1ed3
+    	SWAP_SSIZE_T(subsp, subep);
86a1ed3
 
86a1ed3
     strbuf_replace_data_n(sb, sp, ep, times, substr+subsp, subep-subsp);
86a1ed3
 }
86a1ed3
 
86a1ed3
 int
86a1ed3
-strbuf_replacef_n(StrBuf *sb, int32_t sp, int32_t ep, uint32_t times, const char *fmt, ...)
86a1ed3
+strbuf_replacef_n(StrBuf *sb, ssize_t sp, ssize_t ep, size_t times, const char *fmt, ...)
86a1ed3
 {
86a1ed3
     va_list ap;
86a1ed3
     int len;
86a1ed3
@@ -247,7 +247,7 @@ strbuf_replacef_n(StrBuf *sb, int32_t sp, int32_t ep, uint32_t times, const char
86a1ed3
 }
86a1ed3
 
86a1ed3
 int
86a1ed3
-strbuf_vreplacef_n(StrBuf *sb, int32_t sp, int32_t ep, uint32_t times, const char *fmt, va_list ap)
86a1ed3
+strbuf_vreplacef_n(StrBuf *sb, ssize_t sp, ssize_t ep, size_t times, const char *fmt, va_list ap)
86a1ed3
 {
86a1ed3
     char *str;
86a1ed3
     int len;
86a1ed3
@@ -255,7 +255,7 @@ strbuf_vreplacef_n(StrBuf *sb, int32_t sp, int32_t ep, uint32_t times, const cha
86a1ed3
     sp = normalize_strbuf_pos(sb, sp);
86a1ed3
     ep = normalize_strbuf_pos(sb, ep);
86a1ed3
     if (sp > ep)
86a1ed3
-    	SWAP_INT32(sp, ep);
86a1ed3
+    	SWAP_SSIZE_T(sp, ep);
86a1ed3
 
86a1ed3
     len = vasprintf(&str, fmt, ap);
86a1ed3
     if (len < 0)
86a1ed3
@@ -267,29 +267,29 @@ strbuf_vreplacef_n(StrBuf *sb, int32_t sp, int32_t ep, uint32_t times, const cha
86a1ed3
 }
86a1ed3
 
86a1ed3
 void
86a1ed3
-strbuf_reverse_substring(StrBuf *sb, int32_t sp, int32_t ep)
86a1ed3
+strbuf_reverse_substring(StrBuf *sb, ssize_t sp, ssize_t ep)
86a1ed3
 {
86a1ed3
     sp = normalize_strbuf_pos(sb, sp);
86a1ed3
     ep = normalize_strbuf_pos(sb, ep);
86a1ed3
 
86a1ed3
     while (sp < ep) {
86a1ed3
-    	SWAP_INT32(sb->buf[sp], sb->buf[ep]);
86a1ed3
+    	SWAP_SSIZE_T(sb->buf[sp], sb->buf[ep]);
86a1ed3
     	sp++;
86a1ed3
 	ep--;
86a1ed3
     }
86a1ed3
 }
86a1ed3
 
86a1ed3
 void
86a1ed3
-strbuf_repeat_substring(StrBuf *sb, int32_t sp, int32_t ep, uint32_t times)
86a1ed3
+strbuf_repeat_substring(StrBuf *sb, ssize_t sp, ssize_t ep, size_t times)
86a1ed3
 {
86a1ed3
-    int32_t addlen;
86a1ed3
+    ssize_t addlen;
86a1ed3
 
86a1ed3
     sp = normalize_strbuf_pos(sb, sp);
86a1ed3
     ep = normalize_strbuf_pos(sb, ep);
86a1ed3
 
86a1ed3
     addlen = (ep-sp) * (times - 1);
86a1ed3
     if (addlen != 0) {
86a1ed3
-    	uint32_t p;
86a1ed3
+    	size_t p;
86a1ed3
 
86a1ed3
     	strbuf_ensure_capacity(sb, sb->len+1+addlen);
86a1ed3
 	memmove(sb->buf+sp+addlen, sb->buf+ep, sb->len+1-ep);
86a1ed3
@@ -304,7 +304,7 @@ strbuf_repeat_substring(StrBuf *sb, int32_t sp, int32_t ep, uint32_t times)
86a1ed3
 }
86a1ed3
 
86a1ed3
 void
86a1ed3
-strbuf_set_length(StrBuf *sb, uint32_t new_length)
86a1ed3
+strbuf_set_length(StrBuf *sb, size_t new_length)
86a1ed3
 {
86a1ed3
     strbuf_ensure_capacity(sb, new_length+1);
86a1ed3
     sb->buf[new_length] = '\0';
86a1ed3
@@ -313,7 +313,7 @@ strbuf_set_length(StrBuf *sb, uint32_t new_length)
86a1ed3
 
86a1ed3
 /* Note: The terminating null-byte counts as 1 in min_capacity */
86a1ed3
 void
86a1ed3
-strbuf_ensure_capacity(StrBuf *sb, uint32_t min_capacity)
86a1ed3
+strbuf_ensure_capacity(StrBuf *sb, size_t min_capacity)
86a1ed3
 {
86a1ed3
     if (min_capacity > sb->capacity) {
86a1ed3
 	sb->capacity = MAX(min_capacity, sb->len*2+2); /* MAX -> max */
86a1ed3
@@ -324,14 +324,14 @@ strbuf_ensure_capacity(StrBuf *sb, uint32_t min_capacity)
86a1ed3
 }
86a1ed3
 
86a1ed3
 char *
86a1ed3
-strbuf_substring(StrBuf *sb, int32_t sp, int32_t ep)
86a1ed3
+strbuf_substring(StrBuf *sb, ssize_t sp, ssize_t ep)
86a1ed3
 {
86a1ed3
     char *str;
86a1ed3
 
86a1ed3
     sp = normalize_strbuf_pos(sb, sp);
86a1ed3
     ep = normalize_strbuf_pos(sb, ep);
86a1ed3
     if (sp > ep)
86a1ed3
-    	SWAP_INT32(sp, ep);
86a1ed3
+    	SWAP_SSIZE_T(sp, ep);
86a1ed3
 
86a1ed3
     str = xmalloc((ep-sp+1) * sizeof(char));
86a1ed3
     memcpy(str, sb->buf+sp, (ep-sp+1) * sizeof(char));
86a1ed3
@@ -341,14 +341,14 @@ strbuf_substring(StrBuf *sb, int32_t sp, int32_t ep)
86a1ed3
 }
86a1ed3
 
86a1ed3
 char
86a1ed3
-strbuf_char_at(StrBuf *sb, int32_t sp)
86a1ed3
+strbuf_char_at(StrBuf *sb, ssize_t sp)
86a1ed3
 {
86a1ed3
     return sb->buf[normalize_strbuf_pos(sb, sp)];
86a1ed3
 }
86a1ed3
 
86a1ed3
 #if 0
86a1ed3
 char
86a1ed3
-strbuf_set_char_at(StrBuf *sb, int32_t sp, char chr)
86a1ed3
+strbuf_set_char_at(StrBuf *sb, ssize_t sp, char chr)
86a1ed3
 {
86a1ed3
     char old;
86a1ed3
 
86a1ed3
@@ -364,13 +364,13 @@ strbuf_set_char_at(StrBuf *sb, int32_t sp, char chr)
86a1ed3
 }
86a1ed3
 
86a1ed3
 void
86a1ed3
-strbuf_replace_strbuf(StrBuf *sb, int32_t sp, int32_t ep, StrBuf *strbuf)
86a1ed3
+strbuf_replace_strbuf(StrBuf *sb, ssize_t sp, ssize_t ep, StrBuf *strbuf)
86a1ed3
 {
86a1ed3
     strbuf_replace_data_n(sb,sp,ep,1,strbuf->buf,strbuf->len);
86a1ed3
 }
86a1ed3
 
86a1ed3
 char
86a1ed3
-strbuf_delete_char(StrBuf *sb, int32_t sp)
86a1ed3
+strbuf_delete_char(StrBuf *sb, ssize_t sp)
86a1ed3
 {
86a1ed3
 
86a1ed3
 }
86a1ed3
diff --git a/common/strbuf.h b/common/strbuf.h
86a1ed3
index 67a523d..6cd0d58 100644
86a1ed3
--- a/common/strbuf.h
86a1ed3
+++ b/common/strbuf.h
86a1ed3
@@ -28,16 +28,16 @@ typedef struct _StrBuf StrBuf;
86a1ed3
 
86a1ed3
 struct _StrBuf {
86a1ed3
     char *buf;
86a1ed3
-    uint32_t len;
86a1ed3
-    uint32_t capacity;
86a1ed3
+    size_t len;
86a1ed3
+    size_t capacity;
86a1ed3
 };
86a1ed3
 
86a1ed3
 void strbuf_free(StrBuf *sb);
86a1ed3
 #define strbuf_free_to_string(sb)			strbuf_free_to_substring(sb,0,-1)
86a1ed3
-char *strbuf_free_to_substring(StrBuf *sb, int32_t sp, int32_t ep);
86a1ed3
+char *strbuf_free_to_substring(StrBuf *sb, ssize_t sp, ssize_t ep);
86a1ed3
 
86a1ed3
 StrBuf *strbuf_new(void);
86a1ed3
-StrBuf *strbuf_new_with_capacity(uint32_t capacity);
86a1ed3
+StrBuf *strbuf_new_with_capacity(size_t capacity);
86a1ed3
 
86a1ed3
 #define strbuf_new_from_char(chr)			strbuf_new_from_char_n(1,chr)
86a1ed3
 #define strbuf_new_from_string(str) 	    	    	strbuf_new_from_substring(str,0,-1)
86a1ed3
@@ -46,12 +46,12 @@ StrBuf *strbuf_new_with_capacity(uint32_t capacity);
86a1ed3
 #define strbuf_new_from_substring(str,ssp,sep)		strbuf_new_from_substring_n(1,str,ssp,sep)
86a1ed3
 #define strbuf_newf(fmt...)				strbuf_newf_n(1,fmt)
86a1ed3
 #define strbuf_vnewf(fmt,ap)				strbuf_vnewf_n(1,fmt,ap)
86a1ed3
-StrBuf *strbuf_new_from_char_n(uint32_t times, char ch);
86a1ed3
+StrBuf *strbuf_new_from_char_n(size_t times, char ch);
86a1ed3
 #define strbuf_new_from_string_n(n,str)			strbuf_new_from_substring_n(n,str,0,-1)
86a1ed3
-StrBuf *strbuf_new_from_substring_n(uint32_t times, const char *str, int32_t sp, int32_t ep);
86a1ed3
-StrBuf *strbuf_new_from_data_n(uint32_t times, const void *mem, uint32_t len);
86a1ed3
-StrBuf *strbuf_newf_n(uint32_t times, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
86a1ed3
-StrBuf *strbuf_vnewf_n(uint32_t times, const char *fmt, va_list ap) __attribute__ ((format (printf, 2, 0)));
86a1ed3
+StrBuf *strbuf_new_from_substring_n(size_t times, const char *str, ssize_t sp, ssize_t ep);
86a1ed3
+StrBuf *strbuf_new_from_data_n(size_t times, const void *mem, size_t len);
86a1ed3
+StrBuf *strbuf_newf_n(size_t times, const char *fmt, ...) __attribute__ ((format (printf, 2, 3)));
86a1ed3
+StrBuf *strbuf_vnewf_n(size_t times, const char *fmt, va_list ap) __attribute__ ((format (printf, 2, 0)));
86a1ed3
 
86a1ed3
 #define strbuf_append_char(sb,chr)   	    	        strbuf_append_char_n(sb,1,chr)
86a1ed3
 #define strbuf_append(sb,str) 	    	    	        strbuf_append_n(sb,1,str)
86a1ed3
@@ -116,38 +116,38 @@ StrBuf *strbuf_vnewf_n(uint32_t times, const char *fmt, va_list ap) __attribute_
86a1ed3
 #define strbuf_replace_char(sb,sp,ep,ch)                strbuf_replace_char_n(sb,sp,ep,1,ch)
86a1ed3
 #define strbuf_replace(sb,sp,ep,str)	    	        strbuf_replace_n(sb,sp,ep,1,str)
86a1ed3
 #define strbuf_replace_data(sb,sp,ep,mem,len)	    	strbuf_replace_data_n(sb,sp,ep,1,mem,len)
86a1ed3
-void strbuf_replace_strbuf(StrBuf *sb, int32_t sp, int32_t ep, StrBuf *strbuf); /* or strbuf_replace_data_n(sb,sp,ep,1,strbuf_buffer(strbuf),strbuf_length(strbuf))*/
86a1ed3
+void strbuf_replace_strbuf(StrBuf *sb, ssize_t sp, ssize_t ep, StrBuf *strbuf); /* or strbuf_replace_data_n(sb,sp,ep,1,strbuf_buffer(strbuf),strbuf_length(strbuf))*/
86a1ed3
 #define strbuf_replace_substring(sb,sp,ep,str,ssp,sep)  strbuf_replace_substring_n(sb,sp,ep,1,str,ssp,sep)
86a1ed3
 #define strbuf_replacef(sb,sp,ep,fmt...)                strbuf_replacef_n(sb,sp,ep,1,fmt)
86a1ed3
 #define strbuf_vreplacef(sb,sp,ep,fmt,ap)               strbuf_vreplacef_n(sb,sp,ep,1,fmt,ap)
86a1ed3
-void strbuf_replace_char_n(StrBuf *sb, int32_t sp, int32_t ep, uint32_t times, char ch);
86a1ed3
+void strbuf_replace_char_n(StrBuf *sb, ssize_t sp, ssize_t ep, size_t times, char ch);
86a1ed3
 #define strbuf_replace_n(sb,sp,ep,n,str)	    	strbuf_replace_substring_n(sb,sp,ep,n,str,0,-1)
86a1ed3
-void strbuf_replace_substring_n(StrBuf *sb, int32_t sp, int32_t ep, uint32_t times, const char *str, int32_t ssp, int32_t sep);
86a1ed3
-void strbuf_replace_data_n(StrBuf *sb, int32_t sp, int32_t ep, uint32_t times, const void *mem, uint32_t len);
86a1ed3
-int strbuf_replacef_n(StrBuf *sb, int32_t sp, int32_t ep, uint32_t times, const char *fmt, ...) __attribute__ ((format (printf, 5, 6)));
86a1ed3
-int strbuf_vreplacef_n(StrBuf *sb, int32_t sp, int32_t ep, uint32_t times, const char *fmt, va_list ap) __attribute__ ((format (printf, 5, 0)));
86a1ed3
+void strbuf_replace_substring_n(StrBuf *sb, ssize_t sp, ssize_t ep, size_t times, const char *str, ssize_t ssp, ssize_t sep);
86a1ed3
+void strbuf_replace_data_n(StrBuf *sb, ssize_t sp, ssize_t ep, size_t times, const void *mem, size_t len);
86a1ed3
+int strbuf_replacef_n(StrBuf *sb, ssize_t sp, ssize_t ep, size_t times, const char *fmt, ...) __attribute__ ((format (printf, 5, 6)));
86a1ed3
+int strbuf_vreplacef_n(StrBuf *sb, ssize_t sp, ssize_t ep, size_t times, const char *fmt, va_list ap) __attribute__ ((format (printf, 5, 0)));
86a1ed3
 
86a1ed3
-char strbuf_set_char_at(StrBuf *sb, int32_t sp, char chr); 	/* or strbuf_replace_char(sb,sp,strbuf_next_pos(sb,sp),chr) */
86a1ed3
-char strbuf_delete_char(StrBuf *sb, int32_t sp); 		/* or strbuf_replace(sb,sp,strbuf_next_pos(sb,sp),NULL) */
86a1ed3
+char strbuf_set_char_at(StrBuf *sb, ssize_t sp, char chr); 	/* or strbuf_replace_char(sb,sp,strbuf_next_pos(sb,sp),chr) */
86a1ed3
+char strbuf_delete_char(StrBuf *sb, ssize_t sp); 		/* or strbuf_replace(sb,sp,strbuf_next_pos(sb,sp),NULL) */
86a1ed3
 #define strbuf_delete(sb,sp,ep)   	    	        strbuf_replace(sb,sp,ep,NULL)
86a1ed3
 #define strbuf_clear(sb)   	    	    	        strbuf_replace(sb,0,-1,NULL)
86a1ed3
 
86a1ed3
-void strbuf_reverse_substring(StrBuf *sb, int32_t sp, int32_t ep);
86a1ed3
+void strbuf_reverse_substring(StrBuf *sb, ssize_t sp, ssize_t ep);
86a1ed3
 #define strbuf_reverse(sb)  	    	    	        strbuf_reverse_substring(sb,0,-1)
86a1ed3
 
86a1ed3
-void strbuf_repeat_substring(StrBuf *sb, int32_t sp, int32_t ep, uint32_t times);
86a1ed3
+void strbuf_repeat_substring(StrBuf *sb, ssize_t sp, ssize_t ep, size_t times);
86a1ed3
 #define strbuf_repeat(sb,n)  	    	    	        strbuf_repeat_substring(sb,0,-1,n)
86a1ed3
 
86a1ed3
-uint32_t strbuf_length(StrBuf *sb);
86a1ed3
-uint32_t strbuf_capacity(StrBuf *sb);
86a1ed3
+size_t strbuf_length(StrBuf *sb);
86a1ed3
+size_t strbuf_capacity(StrBuf *sb);
86a1ed3
 char *strbuf_buffer(StrBuf *sb);
86a1ed3
 #define strbuf_is_empty(sb)				(strbuf_length(sb) == 0)
86a1ed3
 
86a1ed3
-void strbuf_set_length(StrBuf *sb, uint32_t new_length);
86a1ed3
-void strbuf_ensure_capacity(StrBuf *sb, uint32_t minimum_capacity); /* minimum_capacity should account for null-byte */
86a1ed3
+void strbuf_set_length(StrBuf *sb, size_t new_length);
86a1ed3
+void strbuf_ensure_capacity(StrBuf *sb, size_t minimum_capacity); /* minimum_capacity should account for null-byte */
86a1ed3
 
86a1ed3
-char *strbuf_substring(StrBuf *sb, int32_t sp, int32_t ep);
86a1ed3
+char *strbuf_substring(StrBuf *sb, ssize_t sp, ssize_t ep);
86a1ed3
 #define strbuf_to_string(sb)	    	    	        strbuf_substring(sb,0,-1)
86a1ed3
-char strbuf_char_at(StrBuf *sb, int32_t index);
86a1ed3
+char strbuf_char_at(StrBuf *sb, ssize_t index);
86a1ed3
 
86a1ed3
 #endif
86a1ed3
-- 
86a1ed3
2.10.2
86a1ed3