Skip to content

Commit

Permalink
fix corruption again
Browse files Browse the repository at this point in the history
  • Loading branch information
marty1885 committed Oct 4, 2023
1 parent b1b824a commit 1de8193
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions gnunetpp/gnunetpp-messenger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,24 +184,26 @@ GNUNET_HashCode Room::getId() const
static std::pair<GNUNET_MESSENGER_Message, std::any> message_convert(const UserSendibleMessage &value)
{
GNUNET_MESSENGER_Message msg;
std::string dup;
if(value.index() == std::variant_npos)
return {msg, std::any()};

std::shared_ptr<std::string> holder = nullptr;

switch(value.index()) {
case 0:
msg.header.kind = GNUNET_MESSENGER_KIND_TEXT;
// HACK: We need to keep the string alive until the message is sent
dup = std::get<0>(value).text;
msg.body.text.text = (char*)dup.c_str();
holder = std::make_shared<std::string>(std::get<0>(value).text);
msg.body.text.text = (char*)holder->c_str();
break;
case 1:
// Don't know how to send files yet
throw std::runtime_error("Sending files is not supported yet");
break;
case 2:
msg.header.kind = GNUNET_MESSENGER_KIND_NAME;
dup = std::get<2>(value).name;
msg.body.name.name = (char*)dup.c_str();
holder = std::make_shared<std::string>(std::get<2>(value).name);
msg.body.name.name = (char*)holder->c_str();
break;
case 3:
msg.header.kind = GNUNET_MESSENGER_KIND_INVITE;
Expand All @@ -212,7 +214,9 @@ static std::pair<GNUNET_MESSENGER_Message, std::any> message_convert(const UserS
// Should never happen
throw std::runtime_error("Unknown message type");
}
return {msg, std::move(dup)};

std::any res = std::move(holder);
return {msg, res};
}

void Room::sendMessage(const std::string &value)
Expand Down

0 comments on commit 1de8193

Please sign in to comment.