[PATCH] tools thermal tmon: Fix signed shift UB in binding display

liujing posted 1 patch 3 weeks, 1 day ago
[PATCH] tools thermal tmon: Fix signed shift UB in binding display
Posted by liujing 3 weeks, 1 day ago
From: Liu Jing <liujing@cmss.chinamobile.com>

In the thermal zone binding display loop, the expression `(1 << j)`
performs a signed integer shift. When j reaches 31, this sets the
sign bit of a 32-bit signed integer, which is undefined behavior.

Fix it by using `(1U << j)` to perform an unsigned shift.

Signed-off-by: Liu Jing <liujing@cmss.chinamobile.com>
---
--- a/tools/thermal/tmon/tmon.c
+++ b/tools/thermal/tmon/tmon.c
@@ -171,7 +171,7 @@
 
 		memset(binding_str, 0, sizeof(binding_str));
 		for (j = 0; j < 32; j++)
-			binding_str[j] = (ptdata.tzi[i].cdev_binding & (1 << j)) ?
+			binding_str[j] = (ptdata.tzi[i].cdev_binding & (1U << j)) ?
 				'1' : '0';
 
 		fprintf(tmon_log, "#thermal zone %s%02d cdevs binding: %32s\n",