[GiNaC-list] Possible size issue in test in numeric.cpp

Pierangelo Masarati masarati at aero.polimi.it
Sun Aug 6 12:15:08 CEST 2006


We're using GiNaC inside our multibody analysis software MBDyn to perform 
automatic differentiation of constitutive laws for deofrmable elements.  
Right now its use is not very intensive, but we plan to extend it quite 

I haven't built GiNaC for a while, and today, rebuilding a 1.3.4 rpm, I 
noticed a warning in numeric.cpp. 

First, a note on the system: it's an AMD Athlon 64, running CentOS 4.2, 
which means stock RedHat gcc/g++ 3.4.5.  I haven't checked with gcc 4.X yet, 
but the issue seems to be clear enough. 

The warning is at line 95 of ginac/numeric.cpp and it didn't change from 
GiNaC 1.3.4 to today's CVS: 

[masarati at ando ginac]$ make numeric.o
if g++ -DHAVE_CONFIG_H -I. -I. -I..     -g -O2 -MT numeric.o -MD -MP -MF 
".deps/numeric.Tpo" -c -o numeric.o numeric.cpp; \
then mv -f ".deps/numeric.Tpo" ".deps/numeric.Po"; else rm -f 
".deps/numeric.Tpo"; exit 1; fi
numeric.cpp: In constructor `GiNaC::numeric::numeric(int)':
numeric.cpp:95: warning: comparison is always true due to limited range of 
data type
numeric.cpp:95: warning: comparison is always true due to limited range of 
data type 

The constructor of "numeric" that takes an "int" as its argument "i" 
performs the test 

       i < (1L << (cl_value_len-1)) 

On my system, "cl_value_len" is 32; so, "1L << 31" is out of range for an 
"int".  Then, the test 

       i >= -(1L << (cl_value_len-1)) 

follows, which is again out of range for an int.  It took a while to figure 
out what that code was intended for.  It appears that cln uses few bits of 
an int, on 32 bit architectures, to store reserved metainformation; on the 
contrary, on architectures with 64 bit pointers, the whole int range is 
available.  My guess is that the test is incorrect on those architectures, 
but I admit I haven't investigated enough. 

I've placed a patch at
please review or feel free to fix as appropriate, in case I'm missing 
anything obvious. 

Sincerely, p. 

Dr. Pierangelo Masarati               | voice: +39 02 2399 8309
Dip. Ing. Aerospaziale                | fax:   +39 02 2399 8334
Politecnico di Milano                 | mailto:pierangelo.masarati at polimi.it
via La Masa 34, 20156 Milano, Italy   | http://www.aero.polimi.it/~masarati 

Please avoid sending me Word or PowerPoint attachments.
See http://www.gnu.org/philosophy/no-word-attachments.html

More information about the GiNaC-list mailing list