mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-03 04:22:47 -05:00
Make dupcat() into a variadic macro.
Up until now, it's been a variadic _function_, whose argument list consists of 'const char *' ASCIZ strings to concatenate, terminated by one containing a null pointer. Now, that function is dupcat_fn(), and it's wrapped by a C99 variadic _macro_ called dupcat(), which automatically suffixes the null-pointer terminating argument. This has three benefits. Firstly, it's just less effort at every call site. Secondly, it protects against the risk of accidentally leaving off the NULL, causing arbitrary words of stack memory to be dereferenced as char pointers. And thirdly, it protects against the more subtle risk of writing a bare 'NULL' as the terminating argument, instead of casting it explicitly to a pointer. That last one is necessary because C permits the macro NULL to expand to an integer constant such as 0, so NULL by itself may not have pointer type, and worse, it may not be marshalled in a variadic argument list in the same way as a pointer. (For example, on a 64-bit machine it might only occupy 32 bits. And yet, on another 64-bit platform, it might work just fine, so that you don't notice the mistake!) I was inspired to do this by happening to notice one of those bare NULL terminators, and thinking I'd better check if there were any more. Turned out there were quite a few. Now there are none.
This commit is contained in:
@ -235,7 +235,7 @@ static void post_fatal_message_box(void *vctx, int result)
|
||||
static void common_connfatal_message_box(
|
||||
GtkFrontend *inst, const char *msg, post_dialog_fn_t postfn)
|
||||
{
|
||||
char *title = dupcat(appname, " Fatal Error", NULL);
|
||||
char *title = dupcat(appname, " Fatal Error");
|
||||
GtkWidget *dialog = create_message_box(
|
||||
inst->window, title, msg,
|
||||
string_width("REASONABLY LONG LINE OF TEXT FOR BASIC SANITY"),
|
||||
@ -661,7 +661,7 @@ gint delete_window(GtkWidget *widget, GdkEvent *event, GtkFrontend *inst)
|
||||
* case we'll just re-emphasise that one.
|
||||
*/
|
||||
if (!find_and_raise_dialog(inst, DIALOG_SLOT_WARN_ON_CLOSE)) {
|
||||
char *title = dupcat(appname, " Exit Confirmation", NULL);
|
||||
char *title = dupcat(appname, " Exit Confirmation");
|
||||
GtkWidget *dialog = create_message_box(
|
||||
inst->window, title,
|
||||
"Are you sure you want to close this session?",
|
||||
@ -1080,8 +1080,7 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
|
||||
char *old = state_string;
|
||||
state_string = dupcat(state_string,
|
||||
state_string[0] ? "|" : "",
|
||||
mod_bits[i].name,
|
||||
(char *)NULL);
|
||||
mod_bits[i].name);
|
||||
sfree(old);
|
||||
|
||||
val &= ~mod_bits[i].mod_bit;
|
||||
@ -4596,7 +4595,7 @@ void change_settings_menuitem(GtkMenuItem *item, gpointer data)
|
||||
if (find_and_raise_dialog(inst, DIALOG_SLOT_RECONFIGURE))
|
||||
return;
|
||||
|
||||
title = dupcat(appname, " Reconfiguration", NULL);
|
||||
title = dupcat(appname, " Reconfiguration");
|
||||
|
||||
ctx = snew(struct after_change_settings_dialog_ctx);
|
||||
ctx->inst = inst;
|
||||
@ -5489,7 +5488,7 @@ void new_session_window(Conf *conf, const char *geometry_string)
|
||||
paste_clipboard_menuitem);
|
||||
MKMENUITEM("Copy All", copy_all_menuitem);
|
||||
MKSEP();
|
||||
s = dupcat("About ", appname, NULL);
|
||||
s = dupcat("About ", appname);
|
||||
MKMENUITEM(s, about_menuitem);
|
||||
sfree(s);
|
||||
#undef MKMENUITEM
|
||||
|
Reference in New Issue
Block a user