From 068b67d2f6e9b186b3107ebcb1e88a141b7b5ebc Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sat, 22 Nov 2014 10:37:14 +0000 Subject: [PATCH] Clarify when ldisc->term may be NULL. Namely, any ldisc that you send actual data through should have a terminal attached, because the ldisc editing/echoing system is designed entirely for use with a terminal. The only time you can have an ldisc with no terminal is when it's only ever used by the backend to report changes to the front end in edit/echo status, e.g. by Unix Plink. Coverity spotted an oddity in ldisc_send which after a while I decided would never have actually caused a problem, but OTOH I agree that it was confusing, so now hopefully it's less so. --- ldisc.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/ldisc.c b/ldisc.c index 8f653a18..31185406 100644 --- a/ldisc.c +++ b/ldisc.c @@ -7,6 +7,7 @@ #include #include +#include #include "putty.h" #include "terminal.h" @@ -139,6 +140,17 @@ void ldisc_send(void *handle, char *buf, int len, int interactive) ldisc_update(ldisc->frontend, ECHOING, EDITING); return; } + + /* + * If that wasn't true, then we expect ldisc->term to be non-NULL + * hereafter. (The only front ends which have an ldisc but no term + * are those which do networking but no terminal emulation, in + * which case they need the above if statement to handle + * ldisc_updates passed from the back ends, but should never send + * any actual input through this function.) + */ + assert(ldisc->term); + /* * Notify the front end that something was pressed, in case * it's depending on finding out (e.g. keypress termination for @@ -146,7 +158,7 @@ void ldisc_send(void *handle, char *buf, int len, int interactive) */ frontend_keypress(ldisc->frontend); - if (interactive && ldisc->term) { + if (interactive) { /* * Interrupt a paste from the clipboard, if one was in * progress when the user pressed a key. This is easier than