-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Signed integer property queries #1493
Comments
Should definitely be int64_t rather than long or the traditional types so that its always the correct size on whatever architecture. I'll take a look to see if it needs to go into 1.4, rather than 1.3.x. What would the Rust client think of a type change - any ramifications there? |
There are two issues 1) the sign/size of the integer and 2) error reporting. To allow the code to work on 16 bit systems, the 4 byte fields should be (unsigned) long or uint32_t (at least). The error reporting would be better done as another parameter - something that wasn't part of the return space. 64 bit minimum would be long long. If we went to uint64_t for now, that would mean changing again for the ideal solution of returning uint32_t and a different error return. That leaves me in favour of doing it properly in 1.4 and leaving 1.3.x for now. |
Yes, if we want to have the full range of the returned value (u32) and room for an error value, then we need a type larger than u32. I would lean toward returning an All that would require is changing the return type from As an aside... 16-bit system?!? Are you still testing on Windows 95?!? Hahaha. |
Also... I would vote to fix this in 1.3.x if 1.4 is still a while to be release. I'm planning releases for Paho C++ and Rust based on the next 1.3.x, from the develop branch, and it would be nice to have this resolved. Although, honestly, I agree this isn't a really big deal. The chance of someone having a session expiry interval of exactly 4284967297 seconds (-9999999 as a uint32_t) is probably pretty slim. |
There are some people who ask about 16 bit systems :-) No point in deliberately not making it work, but it's not something I thought about previously. |
I've put in the change to int64_t for the return value from the functions: MQTTProperties_getNumericValueAt I didn't get any build warnings so I think it's good. I might open another issue for 1.4 to ensure that the 4 byte values don't use int - for 16 byte systems. |
Nice! Yeah, I'm trying to more precise with the integer sizing lately; using the sized types when I know the required size. |
On the Paho C++ repo, someone just pointed out that the 2 and 4-byte integer property values are defined to always be unsigned. (According to the v5 spec). Paho C++ #498 .
Somehow the "always unsigned" part escaped me these last few years.
In this C library it is coded correctly in the enum inside
MQTTProperty
, but the retrieval functions return anint
, which is 32-bits on most modern PC compilers.This means that larger 4-byte values will be misinterpreted as negative numbers, which is kinda bad. But it also means that the "error" return value of -9999999 falls well within the range of valid possible values, and in fact, any 32-bit int value could be valid.
Shouldn't these functions actually return a
long
or - better yet - anint64_t
value where anything >= 0 would be valid, and anything <0 is an error? You could still use -9999999, or make it -1, maybe.I guess, technically, this would be a minor breaking change in the API, but not one that would probably break a lot of builds. And it would be worth it to fix the issue.
The text was updated successfully, but these errors were encountered: