Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mRemoteNG/PuTTYNG.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Tatham <anakin@pobox.com>2019-02-11 09:58:07 +0300
committerSimon Tatham <anakin@pobox.com>2019-02-28 09:42:37 +0300
commitd07d7d66f662b670a94c58e68a083f512e57e7a8 (patch)
tree8a9c66371f7767fc731b3cb7853b8c12435eb85d /logging.c
parente3e4315033a07c828608034d69feb83b6cda182a (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.c18
1 files changed, 5 insertions, 13 deletions
diff --git a/logging.c b/logging.c
index 51444ea3..bfe90b52 100644
--- a/logging.c
+++ b/logging.c
@@ -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;
}