Commit 2d947bf5 authored by Rob Latham's avatar Rob Latham
Browse files

fix unsigned arithmetic yielding unsigned



clang finds a spot where we took the abs() of two unsigned numbers.
result can never be negative (could be surprisingly large).
Signed-off-by: default avatarPaul Coffman <pkcoff@us.ibm.com>
parent fab604e6
......@@ -92,7 +92,7 @@ static unsigned procManhattanDistance(unsigned *aggCoords, unsigned *bridgeCoord
unsigned totalDistance = 0;
int i;
for (i=0;i<MPIX_TORUS_MAX_DIMS;i++) {
unsigned dimDistance = abs(aggCoords[i] - bridgeCoords[i]);
unsigned dimDistance = abs((int)aggCoords[i] - (int)bridgeCoords[i]);
if (dimDistance > 0) { // could torus make it closer?
if (dimTorus[i]) {
if (aggCoords[i] == torusSize[i]) { // is wrap-around closer
......@@ -104,7 +104,8 @@ static unsigned procManhattanDistance(unsigned *aggCoords, unsigned *bridgeCoord
dimDistance = aggCoords[i]+1;
}
}
}
} /* else: dimDistance == 0, meaning aggCoords[i] and bridgeCoords[i] are
the same and there's no closer point to pick */
totalDistance += dimDistance;
}
return totalDistance;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment