From 90d8df8128e5aaa32c53370188d4ce4ef07407cc Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 1 Jul 2020 22:33:31 -0700 Subject: [PATCH] Use _POSIX_VDISABLE instead of \0 to disable control functions Prior to this commit, fish used NUL ('\0') to disable control functions (for example, the function that generates SIGTSTP). However NUL may in fact be bindable and is on macOS via control-space. Use instead _POSIX_VDISABLE if defined and not -1. --- src/reader.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/reader.cpp b/src/reader.cpp index 043408499..6ec992276 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -656,12 +656,20 @@ static void term_fix_modes(struct termios *modes) { modes->c_cc[VMIN] = 1; modes->c_cc[VTIME] = 0; + unsigned char disabling_char = '\0'; + // Prefer to use _POSIX_VDISABLE to disable control functions. + // This permits separately binding nul (typically control-space). + // POSIX calls out -1 as a special value which should be ignored. +#ifdef _POSIX_VDISABLE + if (_POSIX_VDISABLE != -1) disabling_char = _POSIX_VDISABLE; +#endif + // We ignore these anyway, so there is no need to sacrifice a character. - modes->c_cc[VSUSP] = '\0'; + modes->c_cc[VSUSP] = disabling_char; // (these two are already disabled because of IXON/IXOFF) - modes->c_cc[VSTOP] = '\0'; - modes->c_cc[VSTART] = '\0'; + modes->c_cc[VSTOP] = disabling_char; + modes->c_cc[VSTART] = disabling_char; } /// Tracks a currently pending exit. This may be manipulated from a signal handler.