Skip to content

Commit cb3a17a

Browse files
committed
fix FRED and QtFRED handling of waypoint names
First, fix a crash reported in Discord: prevent FRED or QtFRED from giving a waypoint list a name that is too long. Also fix the updating of references, including for the constituent points, if a waypoint list is renamed.
1 parent 2ceb523 commit cb3a17a

File tree

3 files changed

+33
-12
lines changed

3 files changed

+33
-12
lines changed

code/object/waypoint.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,14 @@ SCP_vector<waypoint> &waypoint_list::get_waypoints()
127127

128128
void waypoint_list::set_name(const char *name)
129129
{
130-
Assert(name != NULL);
131-
strcpy_s(this->m_name, name);
130+
Assertion(name != nullptr, "Waypoint name cannot be null!");
131+
132+
auto len = strlen(name);
133+
if (len >= NAME_LENGTH)
134+
len = NAME_LENGTH - 5; // leave room for a colon, three digits, and a null terminator for points that belong to this list
135+
136+
strncpy(this->m_name, name, len);
137+
this->m_name[len] = '\0';
132138
}
133139

134140
//********************FUNCTIONS********************

fred2/waypointpathdlg.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,22 @@ int waypoint_path_dlg::update_data(int redraw)
265265

266266

267267
strcpy_s(old_name, cur_waypoint_list->get_name());
268-
str = (char *) (LPCTSTR) m_name;
269-
cur_waypoint_list->set_name(str);
268+
cur_waypoint_list->set_name((LPCTSTR) m_name);
269+
str = cur_waypoint_list->get_name();
270270
if (strcmp(old_name, str)) {
271271
set_modified(TRUE);
272272
update_sexp_references(old_name, str);
273-
ai_update_goal_references(sexp_ref_type::WAYPOINT, old_name, str);
274-
update_texture_replacements(old_name, str);
273+
ai_update_goal_references(sexp_ref_type::WAYPOINT_PATH, old_name, str);
274+
275+
for (auto &wpt: cur_waypoint_list->get_waypoints()) {
276+
char old_buf[NAME_LENGTH + 8];
277+
char new_buf[NAME_LENGTH + 8];
278+
sprintf(old_buf, "%s:%d", old_name, wpt.get_index() + 1);
279+
sprintf(new_buf, "%s:%d", str, wpt.get_index() + 1);
280+
update_sexp_references(old_buf, new_buf);
281+
ai_update_goal_references(sexp_ref_type::WAYPOINT, old_buf, new_buf);
282+
}
275283
}
276-
277284
}
278285

279286
if (redraw)

qtfred/src/mission/dialogs/WaypointEditorDialogModel.cpp

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,23 @@ bool WaypointEditorDialogModel::apply()
2424
// apply name
2525
char old_name[255];
2626
strcpy_s(old_name, _editor->cur_waypoint_list->get_name());
27-
const char* str = _currentName.c_str();
28-
_editor->cur_waypoint_list->set_name(str);
27+
_editor->cur_waypoint_list->set_name(_currentName.c_str());
28+
auto str = _editor->cur_waypoint_list->get_name();
2929
if (strcmp(old_name, str) != 0) {
30+
_editor->missionChanged();
3031
update_sexp_references(old_name, str);
31-
_editor->ai_update_goal_references(sexp_ref_type::WAYPOINT, old_name, str);
32-
_editor->update_texture_replacements(old_name, str); // ?? Uh really? Check that FRED does this also
32+
_editor->ai_update_goal_references(sexp_ref_type::WAYPOINT_PATH, old_name, str);
33+
34+
for (auto &wpt : _editor->cur_waypoint_list->get_waypoints()) {
35+
char old_buf[NAME_LENGTH + 8];
36+
char new_buf[NAME_LENGTH + 8];
37+
sprintf(old_buf, "%s:%d", old_name, wpt.get_index() + 1);
38+
sprintf(new_buf, "%s:%d", str, wpt.get_index() + 1);
39+
update_sexp_references(old_buf, new_buf);
40+
_editor->ai_update_goal_references(sexp_ref_type::WAYPOINT, old_buf, new_buf);
41+
}
3342
}
3443

35-
_editor->missionChanged();
3644
return true;
3745
}
3846

0 commit comments

Comments
 (0)