mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-03 20:42:48 -05:00
Make bufchain_prefix return a ptrlen.
Now that all the call sites are expecting a size_t instead of an int length field, it's no longer particularly difficult to make it actually return the pointer,length pair in the form of a ptrlen. It would be nice to say that simplifies call sites because those ptrlens can all be passed straight along to other ptrlen-consuming functions. Actually almost none of the call sites are like that _yet_, but this makes it possible to move them in that direction in future (as part of my general aim to migrate ptrlen-wards as much as I can). But also it's just nicer to keep the pointer and length together in one variable, and not have to declare them both in advance with two extra lines of boilerplate.
This commit is contained in:
@ -249,19 +249,18 @@ void ssh_verstring_handle_input(BinaryPacketProtocol *bpp)
|
||||
* If we didn't find it, consume data until we see a newline.
|
||||
*/
|
||||
while (1) {
|
||||
size_t len;
|
||||
void *data;
|
||||
ptrlen data;
|
||||
char *nl;
|
||||
|
||||
/* Wait to receive at least 1 byte, but then consume more
|
||||
* than that if it's there. */
|
||||
BPP_WAITFOR(1);
|
||||
bufchain_prefix(s->bpp.in_raw, &data, &len);
|
||||
if ((nl = memchr(data, '\012', len)) != NULL) {
|
||||
bufchain_consume(s->bpp.in_raw, nl - (char *)data + 1);
|
||||
data = bufchain_prefix(s->bpp.in_raw);
|
||||
if ((nl = memchr(data.ptr, '\012', data.len)) != NULL) {
|
||||
bufchain_consume(s->bpp.in_raw, nl - (char *)data.ptr + 1);
|
||||
break;
|
||||
} else {
|
||||
bufchain_consume(s->bpp.in_raw, len);
|
||||
bufchain_consume(s->bpp.in_raw, data.len);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -281,24 +280,24 @@ void ssh_verstring_handle_input(BinaryPacketProtocol *bpp)
|
||||
*/
|
||||
s->i = 0;
|
||||
do {
|
||||
size_t len;
|
||||
void *data;
|
||||
ptrlen data;
|
||||
char *nl;
|
||||
|
||||
BPP_WAITFOR(1);
|
||||
bufchain_prefix(s->bpp.in_raw, &data, &len);
|
||||
if ((nl = memchr(data, '\012', len)) != NULL) {
|
||||
len = nl - (char *)data + 1;
|
||||
data = bufchain_prefix(s->bpp.in_raw);
|
||||
if ((nl = memchr(data.ptr, '\012', data.len)) != NULL) {
|
||||
data.len = nl - (char *)data.ptr + 1;
|
||||
}
|
||||
|
||||
if (s->vslen >= s->vstrsize - 1 || len >= s->vstrsize - 1 - s->vslen) {
|
||||
s->vstrsize = (s->vslen + len) * 5 / 4 + 32;
|
||||
if (s->vslen >= s->vstrsize - 1 ||
|
||||
data.len >= s->vstrsize - 1 - s->vslen) {
|
||||
s->vstrsize = (s->vslen + data.len) * 5 / 4 + 32;
|
||||
s->vstring = sresize(s->vstring, s->vstrsize, char);
|
||||
}
|
||||
|
||||
memcpy(s->vstring + s->vslen, data, len);
|
||||
s->vslen += len;
|
||||
bufchain_consume(s->bpp.in_raw, len);
|
||||
memcpy(s->vstring + s->vslen, data.ptr, data.len);
|
||||
s->vslen += data.len;
|
||||
bufchain_consume(s->bpp.in_raw, data.len);
|
||||
|
||||
} while (s->vstring[s->vslen-1] != '\012');
|
||||
|
||||
|
Reference in New Issue
Block a user