[gmx-developers] integer overflow in force.c:calc_avcsix
gerald.mathias at physik.uni-muenchen.de
Mon Aug 4 19:01:19 CEST 2003
I just came across a bug in 'calc_avcsix' in
'src/mdlib/force.c' (gmx-version 3.1.4).
The routine calculates the average C6 constant
for the long-range dispersion correction to energy and pressure.
The line 433
csix /= (natoms*natoms);
causes an integer overflow with a compiler that uses four byte integers
(as most do) for
natoms > SQRT(2^31) = 46,341
as the product of integers 'natoms*natoms'
is calculated before the cast to double is performed.
Thus, natoms should be casted to double beforehand.
The effect might not be too obvious in inhomogeneous systems,
as 'natoms*natoms' can still hold a rather large (tough undefined) number.
However, in a simulation of a large water box I was running, I had a factor
of ten in the dispersion energy and an increase of 6% of the density.
Lehrstuhl fuer BioMolekulare Optik (BMO)
Tel.: +49-89-2180 9224
Fax.: +49-89-2180 9202
More information about the gromacs.org_gmx-developers