From eaa12f59bddce2801a454a3d91ed1062ad838ca6 Mon Sep 17 00:00:00 2001 From: Kaphotics Date: Thu, 8 Sep 2016 20:29:12 -0700 Subject: [PATCH] Disallow out-of-bounds puff values Closes #246 Might as well use the SAV property "Puffs" when loading instead of only when saving. --- PKHeX/Subforms/Save Editors/Gen6/SAV_Pokepuff.cs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/PKHeX/Subforms/Save Editors/Gen6/SAV_Pokepuff.cs b/PKHeX/Subforms/Save Editors/Gen6/SAV_Pokepuff.cs index 915668503..cfbaef4ee 100644 --- a/PKHeX/Subforms/Save Editors/Gen6/SAV_Pokepuff.cs +++ b/PKHeX/Subforms/Save Editors/Gen6/SAV_Pokepuff.cs @@ -48,11 +48,18 @@ private void Setup() dgv.Columns.Add(dgvIndex); dgv.Columns.Add(dgvPuff); - dgv.Rows.Add(100); - for (int i = 0; i < 100; i++) + var Puffs = SAV.Puffs; + dgv.Rows.Add(Puffs.Length); + for (int i = 0; i < Puffs.Length; i++) { dgv.Rows[i].Cells[0].Value = (i + 1).ToString(); - dgv.Rows[i].Cells[1].Value = pfa[SAV.Data[SAV.Puff + i]]; + int puffval = Puffs[i]; + if (puffval >= pfa.Length) + { + Util.Error($"Invalid Puff Index: {i}", $"Expected < ${pfa.Length}"); + puffval = 0; + } + dgv.Rows[i].Cells[1].Value = pfa[puffval]; } MT_CNT.Text = SAV.PuffCount.ToString(); }