From 87333ac31592c329a000bcba8be8aa568ef12eb3 Mon Sep 17 00:00:00 2001 From: Joel Uckelman Date: Sun, 10 Sep 2023 00:12:08 +0100 Subject: [PATCH] IncrementPropertly: Corrected bad wrap-around calculation when increment is negative. --- .../VASSAL/build/module/properties/IncrementProperty.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/vassal-app/src/main/java/VASSAL/build/module/properties/IncrementProperty.java b/vassal-app/src/main/java/VASSAL/build/module/properties/IncrementProperty.java index aef4213887..d012bcc974 100644 --- a/vassal-app/src/main/java/VASSAL/build/module/properties/IncrementProperty.java +++ b/vassal-app/src/main/java/VASSAL/build/module/properties/IncrementProperty.java @@ -82,7 +82,11 @@ public String getNewValue(String oldValue) { else if (constraints.isWrap()) { final int min = constraints.getMinimumValue(); final int max = constraints.getMaximumValue(); - value = min + ((value - min + incr) % (max - min + incr)); + final int range = max - min + 1; + // NB: value - min + incr could be < 0 (but > -range), which is + // why we add range and mod a second time to ensure that the + // result is in [0,range). + value = min + ((value - min + incr) % range + range) % range; } else { value += incr;