[PPL-devel] [GIT] ppl/ppl(master): Avoid excessive and dangerous reliance on the C++ operator precedence rules .

Roberto Bagnara bagnara at cs.unipr.it
Tue Oct 18 19:52:55 CEST 2011


Module: ppl/ppl
Branch: master
Commit: 703cc3ccfae900375897b441b2abfe0ad6e0f210
URL:    http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=703cc3ccfae900375897b441b2abfe0ad6e0f210

Author: Roberto Bagnara <bagnara at cs.unipr.it>
Date:   Tue Oct 18 19:51:59 2011 +0200

Avoid excessive and dangerous reliance on the C++ operator precedence rules.
Detected by ECLAIR service exprprns.

---

 src/Linear_Expression.cc   |    2 +-
 src/checked_int.inlines.hh |   15 ++++++++-------
 src/globals.inlines.hh     |    2 +-
 3 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/src/Linear_Expression.cc b/src/Linear_Expression.cc
index f586ac4..86872a2 100644
--- a/src/Linear_Expression.cc
+++ b/src/Linear_Expression.cc
@@ -81,7 +81,7 @@ PPL::Linear_Expression::Linear_Expression(const Congruence& cg)
 
 PPL::Linear_Expression::Linear_Expression(const Variable v)
   : Linear_Row((v.space_dimension() <= max_space_dimension())
-	       ? v.space_dimension() + 1
+	       ? (v.space_dimension() + 1)
 	       : (throw std::length_error("PPL::Linear_Expression::"
 					  "Linear_Expression(v):\n"
 					  "v exceeds the maximum allowed "
diff --git a/src/checked_int.inlines.hh b/src/checked_int.inlines.hh
index 68d811f..00a4b98 100644
--- a/src/checked_int.inlines.hh
+++ b/src/checked_int.inlines.hh
@@ -72,18 +72,19 @@ template <typename Policy, typename Type>
 struct Extended_Int {
   static const Type plus_infinity = C_Integer<Type>::max;
   static const Type minus_infinity = ((C_Integer<Type>::min >= 0)
-				      ? C_Integer<Type>::max - 1
+				      ? (C_Integer<Type>::max - 1)
 				      : C_Integer<Type>::min);
   static const Type not_a_number
   = ((C_Integer<Type>::min >= 0)
-     ? C_Integer<Type>::max - Policy::has_infinity * 2
-     : C_Integer<Type>::min + Policy::has_infinity);
+     ? (C_Integer<Type>::max - Policy::has_infinity * 2)
+     : (C_Integer<Type>::min + Policy::has_infinity));
   static const Type min = (C_Integer<Type>::min
-			   + (C_Integer<Type>::min >= 0 ? 0
+			   + ((C_Integer<Type>::min >= 0)
+                              ? 0
 			      : (Policy::has_infinity + Policy::has_nan)));
   static const Type max = (C_Integer<Type>::max
 			   - ((C_Integer<Type>::min >= 0)
-			      ? (2 * Policy::has_infinity + Policy::has_nan)
+			      ? (2*Policy::has_infinity + Policy::has_nan)
 			      : Policy::has_infinity));
 };
 
@@ -640,7 +641,7 @@ assign_signed_int_mpz(To& to, const mpz_class& from, Rounding_Dir dir) {
       }
     }
   }
-  return ::sgn(from) < 0
+  return (::sgn(from) < 0)
     ? set_neg_overflow_int<To_Policy>(to, dir)
     : set_pos_overflow_int<To_Policy>(to, dir);
 }
@@ -1369,7 +1370,7 @@ smod_2exp_unsigned_int(Type& to, const Type x, unsigned int exp,
   if (exp > sizeof(Type)*CHAR_BIT)
     to = x;
   else {
-    Type v = exp == sizeof(Type)*CHAR_BIT ? x : (x & ((Type(1) << exp) - 1));
+    Type v = (exp == sizeof(Type)*CHAR_BIT ? x : (x & ((Type(1) << exp) - 1)));
     if (v >= Type(1) << (exp - 1))
       return set_neg_overflow_int<To_Policy>(to, dir);
     else
diff --git a/src/globals.inlines.hh b/src/globals.inlines.hh
index 196c46c..fd71d71 100644
--- a/src/globals.inlines.hh
+++ b/src/globals.inlines.hh
@@ -71,7 +71,7 @@ compute_capacity(const dimension_type requested_size,
   assert(requested_size <= maximum_size);
   // Speculation factor 2.
   return (requested_size < maximum_size/2)
-    ? 2*(requested_size + 1)
+    ? (2*(requested_size + 1))
     : maximum_size;
   // Speculation factor 1.5.
   // return (maximum_size - requested_size > requested_size/2)




More information about the PPL-devel mailing list