diff --git a/logging.c b/logging.c index 3ffefcf6..8b87acbc 100644 --- a/logging.c +++ b/logging.c @@ -137,11 +137,9 @@ static void logfopen_callback(void *vctx, int mode) */ assert(ctx->state != L_OPENING); /* make _sure_ it won't be requeued */ while (bufchain_size(&ctx->queue)) { - void *data; - size_t len; - bufchain_prefix(&ctx->queue, &data, &len); - logwrite(ctx, data, len); - bufchain_consume(&ctx->queue, len); + ptrlen data = bufchain_prefix(&ctx->queue); + logwrite(ctx, data.ptr, data.len); + bufchain_consume(&ctx->queue, data.len); } logflush(ctx); } diff --git a/misc.h b/misc.h index 542c38eb..e07d58e4 100644 --- a/misc.h +++ b/misc.h @@ -105,7 +105,7 @@ void bufchain_init(bufchain *ch); void bufchain_clear(bufchain *ch); size_t bufchain_size(bufchain *ch); void bufchain_add(bufchain *ch, const void *data, size_t len); -void bufchain_prefix(bufchain *ch, void **data, size_t *len); +ptrlen bufchain_prefix(bufchain *ch); void bufchain_consume(bufchain *ch, size_t len); void bufchain_fetch(bufchain *ch, void *data, size_t len); void bufchain_fetch_consume(bufchain *ch, void *data, size_t len); diff --git a/noprint.c b/noprint.c index b3e9da5d..2a989082 100644 --- a/noprint.c +++ b/noprint.c @@ -16,7 +16,7 @@ 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, void *data, size_t len) { } diff --git a/proxy.c b/proxy.c index 9341c5f7..81c08e99 100644 --- a/proxy.c +++ b/proxy.c @@ -24,8 +24,7 @@ */ void proxy_activate (ProxySocket *p) { - void *data; - size_t len, output_before, output_after; + size_t output_before, output_after; p->state = PROXY_STATE_ACTIVE; @@ -42,16 +41,16 @@ void proxy_activate (ProxySocket *p) /* send buffered OOB writes */ while (bufchain_size(&p->pending_oob_output_data) > 0) { - bufchain_prefix(&p->pending_oob_output_data, &data, &len); - output_after += sk_write_oob(p->sub_socket, data, len); - bufchain_consume(&p->pending_oob_output_data, len); + ptrlen data = bufchain_prefix(&p->pending_oob_output_data); + output_after += sk_write_oob(p->sub_socket, data.ptr, data.len); + bufchain_consume(&p->pending_oob_output_data, data.len); } /* send buffered normal writes */ while (bufchain_size(&p->pending_output_data) > 0) { - bufchain_prefix(&p->pending_output_data, &data, &len); - output_after += sk_write(p->sub_socket, data, len); - bufchain_consume(&p->pending_output_data, len); + ptrlen data = bufchain_prefix(&p->pending_output_data); + output_after += sk_write(p->sub_socket, data.ptr, data.len); + bufchain_consume(&p->pending_output_data, data.len); } /* if we managed to send any data, let the higher levels know. */ @@ -159,15 +158,13 @@ static void sk_proxy_set_frozen (Socket *s, bool is_frozen) * so we have to check each time. */ while (!ps->freeze && bufchain_size(&ps->pending_input_data) > 0) { - void *data; char databuf[512]; - size_t len; - bufchain_prefix(&ps->pending_input_data, &data, &len); - if (len > lenof(databuf)) - len = lenof(databuf); - memcpy(databuf, data, len); - bufchain_consume(&ps->pending_input_data, len); - plug_receive(ps->plug, 0, databuf, len); + ptrlen data = bufchain_prefix(&ps->pending_input_data); + if (data.len > lenof(databuf)) + data.len = lenof(databuf); + memcpy(databuf, data.ptr, data.len); + bufchain_consume(&ps->pending_input_data, data.len); + plug_receive(ps->plug, 0, databuf, data.len); } /* if we're still frozen, we'll have to wait for another diff --git a/putty.h b/putty.h index 25f6e67e..0726d057 100644 --- a/putty.h +++ b/putty.h @@ -1841,7 +1841,7 @@ printer_enum *printer_start_enum(int *nprinters); char *printer_get_name(printer_enum *, int); void printer_finish_enum(printer_enum *); printer_job *printer_start_job(char *printer); -void printer_job_data(printer_job *, void *, int); +void printer_job_data(printer_job *, const void *, size_t); void printer_finish_job(printer_job *); /* diff --git a/rlogin.c b/rlogin.c index aac3fd11..48f1ccb6 100644 --- a/rlogin.c +++ b/rlogin.c @@ -287,10 +287,8 @@ static size_t rlogin_send(Backend *be, const char *buf, size_t len) if (!rlogin->prompt) { while (bufchain_size(&bc) > 0) { - void *data; - size_t len; - bufchain_prefix(&bc, &data, &len); - rlogin->bufsize = sk_write(rlogin->s, data, len); + ptrlen data = bufchain_prefix(&bc); + rlogin->bufsize = sk_write(rlogin->s, data.ptr, data.len); bufchain_consume(&bc, len); } } diff --git a/scpserver.c b/scpserver.c index c082e091..794d6143 100644 --- a/scpserver.c +++ b/scpserver.c @@ -1077,17 +1077,13 @@ static void scp_sink_coroutine(ScpSink *scp) if (scp->input_eof) goto done; - void *vdata; - size_t len; - const char *cdata, *newline; - - bufchain_prefix(&scp->data, &vdata, &len); - cdata = vdata; - newline = memchr(cdata, '\012', len); + ptrlen data = bufchain_prefix(&scp->data); + const char *cdata = data.ptr; + const char *newline = memchr(cdata, '\012', data.len); if (newline) - len = (int)(newline+1 - cdata); - put_data(scp->command, cdata, len); - bufchain_consume(&scp->data, len); + data.len = (int)(newline+1 - cdata); + put_data(scp->command, cdata, data.len); + bufchain_consume(&scp->data, data.len); if (newline) break; @@ -1179,8 +1175,7 @@ static void scp_sink_coroutine(ScpSink *scp) sshfwd_write(scp->sc, "\0", 1); scp->file_offset = 0; while (scp->file_offset < scp->file_size) { - void *vdata; - size_t len; + ptrlen data; uint64_t this_len, remaining; crMaybeWaitUntilV( @@ -1191,14 +1186,14 @@ static void scp_sink_coroutine(ScpSink *scp) goto done; } - bufchain_prefix(&scp->data, &vdata, &len); - this_len = len; + data = bufchain_prefix(&scp->data); + this_len = data.len; remaining = scp->file_size - scp->file_offset; if (this_len > remaining) this_len = remaining; sftpsrv_write(scp->sf, &scp->reply.srb, scp->reply.handle, scp->file_offset, - make_ptrlen(vdata, this_len)); + make_ptrlen(data.ptr, this_len)); if (scp->reply.err) { scp->errmsg = dupprintf( "'%.*s': unable to write to file: %s", diff --git a/ssh.c b/ssh.c index 8bf6cb77..24e870b6 100644 --- a/ssh.c +++ b/ssh.c @@ -348,17 +348,16 @@ static void ssh_bpp_output_raw_data_callback(void *vctx) return; while (bufchain_size(&ssh->out_raw) > 0) { - void *data; - size_t len, backlog; + size_t backlog; - bufchain_prefix(&ssh->out_raw, &data, &len); + ptrlen data = bufchain_prefix(&ssh->out_raw); if (ssh->logctx) - log_packet(ssh->logctx, PKT_OUTGOING, -1, NULL, data, len, + log_packet(ssh->logctx, PKT_OUTGOING, -1, NULL, data.ptr, data.len, 0, NULL, NULL, 0, NULL); - backlog = sk_write(ssh->s, data, len); + backlog = sk_write(ssh->s, data.ptr, data.len); - bufchain_consume(&ssh->out_raw, len); + bufchain_consume(&ssh->out_raw, data.len); if (backlog > SSH_MAX_BACKLOG) { ssh_throttle_all(ssh, true, backlog); diff --git a/ssh1connection.c b/ssh1connection.c index 78cd1425..8b0c3aa9 100644 --- a/ssh1connection.c +++ b/ssh1connection.c @@ -780,13 +780,11 @@ static void ssh1_connection_got_user_input(PacketProtocolLayer *ppl) /* * Add user input to the main channel's buffer. */ - void *data; - size_t len; - bufchain_prefix(s->ppl.user_input, &data, &len); - if (len > 512) - len = 512; - sshfwd_write(&s->mainchan_sc, data, len); - bufchain_consume(s->ppl.user_input, len); + ptrlen data = bufchain_prefix(s->ppl.user_input); + if (data.len > 512) + data.len = 512; + sshfwd_write(&s->mainchan_sc, data.ptr, data.len); + bufchain_consume(s->ppl.user_input, data.len); } } diff --git a/ssh2connection.c b/ssh2connection.c index da573ee3..a2868f84 100644 --- a/ssh2connection.c +++ b/ssh2connection.c @@ -1064,16 +1064,14 @@ static size_t ssh2_try_send(struct ssh2_channel *c) while (c->remwindow > 0 && (bufchain_size(&c->outbuffer) > 0 || bufchain_size(&c->errbuffer) > 0)) { - size_t len; - void *data; bufchain *buf = (bufchain_size(&c->errbuffer) > 0 ? &c->errbuffer : &c->outbuffer); - bufchain_prefix(buf, &data, &len); - if (len > c->remwindow) - len = c->remwindow; - if (len > c->remmaxpkt) - len = c->remmaxpkt; + ptrlen data = bufchain_prefix(buf); + if (data.len > c->remwindow) + data.len = c->remwindow; + if (data.len > c->remmaxpkt) + data.len = c->remmaxpkt; if (buf == &c->errbuffer) { pktout = ssh_bpp_new_pktout( s->ppl.bpp, SSH2_MSG_CHANNEL_EXTENDED_DATA); @@ -1083,10 +1081,10 @@ static size_t ssh2_try_send(struct ssh2_channel *c) pktout = ssh_bpp_new_pktout(s->ppl.bpp, SSH2_MSG_CHANNEL_DATA); put_uint32(pktout, c->remoteid); } - put_string(pktout, data, len); + put_stringpl(pktout, data); pq_push(s->ppl.out_pq, pktout); - bufchain_consume(buf, len); - c->remwindow -= len; + bufchain_consume(buf, data.len); + c->remwindow -= data.len; } /* @@ -1670,11 +1668,9 @@ static void ssh2_connection_got_user_input(PacketProtocolLayer *ppl) /* * Add user input to the main channel's buffer. */ - void *data; - size_t len; - bufchain_prefix(s->ppl.user_input, &data, &len); - sshfwd_write(s->mainchan_sc, data, len); - bufchain_consume(s->ppl.user_input, len); + ptrlen data = bufchain_prefix(s->ppl.user_input); + sshfwd_write(s->mainchan_sc, data.ptr, data.len); + bufchain_consume(s->ppl.user_input, data.len); } } diff --git a/ssh2userauth.c b/ssh2userauth.c index 7acdaa0c..3c8c7a19 100644 --- a/ssh2userauth.c +++ b/ssh2userauth.c @@ -465,11 +465,9 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl) if (bufchain_size(&s->banner) && (flags & (FLAG_VERBOSE | FLAG_INTERACTIVE))) { while (bufchain_size(&s->banner) > 0) { - void *data; - size_t len; - bufchain_prefix(&s->banner, &data, &len); - seat_stderr(s->ppl.seat, data, len); - bufchain_consume(&s->banner, len); + ptrlen data = bufchain_prefix(&s->banner); + seat_stderr(s->ppl.seat, data.ptr, data.len); + bufchain_consume(&s->banner, data.len); } } bufchain_clear(&s->banner); diff --git a/sshserver.c b/sshserver.c index 334ef1e2..c07779ff 100644 --- a/sshserver.c +++ b/sshserver.c @@ -333,17 +333,16 @@ static void server_bpp_output_raw_data_callback(void *vctx) return; while (bufchain_size(&srv->out_raw) > 0) { - void *data; - size_t len, backlog; + size_t backlog; - bufchain_prefix(&srv->out_raw, &data, &len); + ptrlen data = bufchain_prefix(&srv->out_raw); if (srv->logctx) - log_packet(srv->logctx, PKT_OUTGOING, -1, NULL, data, len, + log_packet(srv->logctx, PKT_OUTGOING, -1, NULL, data.ptr, data.len, 0, NULL, NULL, 0, NULL); - backlog = sk_write(srv->socket, data, len); + backlog = sk_write(srv->socket, data.ptr, data.len); - bufchain_consume(&srv->out_raw, len); + bufchain_consume(&srv->out_raw, data.len); if (backlog > SSH_MAX_BACKLOG) { #ifdef FIXME diff --git a/sshverstring.c b/sshverstring.c index dff350ac..55e0fdc1 100644 --- a/sshverstring.c +++ b/sshverstring.c @@ -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'); diff --git a/terminal.c b/terminal.c index 7f5fe7f1..ac8f5ef4 100644 --- a/terminal.c +++ b/terminal.c @@ -2691,20 +2691,18 @@ static void term_print_setup(Terminal *term, char *printer) } static void term_print_flush(Terminal *term) { - void *data; - size_t len, size; + size_t size; while ((size = bufchain_size(&term->printer_buf)) > 5) { - bufchain_prefix(&term->printer_buf, &data, &len); - if (len > size-5) - len = size-5; - printer_job_data(term->print_job, data, len); - bufchain_consume(&term->printer_buf, len); + ptrlen data = bufchain_prefix(&term->printer_buf); + if (data.len > size-5) + data.len = size-5; + printer_job_data(term->print_job, data.ptr, data.len); + bufchain_consume(&term->printer_buf, data.len); } } static void term_print_finish(Terminal *term) { - void *data; - size_t len, size; + size_t size; char c; if (!term->printing && !term->only_printing) @@ -2712,8 +2710,8 @@ static void term_print_finish(Terminal *term) term_print_flush(term); while ((size = bufchain_size(&term->printer_buf)) > 0) { - bufchain_prefix(&term->printer_buf, &data, &len); - c = *(char *)data; + ptrlen data = bufchain_prefix(&term->printer_buf); + c = *(char *)data.ptr; if (c == '\033' || c == '\233') { bufchain_consume(&term->printer_buf, size); break; @@ -2882,14 +2880,15 @@ static void term_out(Terminal *term) while (nchars > 0 || unget != -1 || bufchain_size(&term->inbuf) > 0) { if (unget == -1) { if (nchars == 0) { - void *ret; - bufchain_prefix(&term->inbuf, &ret, &nchars); - if (nchars > sizeof(localbuf)) - nchars = sizeof(localbuf); - memcpy(localbuf, ret, nchars); - bufchain_consume(&term->inbuf, nchars); + ptrlen data = bufchain_prefix(&term->inbuf); + if (data.len > sizeof(localbuf)) + data.len = sizeof(localbuf); + memcpy(localbuf, data.ptr, data.len); + bufchain_consume(&term->inbuf, data.len); + nchars = data.len; chars = localbuf; assert(chars != NULL); + assert(nchars > 0); } c = *chars++; nchars--; diff --git a/unix/uxcons.c b/unix/uxcons.c index 05ae8bf3..6bb36e54 100644 --- a/unix/uxcons.c +++ b/unix/uxcons.c @@ -493,14 +493,13 @@ static void console_close(FILE *outfp, int infd) static void console_prompt_text(FILE *outfp, const char *data, size_t len) { bufchain sanitised; - void *vdata; bufchain_init(&sanitised); sanitise_term_data(&sanitised, data, len); while (bufchain_size(&sanitised) > 0) { - bufchain_prefix(&sanitised, &vdata, &len); - fwrite(vdata, 1, len, outfp); - bufchain_consume(&sanitised, len); + ptrlen sdata = bufchain_prefix(&sanitised); + fwrite(sdata.ptr, 1, sdata.len, outfp); + bufchain_consume(&sanitised, sdata.len); } fflush(outfp); } diff --git a/unix/uxfdsock.c b/unix/uxfdsock.c index 099c9c00..9ac3cdf8 100644 --- a/unix/uxfdsock.c +++ b/unix/uxfdsock.c @@ -162,12 +162,10 @@ static int fdsocket_try_send(FdSocket *fds) int sent = 0; while (bufchain_size(&fds->pending_output_data) > 0) { - void *data; - size_t len; ssize_t ret; - bufchain_prefix(&fds->pending_output_data, &data, &len); - ret = write(fds->outfd, data, len); + ptrlen data = bufchain_prefix(&fds->pending_output_data); + ret = write(fds->outfd, data.ptr, data.len); noise_ultralight(NOISE_SOURCE_IOID, ret); if (ret < 0 && errno != EWOULDBLOCK) { if (!fds->pending_error) { diff --git a/unix/uxnet.c b/unix/uxnet.c index 68e21a7d..0074c4b8 100644 --- a/unix/uxnet.c +++ b/unix/uxnet.c @@ -1111,7 +1111,7 @@ void try_send(NetSocket *s) while (s->sending_oob || bufchain_size(&s->output_data) > 0) { int nsent; int err; - void *data; + const void *data; size_t len; int urgentflag; @@ -1121,7 +1121,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; } nsent = send(s->s, data, len, urgentflag); noise_ultralight(NOISE_SOURCE_IOLEN, nsent); diff --git a/unix/uxplink.c b/unix/uxplink.c index 1dbf17c2..39cb4291 100644 --- a/unix/uxplink.c +++ b/unix/uxplink.c @@ -329,18 +329,17 @@ size_t try_output(bool is_stderr) { bufchain *chain = (is_stderr ? &stderr_data : &stdout_data); int fd = (is_stderr ? STDERR_FILENO : STDOUT_FILENO); - void *senddata; - size_t sendlen; ssize_t ret; if (bufchain_size(chain) > 0) { bool prev_nonblock = nonblock(fd); + ptrlen senddata; do { - bufchain_prefix(chain, &senddata, &sendlen); - ret = write(fd, senddata, sendlen); + senddata = bufchain_prefix(chain); + ret = write(fd, senddata.ptr, senddata.len); if (ret > 0) bufchain_consume(chain, ret); - } while (ret == sendlen && bufchain_size(chain) != 0); + } while (ret == senddata.len && bufchain_size(chain) != 0); if (!prev_nonblock) no_nonblock(fd); if (ret < 0 && errno != EAGAIN) { diff --git a/unix/uxprint.c b/unix/uxprint.c index 37241007..2a111e65 100644 --- a/unix/uxprint.c +++ b/unix/uxprint.c @@ -25,7 +25,7 @@ printer_job *printer_start_job(char *printer) return ret; } -void printer_job_data(printer_job *pj, void *data, int len) +void printer_job_data(printer_job *pj, const void *data, size_t len) { if (!pj) return; diff --git a/unix/uxpty.c b/unix/uxpty.c index c632ecc6..b57b6776 100644 --- a/unix/uxpty.c +++ b/unix/uxpty.c @@ -1309,15 +1309,13 @@ static void pty_free(Backend *be) static void pty_try_write(Pty *pty) { - void *data; - size_t len; ssize_t ret; assert(pty->master_i >= 0); while (bufchain_size(&pty->output_data) > 0) { - bufchain_prefix(&pty->output_data, &data, &len); - ret = write(pty->master_i, data, len); + ptrlen data = bufchain_prefix(&pty->output_data); + ret = write(pty->master_i, data.ptr, data.len); if (ret < 0 && (errno == EWOULDBLOCK)) { /* diff --git a/unix/uxser.c b/unix/uxser.c index a2055d81..815d82e7 100644 --- a/unix/uxser.c +++ b/unix/uxser.c @@ -422,15 +422,13 @@ static void serial_uxsel_setup(Serial *serial) static void serial_try_write(Serial *serial) { - void *data; - size_t len; ssize_t ret; assert(serial->fd >= 0); while (bufchain_size(&serial->output_data) > 0) { - bufchain_prefix(&serial->output_data, &data, &len); - ret = write(serial->fd, data, len); + ptrlen data = bufchain_prefix(&serial->output_data); + ret = write(serial->fd, data.ptr, data.len); if (ret < 0 && (errno == EWOULDBLOCK)) { /* diff --git a/utils.c b/utils.c index dc5af50a..3f02bd66 100644 --- a/utils.c +++ b/utils.c @@ -714,10 +714,9 @@ void bufchain_consume(bufchain *ch, size_t len) } } -void bufchain_prefix(bufchain *ch, void **data, size_t *len) +ptrlen bufchain_prefix(bufchain *ch) { - *len = ch->head->bufend - ch->head->bufpos; - *data = ch->head->bufpos; + return make_ptrlen(ch->head->bufpos, ch->head->bufend - ch->head->bufpos); } void bufchain_fetch(bufchain *ch, void *data, size_t len) diff --git a/windows/wincons.c b/windows/wincons.c index 997ebb5a..c7d70a61 100644 --- a/windows/wincons.c +++ b/windows/wincons.c @@ -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); } } diff --git a/windows/winhandl.c b/windows/winhandl.c index e291e2cb..d3c95f88 100644 --- a/windows/winhandl.c +++ b/windows/winhandl.c @@ -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 && diff --git a/windows/winhsock.c b/windows/winhsock.c index 541a37b4..4bebba75 100644 --- a/windows/winhsock.c +++ b/windows/winhsock.c @@ -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); diff --git a/windows/winnet.c b/windows/winnet.c index c7187a03..ba3e11bd 100644 --- a/windows/winnet.c +++ b/windows/winnet.c @@ -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); diff --git a/windows/winprint.c b/windows/winprint.c index b8b24512..36699f05 100644 --- a/windows/winprint.c +++ b/windows/winprint.c @@ -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)