@@ -134,9 +134,12 @@ RspData RspConnector::DecodeRLE(const RspData& data)
134134std::unordered_map<std::string, std::uint64_t > RspConnector::PacketToUnorderedMap (const RspData& data)
135135{
136136 std::unordered_map<std::string, std::uint64_t > packet_map{};
137- packet_map[" signal" ] = std::stoull (data.AsString ().substr (1 , 2 ), nullptr , 16 );
138-
139137 const auto data_string = data.AsString ();
138+ if (data_string.length () < 3 )
139+ return packet_map;
140+
141+ packet_map[" signal" ] = ParseInt (data_string.substr (1 , 2 ));
142+
140143 const auto after_signal = data_string.substr (3 );
141144
142145 for ( const auto & entries : RspConnector::Split (after_signal, " ;" )) {
@@ -156,17 +159,21 @@ std::unordered_map<std::string, std::uint64_t> RspConnector::PacketToUnorderedMa
156159 value = value.substr (0 , 16 );
157160
158161 if (key == " thread" ) {
159- if (value[0 ] == ' p' && value.find (' .' ) != std::string::npos) {
160- auto core_id_and_thread_id = RspConnector::Split (value.substr (1 ), " ." );
161- packet_map[" thread" ] = std::stoull (core_id_and_thread_id[1 ], nullptr , 16 );
162+ if (!value.empty () && value[0 ] == ' p' && value.find (' .' ) != std::string::npos) {
163+ // Split takes a regex, so the separator has to be escaped -- an unescaped
164+ // "." matches every character and yields only empty tokens, which meant
165+ // multiprocess thread ids ("pPID.TID") never parsed.
166+ auto core_id_and_thread_id = RspConnector::Split (value.substr (1 ), " \\ ." );
167+ if (core_id_and_thread_id.size () >= 2 )
168+ packet_map[" thread" ] = ParseInt (core_id_and_thread_id[1 ]);
162169 } else {
163- packet_map[" thread" ] = std::stoull (value, nullptr , 16 );
170+ packet_map[" thread" ] = ParseInt (value);
164171 }
165172 } else if (std::regex_search (key, std::regex (" ^[0-9a-fA-F]+$" ))) {
166- packet_map[fmt::format (" r{}" , std::stoi (key, nullptr , 16 ))] =
167- static_cast <std::int64_t >( RspConnector::SwapEndianness (std::stoull (value, nullptr , 16 )));
173+ packet_map[fmt::format (" r{}" , ParseInt< int > (key))] =
174+ static_cast <std::int64_t >( RspConnector::SwapEndianness (ParseInt (value)));
168175 } else {
169- packet_map[key] = std::stoull (value, nullptr , 16 );
176+ packet_map[key] = ParseInt (value);
170177 }
171178 }
172179 else
@@ -245,8 +252,8 @@ void RspConnector::NegotiateCapabilities(const std::vector <std::string>& capabi
245252 {
246253 if ( reply_token.find (" PacketSize=" ) != std::string::npos )
247254 {
248- if (auto packet_tokens = RspConnector::Split (reply_token, " =" ); ! packet_tokens.empty () )
249- this ->m_maxPacketLength = std::stoi (packet_tokens[1 ], nullptr , 16 );
255+ if (auto packet_tokens = RspConnector::Split (reply_token, " =" ); packet_tokens.size () >= 2 )
256+ this ->m_maxPacketLength = ParseInt< int > (packet_tokens[1 ], 16 , this -> m_maxPacketLength );
250257 continue ;
251258 }
252259
@@ -454,11 +461,13 @@ int32_t RspConnector::HostFileIO(const RspData& data, RspData& output, int32_t&
454461 if (resultErrno.find (' ,' ) != std::string::npos) {
455462 const auto split = RspConnector::Split (resultErrno, " ," );
456463 if ((split.size () >= 2 ) && (split[1 ] != " " ))
457- error = std::stol (split[1 ]. c_str (), nullptr , 16 );
464+ error = ParseInt< int32_t > (split[1 ]);
458465
459- return std::stol (split[0 ].c_str (), nullptr , 16 );
466+ if (split.empty ())
467+ return -1 ;
468+ return ParseInt<int32_t >(split[0 ], 16 , -1 );
460469 }
461- return std::stol (resultErrno. c_str (), nullptr , 16 );
470+ return ParseInt< int32_t > (resultErrno, 16 , - 1 );
462471}
463472
464473
0 commit comments