[
https://issues.apache.org/jira/browse/THRIFT-5272?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Jens Geyer resolved THRIFT-5272.
--------------------------------
Fix Version/s: 0.21.0
Assignee: Jens Geyer
Resolution: Fixed
Thanks [Sven Roederer|[SvenRoederer (Sven Roederer)
(github.com)|https://github.com/SvenRoederer]]!
> 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
> Assignee: Jens Geyer
> Priority: Minor
> Fix For: 0.21.0
>
> Attachments: TToString.h.patch
>
> Original Estimate: 0.5h
> Time Spent: 1h 20m
> Remaining Estimate: 0h
>
> 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.20.10#820010)