From 375b28720f7c78e6fac1c274f9dee7c40a78aacb Mon Sep 17 00:00:00 2001
From: "Roberto E. Vargas Caballero" <k0ga@shike2.com>
Date: Sat, 21 Nov 2015 18:21:03 +0100
Subject: [PATCH] Avoid recursive call to ttywrite from ttyread

Ttyread() calls to ttywrite, so if we check for reading before
that for writing in ttywrite we can get a circular call sequence.
---
 st.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/st.c b/st.c
index a47f094..c5d62c1 100644
--- a/st.c
+++ b/st.c
@@ -1518,8 +1518,6 @@ ttywrite(const char *s, size_t n)
 				continue;
 			die("select failed: %s\n", strerror(errno));
 		}
-		if (FD_ISSET(cmdfd, &rfd))
-			lim = ttyread();
 		if (FD_ISSET(cmdfd, &wfd)) {
 			/*
 			 * Only write the bytes written by ttywrite() or the
@@ -1543,6 +1541,8 @@ ttywrite(const char *s, size_t n)
 				break;
 			}
 		}
+		if (FD_ISSET(cmdfd, &rfd))
+			lim = ttyread();
 	}
 	return;