Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit20c1239

Browse files
committed
GameStateLoad: Add bounds check for game slot when deleting save
Possible fix for#1907
1 parentd68dd01 commit20c1239

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

‎src/GameStateLoad.cpp‎

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -496,28 +496,51 @@ void GameStateLoad::logic() {
496496
confirm->logic();
497497
if (confirm->clicked_confirm) {
498498
if (confirm->action_list->getSelected() == DELETE_CONFIRM_OPTION_YES) {
499-
Utils::removeSaveDir(game_slots[selected_slot]->id);
499+
if (selected_slot != -1 &&static_cast<size_t>(selected_slot) < game_slots.size()) {
500+
Utils::removeSaveDir(game_slots[selected_slot]->id);
501+
502+
delete game_slots[selected_slot];
503+
game_slots[selected_slot] =NULL;
504+
game_slots.erase(game_slots.begin()+selected_slot);
505+
506+
visible_slots = (game_slot_max >static_cast<int>(game_slots.size()) ?static_cast<int>(game_slots.size()) : game_slot_max);
507+
if (!game_slots.empty()) {
508+
if (selected_slot >0)
509+
setSelectedSlot(selected_slot -1);
510+
else
511+
setSelectedSlot(0);
512+
}
513+
else {
514+
setSelectedSlot(-1);
515+
}
500516

501-
delete game_slots[selected_slot];
502-
game_slots[selected_slot] =NULL;
503-
game_slots.erase(game_slots.begin()+selected_slot);
517+
while (scroll_offset + visible_slots >static_cast<int>(game_slots.size())) {
518+
scroll_offset--;
519+
}
520+
521+
scrollToSelected();
522+
updateButtons();
523+
524+
refreshSavePaths();
525+
settings->prev_save_slot = -1;
526+
527+
}
528+
tablist.defocus();
529+
}
530+
else {
531+
// We shouldn't end up here!
532+
// But if we do, log an error and try to reset the UI
533+
534+
Utils::logError("GameStateLoad: Can't delete save. Index at %d is out-of-bounds.", selected_slot);
504535

505-
visible_slots = (game_slot_max >static_cast<int>(game_slots.size()) ?static_cast<int>(game_slots.size()) : game_slot_max);
506536
if (!game_slots.empty())
507537
setSelectedSlot(0);
508538
else
509539
setSelectedSlot(-1);
510540

511-
while (scroll_offset + visible_slots >static_cast<int>(game_slots.size())) {
512-
scroll_offset--;
513-
}
514-
515541
scrollToSelected();
516542
updateButtons();
517-
518-
refreshSavePaths();
519543
settings->prev_save_slot = -1;
520-
521544
tablist.defocus();
522545
}
523546

‎src/Version.cpp‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ FLARE. If not, see http://www.gnu.org/licenses/
3030

3131
#include<SDL.h>
3232

33-
VersionVersionInfo::ENGINE(1,14,201);
33+
VersionVersionInfo::ENGINE(1,14,202);
3434
VersionVersionInfo::MIN(0,0,0);
3535
VersionVersionInfo::MAX(USHRT_MAX, USHRT_MAX, USHRT_MAX);
3636

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp