You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@thrift.apache.org by "Jeroen van Oosten (Jira)" <ji...@apache.org> on 2020/09/01 20:54:00 UTC
[jira] [Created] (THRIFT-5272) printTo does not properly handle i8
datatypes
Jeroen van Oosten created THRIFT-5272:
-----------------------------------------
Summary: printTo does not properly handle i8 datatypes
Key: THRIFT-5272
URL: https://issues.apache.org/jira/browse/THRIFT-5272
Project: Thrift
Issue Type: Bug
Components: C++ - Library
Affects Versions: 0.13.0
Environment: MSVC 2019 *and* Linux gcc 10.1.0
Reporter: Jeroen van Oosten
Attachments: TToString.h.patch
We have defined a datastructure with an i8 type in it, like so:
{code:java}
struct Meta
{
1: i8 channel,
2: i32 sequence
}
{code}
For debugging / logging purposes we are printing the information with Meta:: printTo, however the otuput is a bit odd. For example, we see this when the channel number is 0:
Meta(channel= , sequence=5)
I would expect to see "channel=0", just like all other integer types.
Further investigation shows that at the empty space after "channel=" there is in fact a null byte. And if I change 'channel' to 65, I get a "channel=A". Clearly the ASCII value is being dumped, not the integer value.
I have traced down the problem to TToString.h, line 34. The template function "to_string" there in combination with ostringstream does something weird when the input is a int8_t, which corresponds to a 'char' of course.
The fix is to add a specialization of that template for int8_t:
{code:java}
inline std::string my_string(const int8_t& t) {
std::ostringstream o;
o << static_cast<int>(t);
return o.str();
}
{code}
For your information: std::to_string *does* produce the expected result.
--
This message was sent by Atlassian Jira
(v8.3.4#803005)