Hello, I was compiling screen and saw a warning for this line. The C
standard states that binary OR has a higher precedence than the ternary
operator. The patch doesn't seem to change behavior in any way since
FLOW_OFF and FLOW_ON are defined to 0 and 1 respectively. However, I
think it should probably be changed for clarity. The patch is attached.
From 5cffc5bea1d9f847c6180704bc72b5d45887b0a3 Mon Sep 17 00:00:00 2001
From: Collin Funk <collin.fu...@gmail.com>
Date: Tue, 6 Feb 2024 02:06:39 -0800
Subject: [PATCH] process: Fix operator precedence bug.

Binary or has a higher precedence than ternary conditionals. Wrap the
conditional expression in parentheses so it is evaluated first.
---
 src/process.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/process.c b/src/process.c
index c3dcdfc..7519cb0 100644
--- a/src/process.c
+++ b/src/process.c
@@ -1989,7 +1989,7 @@ static void DoCommandFlow(struct action *act)
 			fore->w_flow =
 			    (fore->w_flow & FLOW_AUTO) ? FLOW_AUTOFLAG | FLOW_AUTO | FLOW_ON : FLOW_AUTOFLAG;
 		} else 	if (ParseOnOff(act, &b) == 0)
-			fore->w_flow = (fore->w_flow & FLOW_AUTO) | b ? FLOW_ON : FLOW_OFF;
+			fore->w_flow = (fore->w_flow & FLOW_AUTO) | (b ? FLOW_ON : FLOW_OFF);
 	} else {
 		if (fore->w_flow & FLOW_AUTOFLAG)
 			fore->w_flow = (fore->w_flow & FLOW_AUTO) | FLOW_ON;
-- 
2.39.2

Reply via email to