You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
MSGPACK_DEFINE() with char arrays silently does the wrong thing #399
Compiling and running it unexpectedly results in an exit failure with "bad cast" exception.
Debugging it I see that what happens is that s is correctly serialized because there is a pack<const char N> specialization. However there is no equivalent specialization for convert(), so convert<char> is used which tries to extract char, as an int, from the object containing a string and fails.
IMO this is a pretty bad bug because everything compiles just fine and even works on the server (serialization) side but then fails during run-time on the client.
#include<msgpack.hpp>
#include<iostream>intmain() {
msgpack::zone z;
msgpack::object obj("ABC", z);
std::cout << obj << std::endl;
char c;
// call reference version
obj.convert(c); // Shouldn't be a compile error, but be a runtime error// call pointer version
obj.convert(&c); // Shouldn't be a compile error, but be a runtime errorchar* p;
// call pointer version for `char` unexpectedly// If calling reference version of `char*`, I would get a compile error as expected.
obj.convert(p); // Expected to be a compile error
}
The reported problem is similar as the line obj.convert(p);. I want to get a compile error on the line but don't get. On the contrary, obj.convert(&c); shouldn't make a compile error. There is no way to distinguish the two.
If I remove the pointer version of convert(), I would get a compile error as expected.
Activity
redboltz commentedon Jan 13, 2016
@vadz, thank you for reporting the issue.
I think that the expected behavior is making compile error on the following line:
I will study how to achieve that.
redboltz commentedon Jan 15, 2016
I analyzed the problem.
msgpack-c has two convert interfaces. One is reference version:
https://github.com/msgpack/msgpack-c/blob/master/include/msgpack/object.hpp#L492
the other is pointer version:
https://github.com/msgpack/msgpack-c/blob/master/include/msgpack/object.hpp#L499
The pointer version is kept for older version compatibility.
Consider the following code:
http://melpon.org/wandbox/permlink/abcohg5yciTP6pfX
The reported problem is similar as the line
obj.convert(p);. I want to get a compile error on the line but don't get. On the contrary,obj.convert(&c);shouldn't make a compile error. There is no way to distinguish the two.If I remove the pointer version of convert(), I would get a compile error as expected.
https://github.com/msgpack/msgpack-c/blob/master/include/msgpack/object.hpp#L499
I think that it's a time to remove the pointer version convert. I'd like to hear @nobu-k's idea.
Fixed msgpack#399
Fixed msgpack#399
Merge pull request #410 from redboltz/fix_399