Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Report Control
  New Posts New Posts RSS Feed - TrackControl overflow problem
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

TrackControl overflow problem

 Post Reply Post Reply
Author
Message
Aaron Koolen View Drop Down
Groupie
Groupie


Joined: 22 July 2009
Status: Offline
Points: 32
Post Options Post Options   Thanks (0) Thanks(0)   Quote Aaron Koolen Quote  Post ReplyReply Direct Link To This Post Topic: TrackControl overflow problem
    Posted: 20 June 2010 at 11:17pm
Hi there.
I was getting strange behaviour with my TrackControl where the slider would jump to the end of my time line range when I reached a certain position. I tracked the issue down to an overflow in the CXTPTrackControlHeader OnMoveSlider (~line 180) method.



int fromPosition = m_ptStartDrag.x * (pControl->GetTimeLineMax() - pControl->GetTimeLineMin()) / rcSliderArea.Width();
int toPosition = pt.x * (pControl->GetTimeLineMax() - pControl->GetTimeLineMin()) / rcSliderArea.Width();
int delta = toPosition - fromPosition;


With large timelines, as I had, the initial multiplication overflowed into negative. The fromPosition and toPosition can actually be removed and the delta performed before the multiplication and division. Even better would be to divide first, as I don't think the difference in rounding would matter. I have made the change in my code and all is working well.

As an aside to this, I would suggest that CXTPTrackControl handled unsigned.

Aaron

Product: Xtreme ToolkitPro v13.3.0 (MFC)
Platform: Windows XP (32bit) - SP 3
Language: Visual C++ 6
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 21 June 2010 at 9:24am
Thanks, replaced to


     int fromPosition = MulDiv(m_ptStartDrag.x, (pControl->GetTimeLineMax() - pControl->GetTimeLineMin()), rcSliderArea.Width());
     int toPosition = MulDiv(pt.x, (pControl->GetTimeLineMax() - pControl->GetTimeLineMin()), rcSliderArea.Width());
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
Aaron Koolen View Drop Down
Groupie
Groupie


Joined: 22 July 2009
Status: Offline
Points: 32
Post Options Post Options   Thanks (0) Thanks(0)   Quote Aaron Koolen Quote  Post ReplyReply Direct Link To This Post Posted: 21 June 2010 at 5:49pm
No problem. I also found a couple of other places where the same thing occurs.

XTPrackPaintManager::DrawTrackHeader, around line 305.
XTPTrackHeader::OnLButtonDown, around line 418.

Both of those perform out of range multiplications.

Cheers
Aaron

Product: Xtreme ToolkitPro v13.3.0 (MFC)
Platform: Windows XP (32bit) - SP 3
Language: Visual C++ 6
Back to Top
Oleg View Drop Down
Admin Group
Admin Group


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 23 June 2010 at 5:02am
Thanks, replaced also.
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.250 seconds.