Added null checks for iterators

This commit is contained in:
Andrea Cavalli 2020-05-18 16:53:07 +02:00
parent 1bd26bf882
commit 3034ec9bf5
14 changed files with 23 additions and 23 deletions

View File

@ -147,7 +147,7 @@ void AnimationsManager::tear_down() {
int32 AnimationsManager::get_animation_duration(FileId file_id) const {
auto it = animations_.find(file_id);
if (it == animations_.end()) {
if (it == animations_.end() || it->second == nullptr) {
return 0;
}
return it->second->duration;
@ -224,7 +224,7 @@ FileId AnimationsManager::on_get_animation(unique_ptr<Animation> new_animation,
const AnimationsManager::Animation *AnimationsManager::get_animation(FileId file_id) const {
auto animation = animations_.find(file_id);
if (animation == animations_.end()) {
if (animation == animations_.end() || animation->second == nullptr) {
return make_unique<Animation>().get();
}
@ -274,7 +274,7 @@ bool AnimationsManager::merge_animations(FileId new_id, FileId old_id, bool can_
}
auto new_it = animations_.find(new_id);
if (new_it == animations_.end()) {
if (new_it == animations_.end() || new_it->second == nullptr) {
auto &old = animations_[old_id];
old->is_changed = true;
if (!can_delete_old) {

View File

@ -20,7 +20,7 @@ namespace td {
template <class StorerT>
void AnimationsManager::store_animation(FileId file_id, StorerT &storer) const {
auto it = animations_.find(file_id);
if (it == animations_.end()) {
if (it == animations_.end() || it->second == nullptr) {
return;
}
const Animation *animation = it->second.get();

View File

@ -24,7 +24,7 @@ AudiosManager::AudiosManager(Td *td) : td_(td) {
int32 AudiosManager::get_audio_duration(FileId file_id) const {
auto it = audios_.find(file_id);
if (it == audios_.end()) {
if (it == audios_.end() || it->second == nullptr) {
return 0;
}
return it->second->duration;
@ -93,7 +93,7 @@ FileId AudiosManager::on_get_audio(unique_ptr<Audio> new_audio, bool replace) {
const AudiosManager::Audio *AudiosManager::get_audio(FileId file_id) const {
auto audio = audios_.find(file_id);
if (audio == audios_.end()) {
if (audio == audios_.end() || audio->second == nullptr) {
return make_unique<Audio>().get();
}
@ -126,7 +126,7 @@ bool AudiosManager::merge_audios(FileId new_id, FileId old_id, bool can_delete_o
}
auto new_it = audios_.find(new_id);
if (new_it == audios_.end()) {
if (new_it == audios_.end() || new_it->second == nullptr) {
auto &old = audios_[old_id];
old->is_changed = true;
if (!can_delete_old) {

View File

@ -20,7 +20,7 @@ namespace td {
template <class StorerT>
void AudiosManager::store_audio(FileId file_id, StorerT &storer) const {
auto it = audios_.find(file_id);
if (it == audios_.end()) {
if (it == audios_.end() || it->second == nullptr) {
return;
}
const Audio *audio = it->second.get();

View File

@ -629,7 +629,7 @@ bool DocumentsManager::merge_documents(FileId new_id, FileId old_id, bool can_de
}
auto new_it = documents_.find(new_id);
if (new_it == documents_.end()) {
if (new_it == documents_.end() || new_it->second == nullptr) {
auto &old = documents_[old_id];
old->is_changed = true;
if (!can_delete_old) {

View File

@ -23,7 +23,7 @@ template <class StorerT>
void DocumentsManager::store_document(FileId file_id, StorerT &storer) const {
//LOG(DEBUG) << "Store document " << file_id;
auto it = documents_.find(file_id);
if (it == documents_.end()) {
if (it == documents_.end() || it->second == nullptr) {
return;
}
const GeneralDocument *document = it->second.get();

View File

@ -1328,7 +1328,7 @@ tl_object_ptr<td_api::sticker> StickersManager::get_sticker_object(FileId file_i
auto it = stickers_.find(file_id);
if (it == stickers_.end()) {
if (it == stickers_.end() || it->second == nullptr) {
return nullptr;
}
@ -1606,7 +1606,7 @@ std::pair<int64, FileId> StickersManager::on_get_sticker_document(
StickersManager::Sticker *StickersManager::get_sticker(FileId file_id) {
auto sticker = stickers_.find(file_id);
if (sticker == stickers_.end()) {
if (sticker == stickers_.end() || sticker->second == nullptr) {
return make_unique<Sticker>().get();
}
@ -1768,7 +1768,7 @@ bool StickersManager::merge_stickers(FileId new_id, FileId old_id, bool can_dele
}
auto new_it = stickers_.find(new_id);
if (new_it == stickers_.end()) {
if (new_it == stickers_.end() || new_it->second == nullptr) {
auto &old = stickers_[old_id];
old->is_changed = true;
if (!can_delete_old) {

View File

@ -23,7 +23,7 @@ namespace td {
template <class StorerT>
void StickersManager::store_sticker(FileId file_id, bool in_sticker_set, StorerT &storer) const {
auto it = stickers_.find(file_id);
if (it == stickers_.end()) {
if (it == stickers_.end() || it->second == nullptr) {
return;
}
const Sticker *sticker = it->second.get();

View File

@ -25,7 +25,7 @@ VideoNotesManager::VideoNotesManager(Td *td) : td_(td) {
int32 VideoNotesManager::get_video_note_duration(FileId file_id) const {
auto it = video_notes_.find(file_id);
if (it == video_notes_.end()) {
if (it == video_notes_.end() || it->second == nullptr) {
return 0;
}
return it->second->duration;
@ -136,7 +136,7 @@ bool VideoNotesManager::merge_video_notes(FileId new_id, FileId old_id, bool can
}
auto new_it = video_notes_.find(new_id);
if (new_it == video_notes_.end()) {
if (new_it == video_notes_.end() || new_it->second == nullptr) {
auto &old = video_notes_[old_id];
old->is_changed = true;
if (!can_delete_old) {

View File

@ -20,7 +20,7 @@ namespace td {
template <class StorerT>
void VideoNotesManager::store_video_note(FileId file_id, StorerT &storer) const {
auto it = video_notes_.find(file_id);
if (it == video_notes_.end()) {
if (it == video_notes_.end() || it->second == nullptr) {
return;
}
const VideoNote *video_note = it->second.get();

View File

@ -24,7 +24,7 @@ VideosManager::VideosManager(Td *td) : td_(td) {
int32 VideosManager::get_video_duration(FileId file_id) const {
auto it = videos_.find(file_id);
if (it == videos_.end()) {
if (it == videos_.end() || it->second == nullptr) {
return 0;
}
return it->second->duration;
@ -153,7 +153,7 @@ bool VideosManager::merge_videos(FileId new_id, FileId old_id, bool can_delete_o
}
auto new_it = videos_.find(new_id);
if (new_it == videos_.end()) {
if (new_it == videos_.end() || new_it->second == nullptr) {
auto &old = videos_[old_id];
old->is_changed = true;
if (!can_delete_old) {

View File

@ -20,7 +20,7 @@ namespace td {
template <class StorerT>
void VideosManager::store_video(FileId file_id, StorerT &storer) const {
auto it = videos_.find(file_id);
if (it == videos_.end()) {
if (it == videos_.end() || it->second == nullptr) {
return;
}
const Video *video = it->second.get();

View File

@ -25,7 +25,7 @@ VoiceNotesManager::VoiceNotesManager(Td *td) : td_(td) {
int32 VoiceNotesManager::get_voice_note_duration(FileId file_id) const {
auto it = voice_notes_.find(file_id);
if (it == voice_notes_.end()) {
if (it == voice_notes_.end() || it->second == nullptr) {
return 0;
}
return it->second->duration;
@ -104,7 +104,7 @@ bool VoiceNotesManager::merge_voice_notes(FileId new_id, FileId old_id, bool can
}
auto new_it = voice_notes_.find(new_id);
if (new_it == voice_notes_.end()) {
if (new_it == voice_notes_.end() || new_it->second == nullptr) {
auto &old = voice_notes_[old_id];
old->is_changed = true;
if (!can_delete_old) {

View File

@ -18,7 +18,7 @@ namespace td {
template <class StorerT>
void VoiceNotesManager::store_voice_note(FileId file_id, StorerT &storer) const {
auto it = voice_notes_.find(file_id);
if (it == voice_notes_.end()) {
if (it == voice_notes_.end() || it->second == nullptr) {
return;
}
const VoiceNote *voice_note = it->second.get();