diff options
author | Simon Tatham <anakin@pobox.com> | 2019-02-11 09:58:07 +0300 |
---|---|---|
committer | Simon Tatham <anakin@pobox.com> | 2019-02-28 09:42:37 +0300 |
commit | d07d7d66f662b670a94c58e68a083f512e57e7a8 (patch) | |
tree | 8a9c66371f7767fc731b3cb7853b8c12435eb85d /logging.c | |
parent | e3e4315033a07c828608034d69feb83b6cda182a (diff) |
Replace more ad-hoc growing char buffers with strbuf.
I've fixed a handful of these where I found them in passing, but when
I went systematically looking, there were a lot more that I hadn't
found!
A particular highlight of this collection is the code that formats
Windows clipboard data in RTF, which was absolutely crying out for
strbuf_catf, and now it's got it.
Diffstat (limited to 'logging.c')
-rw-r--r-- | logging.c | 18 |
1 files changed, 5 insertions, 13 deletions
@@ -450,14 +450,11 @@ static Filename *xlatlognam(Filename *src, char *hostname, int port, { char buf[32], *bufp; int size; - char *buffer; - int buflen, bufsize; + strbuf *buffer; const char *s; Filename *ret; - bufsize = FILENAME_MAX; - buffer = snewn(bufsize, char); - buflen = 0; + buffer = strbuf_new(); s = filename_to_str(src); while (*s) { @@ -504,20 +501,15 @@ static Filename *xlatlognam(Filename *src, char *hostname, int port, buf[0] = *s++; size = 1; } - if (bufsize <= buflen + size) { - bufsize = (buflen + size) * 5 / 4 + 512; - buffer = sresize(buffer, bufsize, char); - } while (size-- > 0) { char c = *bufp++; if (sanitise) c = filename_char_sanitise(c); - buffer[buflen++] = c; + put_byte(buffer, c); } } - buffer[buflen] = '\0'; - ret = filename_from_str(buffer); - sfree(buffer); + ret = filename_from_str(buffer->s); + strbuf_free(buffer); return ret; } |