Package: ginac
Version: 1.4.3-1

Hi! While compiling your package on arm, where characters are unsigned
by default, I noticed a bug:

g++ -DHAVE_CONFIG_H -I. -I. -I.. -g -Wall -O2 -finline-limit=1200 -c
add.cpp  -fPIC -DPIC -o add.o
add.cpp: In member function 'virtual GiNaC::ex GiNaC::add::coeff(const
GiNaC::ex&, int) const':
add.cpp:295: warning: comparison is always true due to limited range
of data type
add.cpp:304: warning: comparison is always false due to limited range
of data type

because clifford_max_label returns either a valid unsigned char 0-255
or -1 on failure, which will never signal failure where character->int
promotion yields 0-255, and would give a false failure on
architectures with signed characters for a valid return value of 255
(if this is possible).

The attached patch fixed this by extending the return value to int so
that all 257 values can be returned.
This patch fixes a bug on machines where char is unsigned by default, by
extending the type of clifford_max_label to include all 257 possible
return values.

--- ginac-1.4.3.orig/ginac/add.cpp      2008-03-27 10:16:10.000000000 +0000
+++ ginac-1.4.3/ginac/add.cpp   2008-05-03 10:59:02.000000000 +0100
@@ -291,7 +291,7 @@
 {
        std::auto_ptr<epvector> coeffseq(new epvector);
        std::auto_ptr<epvector> coeffseq_cliff(new epvector);
-       char rl = clifford_max_label(s);
+       int rl = clifford_max_label(s);
        bool do_clifford = (rl != -1);
        bool nonscalar = false;
 
--- ginac-1.4.3.orig/ginac/clifford.cpp 2008-03-27 10:16:10.000000000 +0000
+++ ginac-1.4.3/ginac/clifford.cpp      2008-05-03 10:58:24.000000000 +0100
@@ -1126,7 +1126,7 @@
        return e1;
 }
 
-char clifford_max_label(const ex & e, bool ignore_ONE)
+int clifford_max_label(const ex & e, bool ignore_ONE)
 {
        if (is_a<clifford>(e))
                if (ignore_ONE && is_a<diracone>(e.op(0)))
@@ -1134,7 +1134,7 @@
                else
                        return ex_to<clifford>(e).get_representation_label();
        else {
-               char rl = -1;
+               int rl = -1;
                for (size_t i=0; i < e.nops(); i++) 
                        rl = (rl > clifford_max_label(e.op(i), ignore_ONE)) ? 
rl : clifford_max_label(e.op(i), ignore_ONE);
                return rl;
--- ginac-1.4.3.orig/ginac/clifford.h   2008-03-27 10:16:10.000000000 +0000
+++ ginac-1.4.3/ginac/clifford.h        2008-05-03 11:04:08.000000000 +0100
@@ -299,7 +299,7 @@
  *
  *  @param e Expression to be processed
  *  @ignore_ONE defines if clifford_ONE should be ignored in the search*/
-char clifford_max_label(const ex & e, bool ignore_ONE = false);
+int clifford_max_label(const ex & e, bool ignore_ONE = false);
 
 /** Calculation of the norm in the Clifford algebra. */
 ex clifford_norm(const ex & e);

Reply via email to