Skip to content

Commit

Permalink
Fix potential index out of bounds error (#446)
Browse files Browse the repository at this point in the history
  • Loading branch information
kleonc committed Jan 30, 2021
1 parent 27852b2 commit 499251f
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/Autoload/OpenSave.gd
Original file line number Diff line number Diff line change
Expand Up @@ -529,19 +529,21 @@ func remove_backup_by_path(project_path : String, backup_path : String) -> void:


func reload_backup_file(project_paths : Array, backup_paths : Array) -> void:
assert(project_paths.size() == backup_paths.size())
# Clear non-existant backups
var deleted_backup_paths := []
var existing_backups_count := 0
var dir := Directory.new()
for backup in backup_paths:
if !dir.file_exists(backup):
if Global.config_cache.has_section_key("backups", backup):
Global.config_cache.erase_section_key("backups", backup)
for i in range(backup_paths.size()):
if dir.file_exists(backup_paths[i]):
project_paths[existing_backups_count] = project_paths[i]
backup_paths[existing_backups_count] = backup_paths[i]
existing_backups_count += 1
else:
if Global.config_cache.has_section_key("backups", backup_paths[i]):
Global.config_cache.erase_section_key("backups", backup_paths[i])
Global.config_cache.save("user://cache.ini")
project_paths.remove(backup_paths.find(backup))
deleted_backup_paths.append(backup)

for deleted in deleted_backup_paths:
backup_paths.erase(deleted)
project_paths.resize(existing_backups_count)
backup_paths.resize(existing_backups_count)

# Load the backup files
for i in range(project_paths.size()):
Expand Down

0 comments on commit 499251f

Please sign in to comment.