public inbox for igt-dev@lists.freedesktop.org
 help / color / mirror / Atom feed
* [PATCH i-g-t] lib/igt_aux: Protect expressions from premature casting in aux macros
@ 2026-02-04 13:55 Zbigniew Kempczyński
  2026-02-04 14:31 ` Kamil Konieczny
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Zbigniew Kempczyński @ 2026-02-04 13:55 UTC (permalink / raw)
  To: igt-dev; +Cc: Zbigniew Kempczyński, Matthew Auld, Kamil Konieczny

Missing brackets around expressions might cause undesired behavior
during type casting, for example:

objs = 4096;
objs = min_t(int, objs, vram_size() / SZ_4K)

If vram_size() is 0x80000000 casting to int gives negative number,
so min_t also will be negative even if it wasn't our intention.

Add round brackets to ensure casting refers to whole expression.

Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski@intel.com>
Cc: Matthew Auld <matthew.auld@intel.com>
Cc: Kamil Konieczny <kamil.konieczny@linux.intel.com>
---
 lib/igt_aux.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/igt_aux.h b/lib/igt_aux.h
index 8ff182384c..56761a3b3e 100644
--- a/lib/igt_aux.h
+++ b/lib/igt_aux.h
@@ -255,8 +255,8 @@ void igt_debug_interactive_mode_check(const char *var, const char *expected);
 
 #define clamp(val, lo, hi) min(max(val, lo), hi)
 
-#define min_t(t, x, y)	__careful_cmp((typeof(t))x, (typeof(t))y, <, min_t)
-#define max_t(t, x, y)	__careful_cmp((typeof(t))x, (typeof(t))y, >, max_t)
+#define min_t(t, x, y)	__careful_cmp((typeof(t))(x), (typeof(t))(y), <, min_t)
+#define max_t(t, x, y)	__careful_cmp((typeof(t))(x), (typeof(t))(y), >, max_t)
 
 #define igt_swap(a, b) do {	\
 	typeof(a) _tmp = (a);	\
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2026-02-05 11:53 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-04 13:55 [PATCH i-g-t] lib/igt_aux: Protect expressions from premature casting in aux macros Zbigniew Kempczyński
2026-02-04 14:31 ` Kamil Konieczny
2026-02-04 14:39 ` Matthew Auld
2026-02-04 14:45 ` ✓ Xe.CI.BAT: success for " Patchwork
2026-02-04 15:09 ` ✓ i915.CI.BAT: " Patchwork
2026-02-04 23:55 ` ✗ Xe.CI.FULL: failure " Patchwork
2026-02-05 11:52   ` Zbigniew Kempczyński
2026-02-05  2:50 ` ✗ i915.CI.Full: " Patchwork
2026-02-05 11:53   ` Zbigniew Kempczyński

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox