Skip to contentSkip to conversation

Add parentheses to trace_do_casts macro

PATCH In review Michael Vrable 2 participants 2 messages Mar 17, 2007

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Add parentheses to trace_do_casts macro

# HG changeset patch
# User Michael Vrable <[email protected]> # Date 1174163889 25200
# Node ID e3b3abd0ee933833e4a20a048de35954675a4ad1 # Parent 98eacf1b075cc8bb2ed9136a0ca381840b8d7ae2 Add parentheses to trace_do_casts macro.

The arguments to this macro didn't have parentheses around them where they were used. If a call to a TRACE macro included an expression as an argument, the cast to (unsigned long) could bind to just part of the expression and lead to unexpected results.

xen/include/xen/trace.h +5 -5
diff -r 98eacf1b075c -r e3b3abd0ee93 xen/include/xen/trace.h
@@ -41,11 +41,11 @@ void trace(u32 event, unsigned long d1, 
     do {                                 \
         if ( unlikely(tb_init_done) )    \
             trace(e,                     \
-                 (unsigned long)d1,      \
-                 (unsigned long)d2,      \
-                 (unsigned long)d3,      \
-                 (unsigned long)d4,      \
-                 (unsigned long)d5);     \
+                  (unsigned long)(d1),   \
+                  (unsigned long)(d2),   \
+                  (unsigned long)(d3),   \
+                  (unsigned long)(d4),   \
+                  (unsigned long)(d5));  \
     } while ( 0 )
 
 /* Convenience macros for calling the trace function. */
#1 lore raw

ACK.

Nice catch - guess when I wrote that it hadn't occurred to me that people might be using expressions in trace macros, but it certainly should be a valid thing to do.

Cheers,
Mark

Quoted 39 lines · Michael Vrable

# HG changeset patch
# User Michael Vrable <[email protected]> # Date 1174163889 25200
# Node ID e3b3abd0ee933833e4a20a048de35954675a4ad1 # Parent 98eacf1b075cc8bb2ed9136a0ca381840b8d7ae2 Add parentheses to trace_do_casts macro.

The arguments to this macro didn't have parentheses around them where they were used. If a call to a TRACE macro included an expression as an argument, the cast to (unsigned long) could bind to just part of the expression and lead to unexpected results.

diff -r 98eacf1b075c -r e3b3abd0ee93 xen/include/xen/trace.h

xen/include/xen/trace.h +5 -5
@@ -41,11 +41,11 @@ void trace(u32 event, unsigned long d1,
     do {                                 \
         if ( unlikely(tb_init_done) )    \
             trace(e,                     \
-                 (unsigned long)d1,      \
-                 (unsigned long)d2,      \
-                 (unsigned long)d3,      \
-                 (unsigned long)d4,      \
-                 (unsigned long)d5);     \
+                  (unsigned long)(d1),   \
+                  (unsigned long)(d2),   \
+                  (unsigned long)(d3),   \
+                  (unsigned long)(d4),   \
+                  (unsigned long)(d5));  \
     } while ( 0 )
 
 /* Convenience macros for calling the trace function. */

_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xensource.com/xen-devel

Signature · 4 lines
Dave: Just a question. What use is a unicyle with no seat?  And no pedals!
Mark: To answer a question with a question: What use is a skateboard?
Dave: Skateboards have wheels.
Mark: My wheel has a wheel!