Compile Warning (Error) in trunk

Christian Stimming christian at cstimming.de
Sun Jun 10 15:32:25 EDT 2012


Am Samstag, 9. Juni 2012, 15:57:08 schrieb John Ralls:
> > casey at wizkid2:~/Downloads/gnucash$ gcc --version
> > gcc (Ubuntu/Linaro 4.6.1-9ubuntu3) 4.6.1
> > 
> > 
> >> Can you change the declarations at lines 166, 167, and 168 from int to
> >> gint64 and see if that makes the first warning go away?> 
> > It didn't help.  Got the same overflow warning.
> 
> Then it would seem to be a compiler bug, since the value clearly doesn't
> overflow a gint64, or a problem with your installation of GLib so that
> gint64 isn't correctly typedef'd. Try turning off that warning so that it
> will compile and see if it passes the tests anyway. If it does, then
> there's a problem with the compiler. If the gnc-date tests fail, then
> you'll need to figure out why gint64 doesn't make a 64-bit int.

Actually the change of declarations *does* fix this error. I've got the exact 
same compiler installed (gcc-4.6.1) and with -O2 it gave me the same error. 
Thinking about it, it also becomes rather clear why this is indeed a code 
error: The constant secs_per_year is equal to 0.9e9, which reaches almost 
INT_MAX, which is 2.1e9. Hence, multiplying secs_per_year with some value 
larger than one will immediately overflow. As by C language rules, if the two 
operands of the integer multiplications are "int", the multiplication itself 
will also be performed as "int", which in this case immediately overflows. The 
fact that the resulting value is written into a gint64 doesn't affect the 
actual multiplication.

Unfortunately, with -O2 and changing all declarations into gint64, I now run 
into new runtime check errors:
ERROR:../../../../../src/libqof/qof/test/test-gnc-
date.c:215:test_timespec_cmp: assertion failed (timespec_cmp (&td, &ta) == 
-1): (1 == -1)

I didn't understand the intention of the check here, sorry.

Regards,

Christian



More information about the gnucash-devel mailing list