From 5eb6c19047bb45f2e54b3387e65bfeb43c1b7836 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Thu, 7 Mar 2019 10:17:08 +0000 Subject: [PATCH] Extra inline helpers seat_{stdout,stderr}_pl. These take a ptrlen in place of separate buffer and length arguments. Switched over to them in lots of places. --- putty.h | 4 ++++ ssh.c | 2 +- ssh2userauth.c | 2 +- sshcommon.c | 2 +- unix/gtkwin.c | 4 ++-- unix/uxpty.c | 2 +- windows/windlg.c | 4 ++-- 7 files changed, 12 insertions(+), 8 deletions(-) diff --git a/putty.h b/putty.h index 9a67b932..a721a498 100644 --- a/putty.h +++ b/putty.h @@ -991,8 +991,12 @@ void seat_connection_fatal(Seat *seat, const char *fmt, ...); /* Handy aliases for seat_output which set is_stderr to a fixed value. */ static inline size_t seat_stdout(Seat *seat, const void *data, size_t len) { return seat_output(seat, false, data, len); } +static inline size_t seat_stdout_pl(Seat *seat, ptrlen data) +{ return seat_output(seat, false, data.ptr, data.len); } static inline size_t seat_stderr(Seat *seat, const void *data, size_t len) { return seat_output(seat, true, data, len); } +static inline size_t seat_stderr_pl(Seat *seat, ptrlen data) +{ return seat_output(seat, true, data.ptr, data.len); } /* * Stub methods for seat implementations that want to use the obvious diff --git a/ssh.c b/ssh.c index 849ddb7f..e35ebc64 100644 --- a/ssh.c +++ b/ssh.c @@ -715,7 +715,7 @@ static const char *connect_to_host( * behave in quite the usual way. */ const char *msg = "Reusing a shared connection to this server.\r\n"; - seat_stderr(ssh->seat, msg, strlen(msg)); + seat_stderr_pl(ssh->seat, ptrlen_from_asciz(msg)); } } else { /* diff --git a/ssh2userauth.c b/ssh2userauth.c index a8a0426c..dd16009d 100644 --- a/ssh2userauth.c +++ b/ssh2userauth.c @@ -479,7 +479,7 @@ static void ssh2_userauth_process_queue(PacketProtocolLayer *ppl) (flags & (FLAG_VERBOSE | FLAG_INTERACTIVE))) { while (bufchain_size(&s->banner) > 0) { ptrlen data = bufchain_prefix(&s->banner); - seat_stderr(s->ppl.seat, data.ptr, data.len); + seat_stderr_pl(s->ppl.seat, data); bufchain_consume(&s->banner, data.len); } } diff --git a/sshcommon.c b/sshcommon.c index cd5b839c..39f2a65e 100644 --- a/sshcommon.c +++ b/sshcommon.c @@ -804,7 +804,7 @@ void ssh_ppl_user_output_string_and_free(PacketProtocolLayer *ppl, char *text) /* Messages sent via this function are from the SSH layer, not * from the server-side process, so they always have the stderr * flag set. */ - seat_stderr(ppl->seat, text, strlen(text)); + seat_stderr_pl(ppl->seat, ptrlen_from_asciz(text)); sfree(text); } diff --git a/unix/gtkwin.c b/unix/gtkwin.c index 6532b9ff..2728436e 100644 --- a/unix/gtkwin.c +++ b/unix/gtkwin.c @@ -409,8 +409,8 @@ static void gtk_logging_error(LogPolicy *lp, const char *event) /* Send 'can't open log file' errors to the terminal window. * (Marked as stderr, although terminal.c won't care.) */ - seat_stderr(&inst->seat, event, strlen(event)); - seat_stderr(&inst->seat, "\r\n", 2); + seat_stderr_pl(&inst->seat, ptrlen_from_asciz(event)); + seat_stderr_pl(&inst->seat, PTRLEN_LITERAL("\r\n")); } static const LogPolicyVtable gtk_logpolicy_vt = { diff --git a/unix/uxpty.c b/unix/uxpty.c index 3a95b2a6..5d73fe9c 100644 --- a/unix/uxpty.c +++ b/unix/uxpty.c @@ -729,7 +729,7 @@ static void pty_real_select_result(Pty *pty, int fd, int event, int status) * is better than no message at all */ message = dupprintf("\r\n[pterm: process terminated]\r\n"); } - seat_stdout(pty->seat, message, strlen(message)); + seat_stdout_pl(pty->seat, ptrlen_from_asciz(message)); sfree(message); } diff --git a/windows/windlg.c b/windows/windlg.c index e046a83e..c760c91a 100644 --- a/windows/windlg.c +++ b/windows/windlg.c @@ -799,8 +799,8 @@ static void win_gui_logging_error(LogPolicy *lp, const char *event) { /* Send 'can't open log file' errors to the terminal window. * (Marked as stderr, although terminal.c won't care.) */ - seat_stderr(win_seat, event, strlen(event)); - seat_stderr(win_seat, "\r\n", 2); + seat_stderr_pl(win_seat, ptrlen_from_asciz(event)); + seat_stderr_pl(win_seat, PTRLEN_LITERAL("\r\n")); } void showeventlog(HWND hwnd)