Skip to content

Commit

Permalink
Fix OOB in stores (#2123)
Browse files Browse the repository at this point in the history
  • Loading branch information
AJenbo authored Oct 14, 2020
1 parent e773e76 commit 34e526d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
28 changes: 12 additions & 16 deletions Source/stores.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ItemStruct premiumitem[SMITH_PREMIUM_ITEMS];
BYTE *pSTextBoxCels;
int premiumlevel;
int talker;
STextStruct stext[24];
STextStruct stext[STORE_LINES];
char stextsize;

int stextsmax;
Expand Down Expand Up @@ -90,11 +90,7 @@ void InitStores()
pSTextBoxCels = LoadFileInMem("Data\\TextBox2.CEL", NULL);
pSPentSpn2Cels = LoadFileInMem("Data\\PentSpn2.CEL", NULL);
pSTextSlidCels = LoadFileInMem("Data\\TextSlid.CEL", NULL);
#ifdef HELLFIRE
ClearSText(0, 104);
#else
ClearSText(0, 24);
#endif
ClearSText(0, STORE_LINES);
stextflag = STORE_NONE;
InStoreFlag = 1;
stextsize = FALSE;
Expand Down Expand Up @@ -1535,7 +1531,7 @@ void StartStore(char s)
chrflag = FALSE;
questlog = FALSE;
dropGoldFlag = FALSE;
ClearSText(0, 24);
ClearSText(0, STORE_LINES);
ReleaseStoreBtn();
switch (t) {
case STORE_SMITH:
Expand Down Expand Up @@ -1613,12 +1609,12 @@ void StartStore(char s)
break;
}

for (i = 0; i < 24; i++) {
for (i = 0; i < STORE_LINES; i++) {
if (stext[i]._ssel)
break;
}

stextsel = i == 24 ? -1 : i;
stextsel = i == STORE_LINES ? -1 : i;
stextflag = t;
if (t != STORE_SBUY || storenumh)
break;
Expand Down Expand Up @@ -1658,7 +1654,7 @@ void DrawSText()
}
}

for (i = 0; i < 24; i++) {
for (i = 0; i < STORE_LINES; i++) {
if (stext[i]._sline)
DrawSLine(i);
if (stext[i]._sstr[0])
Expand Down Expand Up @@ -1761,21 +1757,21 @@ void STextUp()
stextsel--;
while (!stext[stextsel]._ssel) {
if (!stextsel)
stextsel = 23;
stextsel = STORE_LINES - 1;
else
stextsel--;
}
return;
}

if (!stextsel)
stextsel = 23;
stextsel = STORE_LINES - 1;
else
stextsel--;

while (!stext[stextsel]._ssel) {
if (!stextsel)
stextsel = 23;
stextsel = STORE_LINES - 1;
else
stextsel--;
}
Expand All @@ -1797,21 +1793,21 @@ void STextDown()

stextsel++;
while (!stext[stextsel]._ssel) {
if (stextsel == 23)
if (stextsel == STORE_LINES - 1)
stextsel = 0;
else
stextsel++;
}
return;
}

if (stextsel == 23)
if (stextsel == STORE_LINES - 1)
stextsel = 0;
else
stextsel++;

while (!stext[stextsel]._ssel) {
if (stextsel == 23)
if (stextsel == STORE_LINES - 1)
stextsel = 0;
else
stextsel++;
Expand Down
2 changes: 1 addition & 1 deletion Source/stores.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ extern ItemStruct premiumitem[SMITH_PREMIUM_ITEMS];
extern BYTE *pSTextBoxCels;
extern int premiumlevel;
extern int talker;
extern STextStruct stext[24];
extern STextStruct stext[STORE_LINES];
extern char stextsize;
extern int stextsmax;
extern int InStoreFlag;
Expand Down
2 changes: 2 additions & 0 deletions defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,14 @@
#define SMITH_PREMIUM_ITEMS 15
#define SMITH_MAX_VALUE 200000
#define SMITH_MAX_PREMIUM_VALUE 200000
#define STORE_LINES 104
#else
#define NUMLEVELS 17
#define SMITH_ITEMS 20
#define SMITH_PREMIUM_ITEMS 6
#define SMITH_MAX_VALUE 140000
#define SMITH_MAX_PREMIUM_VALUE 140000
#define STORE_LINES 24
#endif

// from diablo 2 beta
Expand Down

0 comments on commit 34e526d

Please sign in to comment.