1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-10 01:48:00 +00:00

Convert a few more universal asserts to unreachable().

When I introduced the unreachable() macro in commit 0112936ef, I
searched the source code for assert(0) and assert(false), together
with their variant form assert(0 && "explanatory text"). But I didn't
search for assert(!"explanatory text"), which is the form I used to
use before finding that assert(0 && "text") seemed to be preferred in
other code bases.

So, here's a belated replacement of all the assert(!"stuff") macros
with further instances of unreachable().
This commit is contained in:
Simon Tatham 2019-09-09 19:07:55 +01:00
parent 5d718ef64b
commit 00112549bf
7 changed files with 20 additions and 40 deletions

6
pscp.c
View File

@ -127,14 +127,10 @@ static void tell_user(FILE *stream, const char *fmt, ...)
sfree(str2); sfree(str2);
} }
/*
* In pscp, all agent requests should be synchronous, so this is a
* never-called stub.
*/
void agent_schedule_callback(void (*callback)(void *, void *, int), void agent_schedule_callback(void (*callback)(void *, void *, int),
void *callback_ctx, void *data, int len) void *callback_ctx, void *data, int len)
{ {
assert(!"We shouldn't be here"); unreachable("all PSCP agent requests should be synchronous");
} }
/* /*

View File

@ -2428,14 +2428,10 @@ static bool verbose = false;
void ldisc_echoedit_update(Ldisc *ldisc) { } void ldisc_echoedit_update(Ldisc *ldisc) { }
/*
* In psftp, all agent requests should be synchronous, so this is a
* never-called stub.
*/
void agent_schedule_callback(void (*callback)(void *, void *, int), void agent_schedule_callback(void (*callback)(void *, void *, int),
void *callback_ctx, void *data, int len) void *callback_ctx, void *data, int len)
{ {
assert(!"We shouldn't be here"); unreachable("all PSFTP agent requests should be synchronous");
} }
/* /*

View File

@ -314,8 +314,8 @@ static struct kexinit_algorithm *ssh2_kexinit_addalg(struct kexinit_algorithm
list[i].name = name; list[i].name = name;
return &list[i]; return &list[i];
} }
assert(!"No space in KEXINIT list");
return NULL; unreachable("Should never run out of space in KEXINIT list");
} }
bool ssh2_common_filter_queue(PacketProtocolLayer *ppl) bool ssh2_common_filter_queue(PacketProtocolLayer *ppl)

View File

@ -1292,8 +1292,7 @@ void share_got_pkt_from_server(ssh_sharing_connstate *cs, int type,
break; break;
default: default:
assert(!"This packet type should never have come from ssh.c"); unreachable("This packet type should never have come from ssh.c");
break;
} }
} }

View File

@ -357,7 +357,7 @@ char *dlg_editbox_get(union control *ctrl, dlgparam *dp)
return dupstr(gtk_entry_get_text(GTK_ENTRY(uc->entry))); return dupstr(gtk_entry_get_text(GTK_ENTRY(uc->entry)));
} }
assert(!"We shouldn't get here"); unreachable("bad control type in editbox_get");
} }
#if !GTK_CHECK_VERSION(2,4,0) #if !GTK_CHECK_VERSION(2,4,0)
@ -395,7 +395,7 @@ void dlg_listbox_clear(union control *ctrl, dlgparam *dp)
return; return;
} }
#endif #endif
assert(!"We shouldn't get here"); unreachable("bad control type in listbox_clear");
} }
void dlg_listbox_del(union control *ctrl, dlgparam *dp, int index) void dlg_listbox_del(union control *ctrl, dlgparam *dp, int index)
@ -429,7 +429,7 @@ void dlg_listbox_del(union control *ctrl, dlgparam *dp, int index)
return; return;
} }
#endif #endif
assert(!"We shouldn't get here"); unreachable("bad control type in listbox_del");
} }
void dlg_listbox_add(union control *ctrl, dlgparam *dp, char const *text) void dlg_listbox_add(union control *ctrl, dlgparam *dp, char const *text)
@ -587,7 +587,7 @@ void dlg_listbox_addwithid(union control *ctrl, dlgparam *dp,
goto done; goto done;
} }
#endif #endif
assert(!"We shouldn't get here"); unreachable("bad control type in listbox_addwithid");
done: done:
dp->flags &= ~FLAG_UPDATING_COMBO_LIST; dp->flags &= ~FLAG_UPDATING_COMBO_LIST;
} }
@ -626,7 +626,7 @@ int dlg_listbox_getid(union control *ctrl, dlgparam *dp, int index)
return ret; return ret;
} }
#endif #endif
assert(!"We shouldn't get here"); unreachable("bad control type in listbox_getid");
return -1; /* placate dataflow analysis */ return -1; /* placate dataflow analysis */
} }
@ -711,7 +711,7 @@ int dlg_listbox_index(union control *ctrl, dlgparam *dp)
return ret; return ret;
} }
#endif #endif
assert(!"We shouldn't get here"); unreachable("bad control type in listbox_index");
return -1; /* placate dataflow analysis */ return -1; /* placate dataflow analysis */
} }
@ -768,7 +768,7 @@ bool dlg_listbox_issel(union control *ctrl, dlgparam *dp, int index)
return ret; return ret;
} }
#endif #endif
assert(!"We shouldn't get here"); unreachable("bad control type in listbox_issel");
return false; /* placate dataflow analysis */ return false; /* placate dataflow analysis */
} }
@ -837,7 +837,7 @@ void dlg_listbox_select(union control *ctrl, dlgparam *dp, int index)
return; return;
} }
#endif #endif
assert(!"We shouldn't get here"); unreachable("bad control type in listbox_select");
} }
void dlg_text_set(union control *ctrl, dlgparam *dp, char const *text) void dlg_text_set(union control *ctrl, dlgparam *dp, char const *text)
@ -884,8 +884,7 @@ void dlg_label_change(union control *ctrl, dlgparam *dp, char const *text)
shortcut_highlight(uc->label, ctrl->listbox.shortcut); shortcut_highlight(uc->label, ctrl->listbox.shortcut);
break; break;
default: default:
assert(!"This shouldn't happen"); unreachable("bad control type in label_change");
break;
} }
} }
@ -1016,8 +1015,7 @@ void dlg_set_focus(union control *ctrl, dlgparam *dp)
break; break;
} }
#endif #endif
assert(!"We shouldn't get here"); unreachable("bad control type in set_focus");
break;
} }
} }
@ -2730,8 +2728,7 @@ gint win_key_press(GtkWidget *widget, GdkEventKey *event, gpointer data)
break; break;
} }
#endif #endif
assert(!"We shouldn't get here"); unreachable("bad listbox type in win_key_press");
break;
} }
break; break;
} }

