From: Patrick Tasse Date: Tue, 23 Aug 2016 20:30:24 +0000 (-0400) Subject: tmf: Fix integer overflow in time graph calculations X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=1d46761c66a5287c94f6e7c0964b253c24ae6eea;hp=7a65e099d459077e5c364dd330f8942a42dca414;p=deliverable%2Ftracecompass.git tmf: Fix integer overflow in time graph calculations An x-coordinate very far to the right could overflow to be very far to the left. This could prevent states and/or their labels to be drawn when zoomed-in very close. Change-Id: I6e006d366dfe427a9ac7df1a8f534fe95c230c3d Signed-off-by: Patrick Tasse Reviewed-on: https://git.eclipse.org/r/79565 Reviewed-by: Hudson CI Reviewed-by: Bernd Hufmann Tested-by: Bernd Hufmann --- diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java index 6263b622b2..25129bb3d4 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphControl.java @@ -76,6 +76,7 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Listener; import org.eclipse.swt.widgets.Menu; +import org.eclipse.tracecompass.common.core.math.SaturatedArithmetic; import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager; import org.eclipse.tracecompass.tmf.ui.signal.TmfTimeViewAlignmentInfo; import org.eclipse.tracecompass.tmf.ui.signal.TmfTimeViewAlignmentSignal; @@ -1465,7 +1466,7 @@ public class TimeGraphControl extends TimeGraphBaseControl int width = getSize().x; int nameSpace = fTimeProvider.getNameSpace(); double pixelsPerNanoSec = (width - nameSpace <= RIGHT_MARGIN) ? 0 : (double) (width - nameSpace - RIGHT_MARGIN) / (time1 - time0); - int x = getBounds().x + nameSpace + (int) ((time - time0) * pixelsPerNanoSec); + int x = SaturatedArithmetic.add(getBounds().x + nameSpace, (int) ((time - time0) * pixelsPerNanoSec)); return x; } @@ -1669,8 +1670,8 @@ public class TimeGraphControl extends TimeGraphBaseControl long selectionBegin = fTimeProvider.getSelectionBegin(); long selectionEnd = fTimeProvider.getSelectionEnd(); double pixelsPerNanoSec = (bounds.width - nameSpace <= RIGHT_MARGIN) ? 0 : (double) (bounds.width - nameSpace - RIGHT_MARGIN) / (time1 - time0); - int x0 = bounds.x + nameSpace + (int) ((selectionBegin - time0) * pixelsPerNanoSec); - int x1 = bounds.x + nameSpace + (int) ((selectionEnd - time0) * pixelsPerNanoSec); + int x0 = SaturatedArithmetic.add(bounds.x + nameSpace, (int) ((selectionBegin - time0) * pixelsPerNanoSec)); + int x1 = SaturatedArithmetic.add(bounds.x + nameSpace, (int) ((selectionEnd - time0) * pixelsPerNanoSec)); // draw selection lines if (fDragState != DRAG_SELECTION) { @@ -1961,8 +1962,8 @@ public class TimeGraphControl extends TimeGraphBaseControl int lastX = -1; while (iterator.hasNext()) { ITimeEvent event = iterator.next(); - int x = rect.x + (int) ((event.getTime() - time0) * pixelsPerNanoSec); - int xEnd = rect.x + (int) ((event.getTime() + event.getDuration() - time0) * pixelsPerNanoSec); + int x = SaturatedArithmetic.add(rect.x, (int) ((event.getTime() - time0) * pixelsPerNanoSec)); + int xEnd = SaturatedArithmetic.add(rect.x, (int) ((event.getTime() + event.getDuration() - time0) * pixelsPerNanoSec)); if (x >= rect.x + rect.width || xEnd < rect.x) { // event is out of bounds continue; diff --git a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphScale.java b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphScale.java index f9a1b7560c..4cecd5708c 100644 --- a/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphScale.java +++ b/tmf/org.eclipse.tracecompass.tmf.ui/src/org/eclipse/tracecompass/tmf/ui/widgets/timegraph/widgets/TimeGraphScale.java @@ -33,6 +33,7 @@ import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Rectangle; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Control; +import org.eclipse.tracecompass.common.core.math.SaturatedArithmetic; import org.eclipse.tracecompass.internal.tmf.ui.Messages; import org.eclipse.tracecompass.tmf.core.signal.TmfSignalHandler; import org.eclipse.tracecompass.tmf.core.signal.TmfSignalManager; @@ -366,8 +367,8 @@ public class TimeGraphScale extends TimeGraphBaseControl implements int x2; long selectionBegin = fTimeProvider.getSelectionBegin(); long selectionEnd = fTimeProvider.getSelectionEnd(); - x1 = leftSpace + (int) ((selectionBegin - time0) * pixelsPerNanoSec); - x2 = leftSpace + (int) ((selectionEnd - time0) * pixelsPerNanoSec); + x1 = SaturatedArithmetic.add(leftSpace, (int) ((selectionBegin - time0) * pixelsPerNanoSec)); + x2 = SaturatedArithmetic.add(leftSpace, (int) ((selectionEnd - time0) * pixelsPerNanoSec)); drawRangeDecorators(rect0, gc, x1, x2); } @@ -398,7 +399,7 @@ public class TimeGraphScale extends TimeGraphBaseControl implements List tickList = new ArrayList<>(); while (true) { - int x = rect.x + leftSpace + (int) (Math.floor((time - time0) * pixelsPerNanoSec)); + int x = SaturatedArithmetic.add(rect.x + leftSpace, (int) (Math.floor((time - time0) * pixelsPerNanoSec))); if (x >= rect.x + leftSpace + rect.width - rect0.width) { break; }