Sharad Mishra has uploaded a new change for review. Change subject: core: fix corner case of random number (Long.MIN_VALUE) in RandomUtils. ......................................................................
core: fix corner case of random number (Long.MIN_VALUE) in RandomUtils. This code generates a random signed long and then computes the absolute value of that random long. If the number returned by the random number generator is Long.MIN_VALUE, then the result will be negative as well (since Math.abs(Long.MIN_VALUE) == Long.MIN_VALUE). Change-Id: Ic6fd4d0304c3ffa382fe20afa1a8d41f93a47bed Signed-off-by: Sharad Mishra <snmis...@linux.vnet.ibm.com> --- M backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/RandomUtils.java 1 file changed, 5 insertions(+), 1 deletion(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/51/7851/1 diff --git a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/RandomUtils.java b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/RandomUtils.java index bcd7c0a..2cc2eb9 100644 --- a/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/RandomUtils.java +++ b/backend/manager/modules/utils/src/main/java/org/ovirt/engine/core/utils/RandomUtils.java @@ -176,7 +176,11 @@ throw new IllegalArgumentException("l must be greater than 0!"); } - return (Math.abs(super.nextLong()) % l); + long rand = super.nextLong(); + if (rand == Long.MIN_VALUE) { + rand++; + } + return (Math.abs(rand) % l); } /** -- To view, visit http://gerrit.ovirt.org/7851 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ic6fd4d0304c3ffa382fe20afa1a8d41f93a47bed Gerrit-PatchSet: 1 Gerrit-Project: ovirt-engine Gerrit-Branch: master Gerrit-Owner: Sharad Mishra <snmis...@linux.vnet.ibm.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches