Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
## [Unreleased]

### Fixed
- **Dialog: Fix crash when opening/using Add Comment dialog (2026-04-08)**
- Prevents a segmentation fault when opening or submitting the Add Comment dialog caused by an uninitialized `key` pointer in `GetTextDialog`.
- `GetTextDialog` constructors now initialize all entries of `key[]` to `nullptr` to avoid dereferencing uninitialized pointers.
- Files modified: `zone/dialog_zone.cc`

- **Order Comment: Treat comment modifiers like normal modifiers (2026-04-08)**
- Comment modifiers were previously assigned a hardcoded `call_order`, which caused them to be moved to the bottom when new normal modifiers were added. Comments now inherit a contextual `call_order` so they preserve insertion order and behave like normal modifiers.
- Files modified: `zone/dialog_zone.cc`
Expand Down
10 changes: 10 additions & 0 deletions main/business/check.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5833,6 +5833,11 @@ int Order::Add(Order *order)
FnTrace("Order::Add()");
if (order == nullptr)
return 1; // Add failed
if (debug_mode)
{
fprintf(stderr, "DEBUG: Order::Add(this=%p, order=%p, call_order=%d, modifier_list=%p)\\n",
(void*)this, (void*)order, (int)order->call_order, (void*)modifier_list);
}

// start at end of list and work backwords
Order *ptr = modifier_list;
Expand All @@ -5843,6 +5848,8 @@ int Order::Add(Order *order)
while (ptr && order->call_order < ptr->call_order)
ptr = ptr->fore;
}
if (debug_mode)
fprintf(stderr, "DEBUG: Order::Add selected ptr=%p\\n", (void*)ptr);

// Insert order after ptr
order->parent = this;
Expand All @@ -5860,6 +5867,9 @@ int Order::Add(Order *order)

if (order->next)
order->next->fore = order;
if (debug_mode)
fprintf(stderr, "DEBUG: Order::Add done parent=%p next=%p fore=%p modifier_list=%p\\n",
(void*)order->parent, (void*)order->next, (void*)order->fore, (void*)modifier_list);
return FigureCost();
}

Expand Down
12 changes: 12 additions & 0 deletions main/hardware/terminal.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2866,6 +2866,9 @@ int Terminal::NextDialog(Zone *currZone)
int Terminal::KillDialog()
{
FnTrace("Terminal::KillDialog()");
if (debug_mode)
fprintf(stderr, "DEBUG: Terminal::KillDialog(this=%p, dialog=%p, next_dialog=%p)\\n",
(void*)this, (void*)dialog, (void*)next_dialog);
int jump_index = 0;
char next_signal[STRLENGTH];

Expand All @@ -2880,17 +2883,26 @@ int Terminal::KillDialog()
{
jump_index = dlg->target_index;
vt_safe_string::safe_copy(next_signal, STRLENGTH, dlg->target_signal);
if (debug_mode)
fprintf(stderr, "DEBUG: Terminal::KillDialog dynamic_cast DialogZone dlg=%p target_index=%d next_signal='%s'\\n",
(void*)dlg, jump_index, next_signal);
}
else
{
next_signal[0] = '\0';
if (debug_mode)
fprintf(stderr, "DEBUG: Terminal::KillDialog dialog is not DialogZone, pointer=%p\\n", (void*)dialog);
}

RegionInfo r(dialog);
r.w += dialog->shadow;
r.h += dialog->shadow;
if (debug_mode)
fprintf(stderr, "DEBUG: Terminal::KillDialog deleting dialog=%p\\n", (void*)dialog);
delete dialog;
dialog = nullptr;
if (debug_mode)
fprintf(stderr, "DEBUG: Terminal::KillDialog dialog deleted, proceeding to Draw/Update\\n");

Draw(1);
UpdateAll();
Expand Down
24 changes: 24 additions & 0 deletions zone/dialog_zone.cc
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,8 @@ GetTextDialog::GetTextDialog()
{
FnTrace("GetTextDialog::GetTextDialog()");
int i;
for (i = 0; i < 37; ++i)
key[i] = nullptr;

lit = nullptr;
w = 950;
Expand Down Expand Up @@ -1023,6 +1025,8 @@ GetTextDialog::GetTextDialog(const char* msg, const char* retmsg, int mlen)
{
FnTrace("GetTextDialog::GetTextDialog(const char* )");
int i;
for (i = 0; i < 37; ++i)
key[i] = nullptr;

lit = nullptr;
w = 950;
Expand Down Expand Up @@ -3564,6 +3568,14 @@ RenderResult OrderCommentDialog::Render(Terminal *term, int update_flag)
SignalResult OrderCommentDialog::Signal(Terminal *term, const genericChar* message)
{
FnTrace("OrderCommentDialog::Signal()");
if (debug_mode)
{
int bprint = buffidx;
if (bprint > 200) bprint = 200;
fprintf(stderr, "DEBUG: OrderCommentDialog::Signal term=%p check=%p order=%p buffidx=%d buffer='%.*s'\\n",
(void*)term, (void*)(term ? term->check : nullptr), (void*)(term ? term->order : nullptr),
buffidx, bprint, buffer);
}
SignalResult retval = SIGNAL_OKAY;
static const genericChar* commands[] = {
"backspace", "clear", "enter", "cancel", nullptr};
Expand All @@ -3589,6 +3601,12 @@ SignalResult OrderCommentDialog::Signal(Terminal *term, const genericChar* messa
// Make sure we're working with the parent order, not a modifier
if (parent_order->parent)
parent_order = parent_order->parent;
if (debug_mode)
{
fprintf(stderr, "DEBUG: OrderCommentDialog::Signal parent_order=%p parent=%p modifier_list=%p\\n",
(void*)parent_order, (void*)(parent_order ? parent_order->parent : nullptr),
(void*)(parent_order ? parent_order->modifier_list : nullptr));
}

// Create a new modifier order with the comment text
Order *comment_order = new Order(buffer, 0); // Price is 0 for comments
Expand Down Expand Up @@ -3623,6 +3641,9 @@ SignalResult OrderCommentDialog::Signal(Terminal *term, const genericChar* messa
if (parent_order->Add(comment_order) == 0)
{
// Successfully added - update totals and display
if (debug_mode)
fprintf(stderr, "DEBUG: OrderCommentDialog::Signal comment_order=%p added to parent=%p\\n",
(void*)comment_order, (void*)parent_order);
SubCheck *sc = term->check->current_sub;
if (sc != nullptr)
{
Expand All @@ -3634,6 +3655,9 @@ SignalResult OrderCommentDialog::Signal(Terminal *term, const genericChar* messa
else
{
// Failed to add - clean up
if (debug_mode)
fprintf(stderr, "DEBUG: OrderCommentDialog::Signal parent_order->Add failed, deleting comment_order=%p\\n",
(void*)comment_order);
delete comment_order;
}
}
Expand Down
Loading