GUI: fix possible crash in find/replace

issue #2328
This commit is contained in:
tildearrow 2025-01-17 02:58:22 -05:00
parent 6414de2036
commit cfcad1e689

View file

@ -371,7 +371,7 @@ void FurnaceGUI::doReplace() {
switch (queryReplaceEffectPos) { switch (queryReplaceEffectPos) {
case 0: // clear case 0: // clear
for (int j=0; j<e->song.subsong[i.subsong]->pat[i.x].effectCols; j++) { for (int j=0; j<e->song.subsong[i.subsong]->pat[i.x].effectCols && j<8; j++) {
effectOrder[j]=j; effectOrder[j]=j;
} }
break; break;
@ -380,7 +380,7 @@ void FurnaceGUI::doReplace() {
for (int j=0; j<8 && placementIndex<8 && i.effectPos[j]>=0; j++) { for (int j=0; j<8 && placementIndex<8 && i.effectPos[j]>=0; j++) {
effectOrder[placementIndex++]=i.effectPos[j]; effectOrder[placementIndex++]=i.effectPos[j];
} }
for (int j=0; j<e->song.subsong[i.subsong]->pat[i.x].effectCols; j++) { for (int j=0; j<e->song.subsong[i.subsong]->pat[i.x].effectCols && placementIndex<8 && j<8; j++) {
if (p->data[i.y][4+j*2]!=-1 || p->data[i.y][5+j*2]!=-1) { if (p->data[i.y][4+j*2]!=-1 || p->data[i.y][5+j*2]!=-1) {
effectOrder[placementIndex++]=j; effectOrder[placementIndex++]=j;
} }
@ -392,7 +392,7 @@ void FurnaceGUI::doReplace() {
for (int j=0; j<8 && placementIndex<8 && i.effectPos[j]>=0; j++) { for (int j=0; j<8 && placementIndex<8 && i.effectPos[j]>=0; j++) {
effectOrder[placementIndex++]=i.effectPos[j]; effectOrder[placementIndex++]=i.effectPos[j];
} }
for (int j=0; j<e->song.subsong[i.subsong]->pat[i.x].effectCols; j++) { for (int j=0; j<e->song.subsong[i.subsong]->pat[i.x].effectCols && placementIndex<8 && j<8; j++) {
if (p->data[i.y][4+j*2]!=-1 || p->data[i.y][5+j*2]!=-1) { if (p->data[i.y][4+j*2]!=-1 || p->data[i.y][5+j*2]!=-1) {
effectOrder[placementIndex++]=j; effectOrder[placementIndex++]=j;
} }
@ -406,7 +406,7 @@ void FurnaceGUI::doReplace() {
} }
case 3: { // insert in free spaces case 3: { // insert in free spaces
int placementIndex=0; int placementIndex=0;
for (int j=0; j<e->song.subsong[i.subsong]->pat[i.x].effectCols; j++) { for (int j=0; j<e->song.subsong[i.subsong]->pat[i.x].effectCols && j<8; j++) {
if (p->data[i.y][4+j*2]==-1 && p->data[i.y][5+j*2]==-1) { if (p->data[i.y][4+j*2]==-1 && p->data[i.y][5+j*2]==-1) {
effectOrder[placementIndex++]=j; effectOrder[placementIndex++]=j;
} }
@ -415,7 +415,7 @@ void FurnaceGUI::doReplace() {
} }
} }
for (int j=0; j<queryReplaceEffectCount; j++) { for (int j=0; j<queryReplaceEffectCount && j<8; j++) {
signed char pos=effectOrder[j]; signed char pos=effectOrder[j];
if (pos==-1) continue; if (pos==-1) continue;
if (queryReplaceEffectDo[j]) { if (queryReplaceEffectDo[j]) {