Entering non-existant RoomID in Exits dialog causes segfault
Posted: Sat Mar 16, 2013 11:13 pm
This is using the latest (2.1) git repository code, as far as I can see the code in the dlgRoomExits::save() function in dlgRoomExits.cpp only checks that the text entered for the room number for each exit is non-zero in length before turning it into an integer to use as the RoomID that the exit goes to. I do not see it checking that the entered value actually exists and I think this is causing me getting a terminal segmentation fault as soon as anything touches the map after the exits dialogue box closes.
Would it be a fix to change the code for each exit in that function from:toWhere {exit number edit box on exit dialogue} is the QLineEdit boxes called "n", "ne", .."out" on the dialogue box, and {exit} is "north", "northeast", .."out" the exits for the Room under consideration.
I would point out that this type of situation is most likely to occur from a typo when entering in an Exit number, resulting say in a repeated digit taking the resulting value outside of the range of existing rooms so it is not a totally unlikely event to happen and the consequences are significant enough, I feel, to require attention.
Would it be a fix to change the code for each exit in that function from:
Code: Select all
if( {exit number edit box on exit dialogue}->text().size() > 0 )
mpHost->mpMap->rooms[mRoomID]->{exit} = {exit number edit box on exit dialogue}->text().toInt();
else
mpHost->mpMap->rooms[mRoomID]->{exit} = -1;
Code: Select all
if( {exit number edit box on exit dialogue}->text().size() > 0 )
{
if( mpHost->mpMap->rooms.contains( {exit number edit box on exit dialogue}->text().toInt() ) )
mpHost->mpMap->rooms[mRoomID]->{exit} = {exit number edit box on exit dialogue}->text().toInt();
else
mpHost->mpMap->rooms[mRoomID]->{exit} = -1;
}
else
mpHost->mpMap->rooms[mRoomID]->{exit} = -1;
I would point out that this type of situation is most likely to occur from a typo when entering in an Exit number, resulting say in a repeated digit taking the resulting value outside of the range of existing rooms so it is not a totally unlikely event to happen and the consequences are significant enough, I feel, to require attention.