Skip to content

Commit dbe60e3

Browse files
committed
More gracefully checking that parameter is within bounds
1 parent d903761 commit dbe60e3

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

libs/s25main/postSystem/PostBox.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ const PostMsg* PostBox::GetMsg(unsigned idx) const
6565

6666
const PostMsg* PostBox::GetCurrentMsg() const
6767
{
68-
unsigned idx = currMsgIdx >= 0 && currMsgIdx < (int) numMessages ? currMsgIdx : numMessages - 1;
68+
if(numMessages == 0 || currMsgIdx > static_cast<int>(numMessages) - 1)
69+
return nullptr;
70+
unsigned idx = currMsgIdx >= 0 ? currMsgIdx : numMessages - 1;
6971
return GetMsg(idx);
7072
}
7173

0 commit comments

Comments
 (0)