View File

@ -1658,9 +1658,7 @@ void winctrl_layout(struct dlgparam *dp, struct winctrls *wc,
sfree(escaped); sfree(escaped);
break; break;
default: default:
assert(!"Can't happen"); unreachable("bad control type in winctrl_layout");
num_ids = 0; /* placate gcc */
break;
} }
/* /*
@ -2096,8 +2094,7 @@ int dlg_radiobutton_get(union control *ctrl, dlgparam *dp)
for (i = 0; i < c->ctrl->radio.nbuttons; i++) for (i = 0; i < c->ctrl->radio.nbuttons; i++)
if (IsDlgButtonChecked(dp->hwnd, c->base_id + 1 + i)) if (IsDlgButtonChecked(dp->hwnd, c->base_id + 1 + i))
return i; return i;
assert(!"No radio button was checked?!"); unreachable("no radio button was checked");
return 0;
} }
void dlg_checkbox_set(union control *ctrl, dlgparam *dp, bool checked) void dlg_checkbox_set(union control *ctrl, dlgparam *dp, bool checked)
@ -2286,8 +2283,7 @@ void dlg_label_change(union control *ctrl, dlgparam *dp, char const *text)
id = c->base_id; id = c->base_id;
break; break;
default: default:
assert(!"Can't happen"); unreachable("bad control type in label_change");
break;
} }
if (escaped) { if (escaped) {
SetDlgItemText(dp->hwnd, id, escaped); SetDlgItemText(dp->hwnd, id, escaped);

View File

@ -1119,14 +1119,10 @@ void spawn_cmd(const char *cmdline, const char *args, int show)
} }
} }
/*
* This is a can't-happen stub, since Pageant never makes
* asynchronous agent requests.
*/
void agent_schedule_callback(void (*callback)(void *, void *, int), void agent_schedule_callback(void (*callback)(void *, void *, int),
void *callback_ctx, void *data, int len) void *callback_ctx, void *data, int len)
{ {
assert(!"We shouldn't get here"); unreachable("all Pageant's own agent requests should be synchronous");
} }
void cleanup_exit(int code) void cleanup_exit(int code)