Bug in MyGUI::Progress::updateTrack()

shenjoku

02-12-2011 01:00:25

There's a bad bug in MyGUI::Progress::updateTrack() that is causing the track position to not get clamped between the min and max properly. This issue only occurs, however, if you pass in an unsigned integer value larger than the max value of signed int. One line causing the issue is on line 225:
setTrackPosition(wid, pos, 0, ((int)mEndPosition * (getClientWidth() - mTrackMin) / (int)mRange) - pos + mTrackMin, getClientHeight());

The reason this is broken, is that the unsigned integer values are being cast to int, which turns them into negative values if they are above maxint. Since the code in this class is not clamping values properly but instead just trying to add it to the result it is passing in a negative number which makes the track set to zero.

The proposed fix for this problem would be to completely remove all cases of where mTrackMin is being added to values passed to setTrackPosition() and instead, inside of setTrackPosition(), to clamp the passed in width value between mTrackMin and mTrackWidth.

Thoughts?