From 85eaaa86b74fe6582c7697ae7cde216ed484f9f2 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Wed, 6 Feb 2019 20:52:45 +0000 Subject: [PATCH] Avoid undefined left shift in ANSI macro. If term->esc_query == -1 (reflecting an escape sequence in which the CSI is followed by a prefix character other than ?) then the ANSI macro shouldn't shift it left by 8, because that's undefined behaviour (although in practice I'd be very surprised if any compiler has actually miscompiled it yet). Multiplying it by 256 is a safe alternative which has the behaviour I wanted. --- terminal.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terminal.h b/terminal.h index e39090bb..24c5ac0b 100644 --- a/terminal.h +++ b/terminal.h @@ -169,7 +169,7 @@ struct terminal_tag { unsigned esc_args[ARGS_MAX]; int esc_nargs; int esc_query; -#define ANSI(x,y) ((x)+((y)<<8)) +#define ANSI(x,y) ((x)+((y)*256)) #define ANSI_QUE(x) ANSI(x,1) #define OSC_STR_MAX 2048