Skip to content

Commit 135d84e

Browse files
authored
Merge pull request #7255 from Goober5000/7104_followup
fix some waypoint bugs
2 parents 31ad18f + 482c5a5 commit 135d84e

4 files changed

Lines changed: 25 additions & 29 deletions

File tree

code/object/waypoint.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ void waypoint_stuff_name(char *dest, const char *waypoint_list_name, int waypoin
399399

400400
if (waypoint_num < 1)
401401
{
402-
Assertion(LOCATION, "A waypoint number must be at least 1!");
402+
Error(LOCATION, "A waypoint number must be at least 1!");
403403
*dest = 0;
404404
return;
405405
}
@@ -410,8 +410,9 @@ void waypoint_stuff_name(char *dest, const char *waypoint_list_name, int waypoin
410410
return;
411411
}
412412

413-
strncpy(dest, waypoint_list_name, name_max_len);
414-
sprintf(dest + name_max_len, ":%d", waypoint_num);
413+
auto name_len = std::min(strlen(waypoint_list_name), name_max_len);
414+
strncpy(dest, waypoint_list_name, name_len);
415+
sprintf(dest + name_len, ":%d", waypoint_num);
415416
}
416417

417418
void waypoint_stuff_name(SCP_string &dest, const char *waypoint_list_name, int waypoint_num)
@@ -420,7 +421,7 @@ void waypoint_stuff_name(SCP_string &dest, const char *waypoint_list_name, int w
420421

421422
if (waypoint_num < 1)
422423
{
423-
Assertion(LOCATION, "A waypoint number must be at least 1!");
424+
Error(LOCATION, "A waypoint number must be at least 1!");
424425
dest = "";
425426
return;
426427
}

fred2/campaigntreewnd.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -480,20 +480,25 @@ int campaign_tree_wnd::error(const char *msg, ...)
480480

481481
int campaign_tree_wnd::internal_error(const char *msg, ...)
482482
{
483-
SCP_string buf, buf2;
483+
SCP_string buf;
484484
va_list args;
485485

486-
g_err++;
487486
va_start(args, msg);
488487
vsprintf(buf, msg, args);
489488
va_end(args);
490489

491-
sprintf(buf2, "%s\n\nThis is an internal error. Please let Hoffoss\n"
492-
"know about this so he can fix it. Click cancel to debug.", buf.c_str());
490+
g_err++;
493491

494-
nprintf(("Error", buf.c_str()));
495-
if (MessageBox(buf2.c_str(), "Internal Error", MB_OKCANCEL | MB_ICONEXCLAMATION) == IDCANCEL)
492+
#ifndef NDEBUG
493+
nprintf(("Internal Error", buf.c_str()));
494+
495+
buf += "\n\nThis is an internal error. Please notify a coder about this. Click cancel to debug.";
496+
497+
if (MessageBox(buf.c_str(), "Internal Error", MB_OKCANCEL | MB_ICONEXCLAMATION) == IDCANCEL)
496498
Int3(); // drop to debugger so the problem can be analyzed.
499+
#else
500+
MessageBox(buf.c_str(), "Error", MB_OK | MB_ICONEXCLAMATION);
501+
#endif
497502

498503
return -1;
499504
}

fred2/fredview.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3400,27 +3400,22 @@ int CFREDView::error(const char *msg, ...)
34003400

34013401
int CFREDView::internal_error(const char *msg, ...)
34023402
{
3403-
char buf[2048];
3403+
SCP_string buf;
34043404
va_list args;
34053405

34063406
va_start(args, msg);
3407-
vsnprintf(buf, sizeof(buf)-1, msg, args);
3407+
vsprintf(buf, msg, args);
34083408
va_end(args);
3409-
buf[sizeof(buf)-1] = '\0';
34103409

34113410
g_err = 1;
34123411

34133412
#ifndef NDEBUG
3414-
char buf2[2048];
3413+
buf += "\n\nThis is an internal error. Please notify a coder about this. Click cancel to debug.";
34153414

3416-
sprintf(buf2, "%s\n\nThis is an internal error. Please let Jason\n"
3417-
"know about this so he can fix it. Click cancel to debug.", buf);
3418-
3419-
if (MessageBox(buf2, "Internal Error", MB_OKCANCEL | MB_ICONEXCLAMATION) == IDCANCEL)
3415+
if (MessageBox(buf.c_str(), "Internal Error", MB_OKCANCEL | MB_ICONEXCLAMATION) == IDCANCEL)
34203416
Int3(); // drop to debugger so the problem can be analyzed.
3421-
34223417
#else
3423-
MessageBox(buf, "Error", MB_OK | MB_ICONEXCLAMATION);
3418+
MessageBox(buf.c_str(), "Error", MB_OK | MB_ICONEXCLAMATION);
34243419
#endif
34253420

34263421
return -1;

qtfred/src/mission/Editor.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2642,29 +2642,24 @@ int Editor::error(const char* msg, ...) {
26422642
return 1;
26432643
}
26442644
int Editor::internal_error(const char* msg, ...) {
2645-
char buf[2048];
2645+
SCP_string buf;
26462646
va_list args;
26472647

26482648
va_start(args, msg);
2649-
vsnprintf(buf, sizeof(buf) - 1, msg, args);
2649+
vsprintf(buf, msg, args);
26502650
va_end(args);
2651-
buf[sizeof(buf) - 1] = '\0';
26522651

26532652
g_err = 1;
26542653

26552654
#ifndef NDEBUG
2656-
char buf2[2048];
2657-
2658-
sprintf_safe(buf2, "%s\n\nThis is an internal error. Please let Jason\n"
2659-
"know about this so he can fix it. Click cancel to debug.", buf);
2655+
buf += "\n\nThis is an internal error. Please notify a coder about this. Click cancel to debug.";
26602656

26612657
if (_lastActiveViewport->dialogProvider->showButtonDialog(DialogType::Error,
26622658
"Internal Error",
2663-
buf2,
2659+
buf,
26642660
{ DialogButton::Ok, DialogButton::Cancel })
26652661
== DialogButton::Cancel)
26662662
Int3(); // drop to debugger so the problem can be analyzed.
2667-
26682663
#else
26692664
_lastActiveViewport->dialogProvider->showButtonDialog(DialogType::Error, "Error", buf, { DialogButton::Ok });
26702665
#endif

0 commit comments

Comments
 (0)