-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: allow controller setting integer to have a negative range #13656
fix: allow controller setting integer to have a negative range #13656
Conversation
return AbstractLegacyControllerSetting::valid() && | ||
m_defaultValue >= m_minValue && m_savedValue >= m_minValue && | ||
m_editedValue >= m_minValue && m_defaultValue <= m_maxValue && | ||
m_savedValue <= m_maxValue && m_editedValue <= m_maxValue && | ||
m_stepValue > 0 && m_stepValue < m_maxValue; | ||
m_stepValue > 0 && | ||
(typeSize || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be confirmed, but I read that some platform use the same byte size for int
and long
and since the default min and max uses the int limits, without a larger type, this would lead to an overflow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of the temp variable sounds like a size itself. Since long is different on Linux and Windows we try to not use it at all. What is the reason that it is used here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case of an int a step value can't be bigger than the half of the range. If we assume 8 bit, we may have
-128 ... 127 and the maximum Step that can be expressed is 127.
So you may check:
m_minValue <= 0 && m_minValue + m_stepValue <= m_maxValue &&
m_maxValue >= 0 && m_maxValue - m_stepValue >= sm_minValue
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And m_maxValue - m_stepValue < m_maxValue for the unsigned case ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and put it in a utility function please. The long condition chain is already not super easy to follow.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And m_maxValue - m_stepValue < m_maxValue for the unsigned case ...
Not sure which usecase you are referring to?
What is the usecase for this? If I understand |
This doesn't allow a |
return AbstractLegacyControllerSetting::valid() && | ||
m_defaultValue >= m_minValue && m_savedValue >= m_minValue && | ||
m_editedValue >= m_minValue && m_defaultValue <= m_maxValue && | ||
m_savedValue <= m_maxValue && m_editedValue <= m_maxValue && | ||
m_stepValue > 0 && m_stepValue < m_maxValue; | ||
m_stepValue > 0 && | ||
(typeSize || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name of the temp variable sounds like a size itself. Since long is different on Linux and Windows we try to not use it at all. What is the reason that it is used here?
return AbstractLegacyControllerSetting::valid() && | ||
m_defaultValue >= m_minValue && m_savedValue >= m_minValue && | ||
m_editedValue >= m_minValue && m_defaultValue <= m_maxValue && | ||
m_savedValue <= m_maxValue && m_editedValue <= m_maxValue && | ||
m_stepValue > 0 && m_stepValue < m_maxValue; | ||
m_stepValue > 0 && | ||
(typeSize || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In case of an int a step value can't be bigger than the half of the range. If we assume 8 bit, we may have
-128 ... 127 and the maximum Step that can be expressed is 127.
So you may check:
m_minValue <= 0 && m_minValue + m_stepValue <= m_maxValue &&
m_maxValue >= 0 && m_maxValue - m_stepValue >= sm_minValue
ah, yeah. That makes total sense. Thanks for the explanation. |
9aabb13
to
b050325
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm otherwise.
@@ -263,7 +271,7 @@ class LegacyControllerNumberSetting | |||
m_defaultValue >= m_minValue && m_savedValue >= m_minValue && | |||
m_editedValue >= m_minValue && m_defaultValue <= m_maxValue && | |||
m_savedValue <= m_maxValue && m_editedValue <= m_maxValue && | |||
m_stepValue > 0 && m_stepValue < m_maxValue; | |||
m_stepValue > 0 && valid_range(m_minValue, m_maxValue, m_stepValue); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We may face the condition that the default "default" = 0 in case of a missing attribute is not valid. Do we want to improve that as well for the negative range?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added the usecase at the de-serialisation step.
2326ded
to
9cf405f
Compare
VERIFY_OR_DEBUG_ASSERT(step >= 0) { | ||
return false; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we actually ensure this somewhere else (and provide appropriate debug feedback)? I'm not particularly familiar with the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes and no. If a setting definition is invalid, you will get a warning log message telling you about it, no actual UI feedback on the matter.
At the time of implementation, the assumption was made that mapping developer would be able to gather log if they needed to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
debug message is fine, does it specify what exactly is invalid?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it just says it will ignore a definition due to an invalid settings
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thats unfortunate. we should fix that in the future. Just saying something is invalid gets increasingly frustrating the more complex the definition is. how would I know which of my (hypothetical) 10 parameters are invalid? Out-of-scope here though. Just suggestion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You would know which settings is invalid, but it wouldn't details what's wrong with it (e.g Default out of range? Min after max?)
The warning for that is here
Let's say you have 10 setitings (my setting1
..mySetting10
), and mySetting6
is invalid, you would get something like
Warning: The parsed setting in file "/home/me/myfile.hid.xml" at line 42 appears to be invalid. It will be ignored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, thats not great once a setting has a bunch of parameters (along with non-obvious constraints). Ideally the parser should be able to report validation failures as they happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might look into that for the future. Happy to get this bugfix in the meantime?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thank you.
No description provided.