You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@geode.apache.org by "Dan Smith (JIRA)" <ji...@apache.org> on 2015/06/02 01:21:17 UTC

[jira] [Created] (GEODE-43) Integer overflow in PartitionedRegionLoadModel

Dan Smith created GEODE-43:
------------------------------

             Summary: Integer overflow in PartitionedRegionLoadModel
                 Key: GEODE-43
                 URL: https://issues.apache.org/jira/browse/GEODE-43
             Project: Geode
          Issue Type: Bug
          Components: core
    Affects Versions: 1.0.0-incubating
            Reporter: Dan Smith
            Assignee: Dan Smith


PartitionRegionLoadModel.getAverageLoad() is casting a float to an integer and potentially overflowing. totalLoad here is size of a region in bytes, this code easily be bigger than Integer.MaxValue.

{code}
private float getAverageLoad() {
    if(this.averageLoad == -1) {
      float totalWeight = 0;
      int totalLoad = 0;
      for(Member member : this.members.values()) {
        totalLoad += member.getTotalLoad();
        totalWeight += member.getWeight();
      }
      
      this.averageLoad = totalLoad / totalWeight;
    }
    
    return this.averageLoad;
  }
{code}

member.getTotalLoad() returns a float.

Interestingly, if this expression is written as below, the compiler will complain:
{code}
totalLoad = totalLoad + member.getTotalLoad()
{code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)