Print Page | Close Window

TrackControl overflow problem

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Report Control
Forum Description: Topics Related to Codejock Report Control
URL: http://forum.codejock.com/forum_posts.asp?TID=16855
Printed Date: 23 November 2024 at 7:28am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: TrackControl overflow problem
Posted By: Aaron Koolen
Subject: TrackControl overflow problem
Date 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



Replies:
Posted By: Oleg
Date 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


Posted By: Aaron Koolen
Date 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


Posted By: Oleg
Date Posted: 23 June 2010 at 5:02am
Thanks, replaced also.

-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net