Skip to content

Commit

Permalink
fixed anycast usage without checking
Browse files Browse the repository at this point in the history
  • Loading branch information
sgiurgiu committed Mar 8, 2022
1 parent f0f1bb5 commit 2201930
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 20 deletions.
9 changes: 5 additions & 4 deletions src/commentswindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,6 @@ void CommentsWindow::voteParentPost(Voted vote)
{
auto self = weak.lock();
if(!self) return;
Voted voted = std::any_cast<Voted>(response.userData);

if(ec)
{
Expand All @@ -717,8 +716,9 @@ void CommentsWindow::voteParentPost(Voted vote)
{
boost::asio::post(self->uiExecutor,std::bind(&CommentsWindow::setErrorMessage,self,std::move(response.body)));
}
else
else if(response.userData.has_value() && response.userData.type() == typeid(Voted))
{
Voted voted = std::any_cast<Voted>(response.userData);
boost::asio::post(self->uiExecutor,std::bind(&CommentsWindow::updatePostVote,self, voted));
}
});
Expand All @@ -743,7 +743,7 @@ void CommentsWindow::voteComment(DisplayComment* c,Voted vote)
{
auto self = weak.lock();
if (!self) return;
auto p = std::any_cast<std::pair<std::string, Voted>>(response.userData);

if (ec)
{
boost::asio::post(self->uiExecutor, std::bind(&CommentsWindow::setErrorMessage, self, ec.message()));
Expand All @@ -752,8 +752,9 @@ void CommentsWindow::voteComment(DisplayComment* c,Voted vote)
{
boost::asio::post(self->uiExecutor, std::bind(&CommentsWindow::setErrorMessage, self, std::move(response.body)));
}
else
else if(response.userData.has_value() && response.userData.type() == typeid(std::pair<std::string, Voted>))
{
auto p = std::any_cast<std::pair<std::string, Voted>>(response.userData);
boost::asio::post(self->uiExecutor, std::bind(&CommentsWindow::updateCommentVote, self, std::move(p.first), p.second));
}
});
Expand Down
7 changes: 6 additions & 1 deletion src/globalresourcescache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,14 @@ RedditClientProducer::RedditResourceClientConnection
resourceConnection->connectionCompleteHandler(
[uiExecutor](const boost::system::error_code& ec,
resource_response response){
std::string id = std::any_cast<std::string>(response.userData);
std::string id = "";
if(response.userData.has_value() && response.userData.type() == typeid(std::string))
{
id = std::any_cast<std::string>(response.userData);
}
if(!ec)
{

int width, height, channels;
auto data = Utils::decodeImageData(response.data.data(),response.data.size(),&width,&height,&channels);

Expand Down
15 changes: 10 additions & 5 deletions src/subredditwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,11 @@ void SubredditWindow::setupConnections()
{
auto self = weak.lock();
if(!self) return;
std::string postName = std::any_cast<std::string>(response.userData);

std::string postName = "";
if(response.userData.has_value() && response.userData.type() == typeid(std::string))
{
postName = std::any_cast<std::string>(response.userData);
}
if(ec)
{
auto message = "Cannot load thumbnail:" + ec.message();
Expand All @@ -218,8 +221,9 @@ void SubredditWindow::setupConnections()
auto message = "Cannot load thumbnail:" + response.body;
boost::asio::post(self->uiExecutor,std::bind(&SubredditWindow::setPostErrorMessage,self,std::move(postName),std::move(message)));
}
else if(response.status == 200)
else if(response.status == 200 )
{

int width, height, channels;
auto data = Utils::decodeImageData(response.data.data(),response.data.size(),&width,&height,&channels);
boost::asio::post(self->uiExecutor,std::bind(&SubredditWindow::setPostThumbnail,self,
Expand All @@ -236,7 +240,7 @@ void SubredditWindow::setupConnections()
{
auto self = weak.lock();
if (!self) return;
auto p = std::any_cast<std::pair<std::string, Voted>>(response.userData);


if (ec)
{
Expand All @@ -246,8 +250,9 @@ void SubredditWindow::setupConnections()
{
boost::asio::post(self->uiExecutor, std::bind(&SubredditWindow::setErrorMessage, self, std::move(response.body)));
}
else
else if(response.userData.has_value() && response.userData.type() == typeid(std::pair<std::string, Voted>))
{
auto p = std::any_cast<std::pair<std::string, Voted>>(response.userData);
boost::asio::post(self->uiExecutor, std::bind(&SubredditWindow::updatePostVote, self, std::move(p.first), p.second));
}
});
Expand Down
5 changes: 3 additions & 2 deletions src/twitterrenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,10 @@ void TwitterRenderer::loadTweetImages()
resource_response response){
auto self = weak.lock();
if(!self) return;
size_t imageIndex = std::any_cast<size_t>(response.userData);
if(!ec && response.status == 200)

if(!ec && response.status == 200 && response.userData.has_value() && response.userData.type() == typeid(size_t))
{
size_t imageIndex = std::any_cast<size_t>(response.userData);
int width, height, channels;
auto data = Utils::decodeImageData(response.data.data(),response.data.size(),&width,&height,&channels);
boost::asio::post(self->uiExecutor,std::bind(&TwitterRenderer::addTweetImage,self,
Expand Down
19 changes: 11 additions & 8 deletions src/userinformationwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,13 @@ void UserInformationWindow::loadMessages()
{
for(const auto& msgResponse : things)
{
boost::asio::post(self->uiExecutor,
std::bind(&UserInformationWindow::loadMessageResponse,
self,std::move(msgResponse),
std::any_cast<ParentMessageResponseData>(response.userData)));
if(response.userData.has_value() && response.userData.type() == typeid(ParentMessageResponseData))
{
boost::asio::post(self->uiExecutor,
std::bind(&UserInformationWindow::loadMessageResponse,
self,std::move(msgResponse),
std::any_cast<ParentMessageResponseData>(response.userData)));
}
}
}
}
Expand Down Expand Up @@ -88,7 +91,7 @@ void UserInformationWindow::loadMessages()
boost::asio::post(self->uiExecutor,
std::bind(&UserInformationWindow::setErrorMessage,self,response.body));
}
else
else if(response.userData.has_value() && response.userData.type() == typeid(MarkMessagesType))
{

boost::asio::post(self->uiExecutor,
Expand Down Expand Up @@ -150,7 +153,7 @@ void UserInformationWindow::loadMessages(const std::string& kind)
{
boost::asio::post(self->uiExecutor,std::bind(&UserInformationWindow::setErrorMessage,self,std::move(response.body)));
}
else
else if(response.userData.has_value() && response.userData.type() == typeid(std::string))
{
boost::asio::post(self->uiExecutor,std::bind(&UserInformationWindow::loadListingsFromConnection,
self,std::move(response.data),
Expand Down Expand Up @@ -262,7 +265,6 @@ void UserInformationWindow::voteComment(const std::string& kind, DisplayMessage&
{
auto self = weak.lock();
if (!self) return;
std::tuple<std::string, std::string, Voted> voted = std::any_cast<std::tuple<std::string, std::string, Voted>>(response.userData);

if (ec)
{
Expand All @@ -272,8 +274,9 @@ void UserInformationWindow::voteComment(const std::string& kind, DisplayMessage&
{
boost::asio::post(self->uiExecutor, std::bind(&UserInformationWindow::setErrorMessage, self, std::move(response.body)));
}
else
else if(response.userData.has_value() && response.userData.type() == typeid(std::tuple<std::string, std::string, Voted>))
{
auto voted = std::any_cast<std::tuple<std::string, std::string, Voted>>(response.userData);
boost::asio::post(self->uiExecutor, std::bind(&UserInformationWindow::updateCommentVote, self,
std::get<0>(voted), std::get<1>(voted),std::get<2>(voted)));
}
Expand Down

0 comments on commit 2201930

Please sign in to comment.