-
Notifications
You must be signed in to change notification settings - Fork 1
Fix clipping of integer values #81
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
base: develop
Are you sure you want to change the base?
Conversation
Clamp parsed 32/64-bit value to 8/16-bit as required. Use `simple-int` test value which exceeds int8_t range to verify
c84618d to
fb769cb
Compare
I would rather have the library throw an error if the number is out of range, but thinking about this, I've never tested that at all, what happens if I call |
It stores 64. Value is clamped/clipped to range. See #1 (comment) |
|
I haven't really spent any time yet on error reporting #49 or change callbacks #48, both of which are mechanisms by which errors like these might be handled. At present, Range errors can (and probably should) be managed more in the front end using standard HTML validation, using the ranges defined in the schema. If that is done, then at least database behaviour is predictable. |
|
I've been thinking if it would be worthwhile to implement something like esp_idf uses where every function call returns ESP_ERROR but then, I think that's not really worth it - at least not for my application. The challenge is, that the code does not "know" the min and max values for a given updater function, so it's really down to the developer to obey this range by knowing the schema. It would potentially be good to have getters for those range borders, (like How about a flag that is updated after every write to a store? If I want to be cautious, I could write that would be a single value per store that could be updated with every set function and the developer would be free to check it to be sure. [edit] in a roundabout way that would be a way to derive the max and min for any property, just call it with the largest/smallest INT, check for E_CLAMPED and read back the value - that is the min/max for that field. not straight forward, but workable. |
81b0ffd to
82e9dbb
Compare
|
I think this is wandering off-topic as this PR is just a bugfix - I'll merge this PR once CI completes.
Last commit in this PR changes the parameter type to |
Work with signed 64-bit arguments when setting properties, except for explicit `uint64_t` properties.
adfb1c5 to
4779755
Compare
This PR fixes #80 so that when setting integer values they are clipped/clamped to the correct range rather than being truncated modulo-2. Values are now treated as signed 64-bit integers which are clamped as appropriate. The exception is for unsigned 64-bit storage type, which just uses
uint64_t.This affects:
set_xxxmethods, which use the smallest appropriate data type for the value.The test data has been updated to verify that this operates correctly.