diff options
author | Mark Pulford <mark@kyne.com.au> | 2016-04-13 12:12:18 +0300 |
---|---|---|
committer | Mark Pulford <mark@kyne.com.au> | 2016-04-13 12:12:18 +0300 |
commit | 7eb09593cbddfa682f81f198734ce508b519fe00 (patch) | |
tree | a7f519fe7efdbd3f2c71e235b1f4e5855e3cac5c /strbuf.c | |
parent | 1740e529ca7a9c249b7c8aaeec7336d8000bd192 (diff) |
Fix build with g++
- Add explicit casts for functions returning void*
- Rename "try" variable to avoid reserved C++ keyword
Diffstat (limited to 'strbuf.c')
-rw-r--r-- | strbuf.c | 13 |
1 files changed, 7 insertions, 6 deletions
@@ -58,7 +58,7 @@ void strbuf_init(strbuf_t *s, int len) s->reallocs = 0; s->debug = 0; - s->buf = malloc(size); + s->buf = (char *)malloc(size); if (!s->buf) die("Out of memory"); @@ -69,7 +69,7 @@ strbuf_t *strbuf_new(int len) { strbuf_t *s; - s = malloc(sizeof(strbuf_t)); + s = (strbuf_t*)malloc(sizeof(strbuf_t)); if (!s) die("Out of memory"); @@ -173,7 +173,7 @@ void strbuf_resize(strbuf_t *s, int len) } s->size = newsize; - s->buf = realloc(s->buf, s->size); + s->buf = (char *)realloc(s->buf, s->size); if (!s->buf) die("Out of memory"); s->reallocs++; @@ -221,12 +221,13 @@ void strbuf_append_fmt(strbuf_t *s, int len, const char *fmt, ...) void strbuf_append_fmt_retry(strbuf_t *s, const char *fmt, ...) { va_list arg; - int fmt_len, try; + int fmt_len; int empty_len; + int t; /* If the first attempt to append fails, resize the buffer appropriately * and try again */ - for (try = 0; ; try++) { + for (t = 0; ; t++) { va_start(arg, fmt); /* Append the new formatted string */ /* fmt_len is the length of the string required, excluding the @@ -238,7 +239,7 @@ void strbuf_append_fmt_retry(strbuf_t *s, const char *fmt, ...) if (fmt_len <= empty_len) break; /* SUCCESS */ - if (try > 0) + if (t > 0) die("BUG: length of formatted string changed"); strbuf_resize(s, s->length + fmt_len); |