-
-
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
Runtime Error in MQTTPacket_formatPayload Due to char Type Not Defaulting to Unsigned in MSVC 193833134 (Visual Studio 2022) #1565
Comments
The problem here is that the behavior for
Therefore, the CRT debug library correctly throws an assertion error if the character is outside this range to prevent undefined behavior:
The problem is that although Following code locations might produce the same issue: Footnotes
|
It does feel a little odd to accept an int but only be valid for an unsigned char! I presume a cast to unsigned char would work in this case ... |
Is this a new issue? (I see the code that calls isprint() was added 2 months ago...) I was happily using vcpkg paho-mqttpp3 dependency for a while now and just now decided to update vcpkg baseline to the latest. That pulled everything latest, and now I get this error when trying to run my client. Is the workaround going back to the older version? If yes, can you recommend which one? I'm using protobuf for the payload (the publish method accepts a byte array) and the 'c' it fails on for me has a value -102 but the exact number is obviously irrelevant. This happens on the async send thread: The error: Debug Assertion Failed! The call stack:
The 'char' in this function signature 'int MQTTPacket_formatPayload(int buflen, char* buf, int payloadlen, char* payload)' can obviously be any byte character. To be honest, I'm surprised the isprint() has an assert in debug version. Like was mentions already it should be cast to 'unsighned char' to safely call isprint(): Like all other functions from , the behavior of std::isprint is undefined if the argument's value is neither representable as unsigned char nor equal to EOF. To use these functions safely with plain chars (or signed chars), the argument should first be converted to unsigned char: bool my_isprint(char ch) |
Yes, it was introduced two months ago. The previous version 1.3.13 doesn't have it. |
Issue Description:
Compilation Environment: Visual Studio 2022
Compiler Version: MSVC 193833134
In the file
paho.mqtt.c\src\MQTTPacket.c
, the function:at line 863:
the isprint causes an error during debugging with the isprint function. This is because the compiler does not default the char type to unsigned, as shown in the attached image.
convert isclype.cpp Line: 36 Expression:c>=-1&&c<= 255
The text was updated successfully, but these errors were encountered: