Skip to content

Commit

Permalink
fix overflow bug with cosmo8
Browse files Browse the repository at this point in the history
  • Loading branch information
jortiz16 committed May 1, 2015
1 parent 69b25a0 commit 8bb6bf0
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ protected final void init(final ImmutableMap<String, Object> execEnvVars) throws
ndark = dataInputForBin.readInt();
nstar = dataInputForBin.readInt();
dataInputForBin.readInt();
long proposed = H_SIZE + ngas * G_SIZE + ndark * D_SIZE + nstar * S_SIZE;
long proposed = (long) H_SIZE + ngas * G_SIZE + ndark * D_SIZE + nstar * S_SIZE;
if (ntot != ngas + ndark + nstar) {
throw new DbException("header info incorrect");
}
Expand Down

2 comments on commit 8bb6bf0

@jingjingwang
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although this fix solves the overflow problem, it doesn't seem to be the perfect fix to me, since the fault is not on H_SIZE :) What if, for example, ngas * G_SIZE gets larger than INT_MAX in another simulation..?

I think depends on your expectation of the data, you may need to declare ngas/ndark/nstar as long.

@domoritz
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, we should use Guava's overflow checks.

Please sign in to comment.