1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-01 11:32: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:
Simon Tatham
2019-02-06 20:46:45 +00:00
parent 0cda34c6f8
commit 59f7b24b9d
27 changed files with 128 additions and 163 deletions

View File

@ -392,14 +392,13 @@ static void console_data_untrusted(HANDLE hout, const char *data, size_t len)
{
DWORD dummy;
bufchain sanitised;
void *vdata;
bufchain_init(&sanitised);
sanitise_term_data(&sanitised, data, len);
while (bufchain_size(&sanitised) > 0) {
bufchain_prefix(&sanitised, &vdata, &len);
WriteFile(hout, vdata, len, &dummy, NULL);
bufchain_consume(&sanitised, len);
ptrlen sdata = bufchain_prefix(&sanitised);
WriteFile(hout, sdata.ptr, sdata.len, &dummy, NULL);
bufchain_consume(&sanitised, sdata.len);
}
}

View File

@ -257,7 +257,7 @@ struct handle_output {
* Data set by the main thread before signalling ev_from_main,
* and read by the input thread after receiving that signal.
*/
char *buffer; /* the data to write */
const char *buffer; /* the data to write */
DWORD len; /* how much data there is */
/*
@ -347,13 +347,10 @@ static DWORD WINAPI handle_output_threadfunc(void *param)
static void handle_try_output(struct handle_output *ctx)
{
void *senddata;
size_t sendlen;
if (!ctx->busy && bufchain_size(&ctx->queued_data)) {
bufchain_prefix(&ctx->queued_data, &senddata, &sendlen);
ctx->buffer = senddata;
ctx->len = min(sendlen, ~(DWORD)0);
ptrlen data = bufchain_prefix(&ctx->queued_data);
ctx->buffer = data.ptr;
ctx->len = min(data.len, ~(DWORD)0);
SetEvent(ctx->ev_from_main);
ctx->busy = true;
} else if (!ctx->busy && bufchain_size(&ctx->queued_data) == 0 &&

View File

@ -164,8 +164,6 @@ static void sk_handle_flush(Socket *s)
static void handle_socket_unfreeze(void *hsv)
{
HandleSocket *hs = (HandleSocket *)hsv;
void *data;
size_t len;
/*
* If we've been put into a state other than THAWING since the
@ -177,16 +175,16 @@ static void handle_socket_unfreeze(void *hsv)
/*
* Get some of the data we've buffered.
*/
bufchain_prefix(&hs->inputdata, &data, &len);
assert(len > 0);
ptrlen data = bufchain_prefix(&hs->inputdata);
assert(data.len > 0);
/*
* Hand it off to the plug. Be careful of re-entrance - that might
* have the effect of trying to close this socket.
*/
hs->defer_close = true;
plug_receive(hs->plug, 0, data, len);
bufchain_consume(&hs->inputdata, len);
plug_receive(hs->plug, 0, data.ptr, data.len);
bufchain_consume(&hs->inputdata, data.len);
hs->defer_close = false;
if (hs->deferred_close) {
sk_handle_close(&hs->sock);

View File

@ -1377,7 +1377,7 @@ void try_send(NetSocket *s)
while (s->sending_oob || bufchain_size(&s->output_data) > 0) {
int nsent;
DWORD err;
void *data;
const void *data;
size_t len;
int urgentflag;
@ -1387,7 +1387,9 @@ void try_send(NetSocket *s)
data = &s->oobdata;
} else {
urgentflag = 0;
bufchain_prefix(&s->output_data, &data, &len);
ptrlen bufdata = bufchain_prefix(&s->output_data);
data = bufdata.ptr;
len = bufdata.len;
}
len = min(len, INT_MAX); /* WinSock send() takes an int */
nsent = p_send(s->s, data, len, urgentflag);

View File

@ -202,14 +202,14 @@ printer_job *printer_start_job(char *printer)
return NULL;
}
void printer_job_data(printer_job *pj, void *data, int len)
void printer_job_data(printer_job *pj, const void *data, size_t len)
{
DWORD written;
if (!pj)
return;
p_WritePrinter(pj->hprinter, data, len, &written);
p_WritePrinter(pj->hprinter, (void *)data, len, &written);
}
void printer_finish_job(printer_job *pj)