mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-21 23:40:26 -04:00
added security check to avoid crash in counting comments, when a comment refers to no post (due to sync limits)
This commit is contained in:
parent
24735c2235
commit
c32f90f84d
1 changed files with 14 additions and 1 deletions
|
@ -87,7 +87,20 @@ void updateCommentCounts( std::vector<RsGxsChannelPost>& posts, std::vector<RsGx
|
|||
// now look into comments and increase the count
|
||||
|
||||
for(uint32_t i=0;i<comments.size();++i)
|
||||
++posts[post_indices[comments[i].mMeta.mThreadId]].mCommentCount;
|
||||
{
|
||||
auto it = post_indices.find(comments[i].mMeta.mThreadId);
|
||||
|
||||
// This happens when because of sync periods, we receive
|
||||
// the comments for a post, but not the post itself.
|
||||
// In this case, the post the comment refers to is just not here.
|
||||
// it->second>=posts.size() is impossible by construction, since post_indices
|
||||
// is previously filled using posts ids.
|
||||
|
||||
if(it == post_indices.end())
|
||||
continue;
|
||||
|
||||
++posts[it->second].mCommentCount;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue