[gmx-developers] integer overflow in force.c:calc_avcsix
spoel at xray.bmc.uu.se
Mon Aug 4 19:08:03 CEST 2003
On Mon, 2003-08-04 at 19:01, Gerald Mathias wrote:
> Dear all,
> 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.
Yes, this bug has been fixed in CVS already, thanks for reporting it.
> 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.
> Best regards,
Dr. David van der Spoel, Dept. of Cell and Molecular Biology
Husargatan 3, Box 596, 75124 Uppsala, Sweden
phone: 46 18 471 4205 fax: 46 18 511 755
spoel at xray.bmc.uu.se spoel at gromacs.org http://xray.bmc.uu.se/~spoel
More information about the gromacs.org_gmx-developers