]> xenbits.xensource.com Git - people/royger/xen.git/commitdiff
radix-tree: don't left-shift negative values
authorJan Beulich <jbeulich@suse.com>
Tue, 25 Feb 2025 07:45:14 +0000 (08:45 +0100)
committerJan Beulich <jbeulich@suse.com>
Tue, 25 Feb 2025 07:45:14 +0000 (08:45 +0100)
Any (signed) integer is okay to pass into radix_tree_int_to_ptr(), yet
left shifting negative values is UB. Use an unsigned intermediate type,
reducing the impact to implementation defined behavior (for the
unsigned->signed conversion).

Also please Misra C:2012 rule 7.3 by dropping the lower case numeric 'l'
tag.

No difference in generated code, at least on x86.

Fixes: b004883e29bb ("Simplify and build-fix (for some gcc versions) radix_tree_int_to_ptr()")
Reported-by: Teddy Astie <teddy.astie@vates.tech>
Signed-off-by: Jan Beulich <jbeulich@suse.com>
Reviewed-by: Andrew Cooper <andrew.cooper3@citrix.com>
xen/include/xen/radix-tree.h

index 40773659727b3b2526bab920ed5d00bc1b415dc6..634737eaf56dddf2de510d480616ddc3c1c05784 100644 (file)
@@ -172,7 +172,7 @@ static inline void radix_tree_replace_slot(void **pslot, void *item)
  */
 static inline void *radix_tree_int_to_ptr(int val)
 {
-    long _ptr = ((long)val << 2) | 0x2l;
+    long _ptr = ((unsigned long)val << 2) | 2;
     ASSERT((_ptr >> 2) == val);
     return (void *)_ptr;
 }