1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-13 00:57:33 -05:00

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.
This commit is contained in:
Simon Tatham
2019-02-11 06:58:07 +00:00
parent e3e4315033
commit d07d7d66f6
13 changed files with 194 additions and 311 deletions

View File

@ -548,34 +548,33 @@ bool enum_settings_next(settings_e *handle, strbuf *out)
{
struct dirent *de;
struct stat st;
char *fullpath;
int maxlen, thislen, len;
strbuf *fullpath;
if (!handle->dp)
return NULL;
fullpath = make_filename(INDEX_SESSIONDIR, NULL);
maxlen = len = strlen(fullpath);
fullpath = strbuf_new();
char *sessiondir = make_filename(INDEX_SESSIONDIR, NULL);
put_datapl(fullpath, ptrlen_from_asciz(sessiondir));
sfree(sessiondir);
put_byte(fullpath, '/');
size_t baselen = fullpath->len;
while ( (de = readdir(handle->dp)) != NULL ) {
thislen = len + 1 + strlen(de->d_name);
if (maxlen < thislen) {
maxlen = thislen;
fullpath = sresize(fullpath, maxlen+1, char);
}
fullpath[len] = '/';
strncpy(fullpath+len+1, de->d_name, thislen - (len+1));
fullpath[thislen] = '\0';
fullpath->len = baselen;
put_datapl(fullpath, ptrlen_from_asciz(de->d_name));
if (stat(fullpath, &st) < 0 || !S_ISREG(st.st_mode))
if (stat(fullpath->s, &st) < 0 || !S_ISREG(st.st_mode))
continue; /* try another one */
decode_session_filename(de->d_name, out);
sfree(fullpath);
strbuf_free(fullpath);
return true;
}
sfree(fullpath);
strbuf_free(fullpath);
return false;
}