1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-06-30 19:12:48 -05:00

New functions to shrink a strbuf.

These are better than my previous approach of just assigning to
sb->len, because firstly they check by assertion that the new length
is within range, and secondly they preserve the invariant that the
byte stored in the buffer just after the length runs out is \0.

Switched to using the new functions everywhere a grep could turn up
opportunities.

(cherry picked from commit 5891142aee)
This commit is contained in:
Simon Tatham
2020-01-21 20:16:28 +00:00
parent 2c66217af8
commit 34a0460f05
17 changed files with 45 additions and 29 deletions

View File

@ -3835,7 +3835,7 @@ static void eventlog_list_handler(union control *ctrl, dlgparam *dp,
/*
* Construct the data to use as the selection.
*/
es->seldata->len = 0;
strbuf_clear(es->seldata);
for (i = 0; i < es->ninitial; i++) {
if (dlg_listbox_issel(ctrl, dp, i))
strbuf_catf(es->seldata, "%s\n", es->events_initial[i]);

View File

@ -252,7 +252,7 @@ SockAddr *sk_namelookup(const char *host, char **canonicalname, int address_fami
return ret;
}
/* This way we are always sure the h->h_name is valid :) */
realhost->len = 0;
strbuf_clear(realhost);
strbuf_catf(realhost, "%s", h->h_name);
for (n = 0; h->h_addr_list[n]; n++);
ret->addresses = snewn(n, unsigned long);
@ -267,7 +267,7 @@ SockAddr *sk_namelookup(const char *host, char **canonicalname, int address_fami
* success return from inet_addr.
*/
ret->superfamily = IP;
realhost->len = 0;
strbuf_clear(realhost);
strbuf_catf(realhost, "%s", host);
ret->addresses = snew(unsigned long);
ret->naddresses = 1;

View File

@ -564,7 +564,7 @@ bool enum_settings_next(settings_e *handle, strbuf *out)
size_t baselen = fullpath->len;
while ( (de = readdir(handle->dp)) != NULL ) {
fullpath->len = baselen;
strbuf_shrink_to(fullpath, baselen);
put_datapl(fullpath, ptrlen_from_asciz(de->d_name));
if (stat(fullpath->s, &st) < 0 || !S_ISREG(st.st_mode))