[PPL-devel] [GIT] ppl/ppl(master): Avoid unsigned integer wrap-around in constant expressions.

Marco Poletti poletti.marco at gmail.com
Sat Oct 29 14:06:21 CEST 2011


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

Author: Marco Poletti <poletti.marco at gmail.com>
Date:   Sat Oct 29 14:04:21 2011 +0200

Avoid unsigned integer wrap-around in constant expressions.
Detected by ECLAIR service cnstwrap.

---

 src/CO_Tree.defs.hh    |    4 ++--
 src/CO_Tree.inlines.hh |    2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/CO_Tree.defs.hh b/src/CO_Tree.defs.hh
index f565ffd..fe72838 100644
--- a/src/CO_Tree.defs.hh
+++ b/src/CO_Tree.defs.hh
@@ -106,7 +106,7 @@ private:
   //! This is used for node heights and depths in the tree.
   typedef unsigned height_t;
 
-  PPL_COMPILE_TIME_CHECK(-(height_t)1 >= CHAR_BITS*sizeof(dimension_type),
+  PPL_COMPILE_TIME_CHECK(C_Integer<height_t>::max >= CHAR_BITS*sizeof(dimension_type),
                          "height_t is too small to store depths.");
 
   class tree_iterator;
@@ -1251,7 +1251,7 @@ private:
   /*!
     This must not be used as a key.
   */
-  static const dimension_type unused_index = -(dimension_type)1;
+  static const dimension_type unused_index = C_Integer<dimension_type>::max;
 
   //! The %iterator returned by end().
   /*!
diff --git a/src/CO_Tree.inlines.hh b/src/CO_Tree.inlines.hh
index 8d12bab..9ff72a7 100644
--- a/src/CO_Tree.inlines.hh
+++ b/src/CO_Tree.inlines.hh
@@ -99,7 +99,7 @@ CO_Tree::size() const {
 
 inline dimension_type
 CO_Tree::max_size() {
-  return (-dimension_type(1))/100;
+  return C_Integer<dimension_type>::max/100;
 }
 
 inline void




More information about the PPL-devel mailing list