Skip to content
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

Merged

Conversation

acolombier
Copy link
Member

No description provided.

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 ||
Copy link
Member Author

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.

Copy link
Member

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?

Copy link
Member

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

Copy link
Member

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 ...

Copy link
Member

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.

Copy link
Member Author

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?

@Swiftb0y
Copy link
Member

What is the usecase for this? If I understand LegacyControllerNumberSetting correctly, its just modeling a closed integer interval $[ a \ldotp \ldotp b ]$ (where $a \leq b$), right? What is the purpose of allowing $a \ge b$ too?

@acolombier
Copy link
Member Author

This doesn't allow a a > b, it allows the step to be less than the max. My usecase was the following: I have a setting that can be in the range [-250; 0] and the step is 1. Currently, this would fall. With this changes, instead of doing making sure the step is less than the max, it makes sure the the step is less than the range side (250 in my case)

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 ||
Copy link
Member

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 ||
Copy link
Member

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

@Swiftb0y
Copy link
Member

This doesn't allow a a > b, it allows the step to be less than the max. My usecase was the following: I have a setting that can be in the range [-250; 0] and the step is 1. Currently, this would fall. With this changes, instead of doing making sure the step is less than the max, it makes sure the the step is less than the range side (250 in my case)

ah, yeah. That makes total sense. Thanks for the explanation.

@acolombier acolombier force-pushed the fix/controller-setting-integer-negative-range branch from 9aabb13 to b050325 Compare September 16, 2024 11:05
Copy link
Member

@Swiftb0y Swiftb0y left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm otherwise.

src/controllers/legacycontrollersettings.h Outdated Show resolved Hide resolved
@@ -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);
Copy link
Member

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?

Copy link
Member Author

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.

@acolombier acolombier force-pushed the fix/controller-setting-integer-negative-range branch from 2326ded to 9cf405f Compare September 19, 2024 12:36
Comment on lines +12 to +14
VERIFY_OR_DEBUG_ASSERT(step >= 0) {
return false;
}
Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member

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?

Copy link
Member Author

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

Copy link
Member

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.

Copy link
Member Author

@acolombier acolombier Sep 19, 2024

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.

Copy link
Member

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.

Copy link
Member Author

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?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes.

Copy link
Member

@daschuer daschuer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you.

Copy link
Member

@Swiftb0y Swiftb0y left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thank you.

@Swiftb0y Swiftb0y merged commit 5b895b8 into mixxxdj:2.5 Sep 20, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants