[PPL-devel] [GIT] ppl/ppl(master): Prefer using C_Integer traits rather than macros in <climits>, thereby
Enea Zaffanella
zaffanella at cs.unipr.it
Wed Feb 22 10:11:53 CET 2012
Module: ppl/ppl
Branch: master
Commit: ff759c6b48d0bf2ed81e2bcdaf5aa072d1b540e5
URL: http://www.cs.unipr.it/git/gitweb.cgi?p=ppl/ppl.git;a=commit;h=ff759c6b48d0bf2ed81e2bcdaf5aa072d1b540e5
Author: Enea Zaffanella <zaffanella at cs.unipr.it>
Date: Wed Feb 22 10:09:23 2012 +0100
Prefer using C_Integer traits rather than macros in <climits>, thereby
avoiding a few implicit conversions changing signedness.
Detected by ECLAIR service utypflag.
---
src/Bit_Matrix.cc | 11 +++++++----
src/Bit_Row.cc | 16 ++++++++--------
src/checked.cc | 9 +++++----
3 files changed, 20 insertions(+), 16 deletions(-)
diff --git a/src/Bit_Matrix.cc b/src/Bit_Matrix.cc
index 75e1fb1..96243f7 100644
--- a/src/Bit_Matrix.cc
+++ b/src/Bit_Matrix.cc
@@ -25,9 +25,9 @@ site: http://bugseng.com/products/ppl/ . */
#include "Bit_Matrix.defs.hh"
#include "globals.defs.hh"
#include "swapping_sort.templates.hh"
+#include "C_Integer.hh"
#include <iostream>
#include <string>
-#include <climits>
namespace PPL = Parma_Polyhedra_Library;
@@ -85,7 +85,8 @@ PPL::Bit_Matrix::transpose() {
const dimension_type ncols = num_columns();
Bit_Matrix tmp(ncols, nrows);
for (dimension_type i = nrows; i-- > 0; )
- for (unsigned long j = x[i].last(); j != ULONG_MAX; j = x[i].prev(j))
+ for (unsigned long j = x[i].last();
+ j != C_Integer<unsigned long>::max; j = x[i].prev(j))
tmp[j].set(i);
m_swap(tmp);
PPL_ASSERT(OK());
@@ -97,7 +98,8 @@ PPL::Bit_Matrix::transpose_assign(const Bit_Matrix& y) {
const dimension_type y_num_columns = y.num_columns();
Bit_Matrix tmp(y_num_columns, y_num_rows);
for (dimension_type i = y_num_rows; i-- > 0; )
- for (unsigned long j = y[i].last(); j != ULONG_MAX; j = y[i].prev(j))
+ for (unsigned long j = y[i].last();
+ j != C_Integer<unsigned long>::max; j = y[i].prev(j))
tmp[j].set(i);
m_swap(tmp);
PPL_ASSERT(OK());
@@ -205,7 +207,8 @@ PPL::Bit_Matrix::OK() const {
const Bit_Row& row = x[i];
if (!row.OK())
return false;
- else if (row.last() != ULONG_MAX && row.last() >= row_size) {
+ else if (row.last() != C_Integer<unsigned long>::max
+ && row.last() >= row_size) {
#ifndef NDEBUG
cerr << "Bit_Matrix[" << i << "] is a row with too many bits!"
<< endl
diff --git a/src/Bit_Row.cc b/src/Bit_Row.cc
index 9fec973..ac56da2 100644
--- a/src/Bit_Row.cc
+++ b/src/Bit_Row.cc
@@ -24,7 +24,7 @@ site: http://bugseng.com/products/ppl/ . */
#include "ppl-config.h"
#include "Bit_Row.defs.hh"
#include "assert.hh"
-#include <climits>
+#include "C_Integer.hh"
namespace PPL = Parma_Polyhedra_Library;
@@ -38,7 +38,7 @@ PPL::Bit_Row::first() const {
if (limb != 0)
return li*PPL_BITS_PER_GMP_LIMB + Implementation::first_one(limb);
}
- return ULONG_MAX;
+ return C_Integer<unsigned long>::max;
}
unsigned long
@@ -50,13 +50,13 @@ PPL::Bit_Row::next(unsigned long position) const {
// case mpz_scan1() is improved.
//
// unsigned long r = mpz_scan1(vec, position);
- // return (r == ULONG_MAX) ? -1 : r;
+ // return (r == C_Integer<unsigned long>::max) ? -1 : r;
mp_size_t li = position / PPL_BITS_PER_GMP_LIMB;
const mp_size_t vec_size = vec->_mp_size;
PPL_ASSERT(vec_size >= 0);
if (li >= vec_size)
- return ULONG_MAX;
+ return C_Integer<unsigned long>::max;
// Get the first limb.
mp_srcptr p = vec->_mp_d + li;
@@ -74,7 +74,7 @@ PPL::Bit_Row::next(unsigned long position) const {
++p;
limb = *p;
}
- return ULONG_MAX;
+ return C_Integer<unsigned long>::max;
}
unsigned long
@@ -82,7 +82,7 @@ PPL::Bit_Row::last() const {
mp_size_t li = vec->_mp_size;
PPL_ASSERT(li >= 0);
if (li == 0)
- return ULONG_MAX;
+ return C_Integer<unsigned long>::max;
--li;
const mp_srcptr p = vec->_mp_d + li;
const mp_limb_t limb = *p;
@@ -93,7 +93,7 @@ PPL::Bit_Row::last() const {
unsigned long
PPL::Bit_Row::prev(unsigned long position) const {
if (position == 0)
- return ULONG_MAX;
+ return C_Integer<unsigned long>::max;
--position;
@@ -127,7 +127,7 @@ PPL::Bit_Row::prev(unsigned long position) const {
--p;
limb = *p;
}
- return ULONG_MAX;
+ return C_Integer<unsigned long>::max;
}
bool
diff --git a/src/checked.cc b/src/checked.cc
index 2fc1900..b024861 100644
--- a/src/checked.cc
+++ b/src/checked.cc
@@ -23,7 +23,7 @@ site: http://bugseng.com/products/ppl/ . */
#include "ppl-config.h"
#include "checked.defs.hh"
-#include <climits>
+#include "C_Integer.hh"
namespace Parma_Polyhedra_Library {
@@ -109,7 +109,7 @@ inline bool
sum_sign(bool& a_neg, unsigned long& a_mod,
bool b_neg, unsigned long b_mod) {
if (a_neg == b_neg) {
- if (a_mod > ULONG_MAX - b_mod)
+ if (a_mod > C_Integer<unsigned long>::max - b_mod)
return false;
a_mod += b_mod;
}
@@ -279,8 +279,9 @@ parse_number_part(std::istream& is, number_struct& numer) {
exp:
state = EXPONENT;
PPL_ASSERT(numer.base >= 2);
- max_exp_div = LONG_MAX / numer.base;
- max_exp_rem = static_cast<int>(LONG_MAX % numer.base);
+ const long l_max = C_Integer<long>::max;
+ max_exp_div = static_cast<unsigned long>(l_max) / numer.base;
+ max_exp_rem = static_cast<int>(l_max % static_cast<long>(numer.base));
if (!is.get(c))
return V_CVT_STR_UNK;
if (c == '-') {
More information about the PPL-devel
mailing list