summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
7957e6e)
[problem] A crash has been reported with a stack trace showing an integer
divide by zero exception in FixedRuler::GetPageFromPosition().
[cause] We have code there that divides by zero if a FixedRuler is setup
with a domain that is smaller than its page spacing
(a nonsensical state)
[solution] Clamp the divisor to be >= 1 and log an error so the App devs can
choose to fix the setup of the FixedRuler. Additionally, force
the page spacing to a reasonable value at construction time to
avoid a second set of possible divide by zero errors in floating
point numbers.
Change-Id: Iae4fa025600c2ee54796fc458ca367d993c6ef66
Signed-off-by: Andrew Cox <andrew.cox@partner.samsung.com>
FixedRuler::FixedRuler(float spacing)
: mSpacing(spacing)
{
FixedRuler::FixedRuler(float spacing)
: mSpacing(spacing)
{
+ if(fabsf(mSpacing) <= Math::MACHINE_EPSILON_1)
+ {
+ DALI_LOG_ERROR( "Page spacing too small (%f).", double(spacing) );
+ mSpacing = spacing >= 0.0f ? Math::MACHINE_EPSILON_1 : -Math::MACHINE_EPSILON_1;
+ }
volume = 0;
// spacing must be present.
volume = 0;
// spacing must be present.
- if(mEnabled && fabsf(mSpacing) > Math::MACHINE_EPSILON_1)
{
unsigned int column = page;
{
unsigned int column = page;
unsigned int page = 0;
// spacing must be present.
unsigned int page = 0;
// spacing must be present.
- if(mEnabled && fabsf(mSpacing) > Math::MACHINE_EPSILON_1)
if(wrap)
{
unsigned int pagesPerVolume = mDomain.GetSize() / mSpacing;
if(wrap)
{
unsigned int pagesPerVolume = mDomain.GetSize() / mSpacing;
+ // Defensive check to avoid a divide by zero below when the ruler is in an invalid state (entire domain smaller than spacing between pages of it):
+ if(pagesPerVolume < 1u)
+ {
+ pagesPerVolume = 1u;
+ DALI_LOG_ERROR("Ruler domain(%f) is smaller than its spacing(%f).", mDomain.GetSize() * 1.0, mSpacing * 1.0 );
+ }
page %= pagesPerVolume;
}
}
page %= pagesPerVolume;
}
}
unsigned int pagesPerVolume = 1;
// spacing must be present.
unsigned int pagesPerVolume = 1;
// spacing must be present.
- if(mEnabled && fabsf(mSpacing) > Math::MACHINE_EPSILON_1)
{
pagesPerVolume = mDomain.GetSize() / mSpacing;
}
{
pagesPerVolume = mDomain.GetSize() / mSpacing;
}