1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-01 19:42:48 -05:00

Giant const-correctness patch of doom!

Having found a lot of unfixed constness issues in recent development,
I thought perhaps it was time to get proactive, so I compiled the
whole codebase with -Wwrite-strings. That turned up a huge load of
const problems, which I've fixed in this commit: the Unix build now
goes cleanly through with -Wwrite-strings, and the Windows build is as
close as I could get it (there are some lingering issues due to
occasional Windows API functions like AcquireCredentialsHandle not
having the right constness).

Notable fallout beyond the purely mechanical changing of types:
 - the stuff saved by cmdline_save_param() is now explicitly
   dupstr()ed, and freed in cmdline_run_saved.
 - I couldn't make both string arguments to cmdline_process_param()
   const, because it intentionally writes to one of them in the case
   where it's the argument to -pw (in the vain hope of being at least
   slightly friendly to 'ps'), so elsewhere I had to temporarily
   dupstr() something for the sake of passing it to that function
 - I had to invent a silly parallel version of const_cmp() so I could
   pass const string literals in to lookup functions.
 - stripslashes() in pscp.c and psftp.c has the annoying strchr nature
This commit is contained in:
Simon Tatham
2015-05-15 11:15:42 +01:00
parent fb4fbe1158
commit 89da2ddf56
65 changed files with 559 additions and 450 deletions

View File

@ -342,7 +342,7 @@ char *gtk_askpass_main(const char *display, const char *wintitle,
}
#ifdef TEST_ASKPASS
void modalfatalbox(char *p, ...)
void modalfatalbox(const char *p, ...)
{
va_list ap;
fprintf(stderr, "FATAL ERROR: ");

View File

@ -1055,7 +1055,7 @@ static void set_transient_window_pos(GtkWidget *parent, GtkWidget *child)
gtk_widget_set_uposition(GTK_WIDGET(child), dx, dy);
}
void dlg_error_msg(void *dlg, char *msg)
void dlg_error_msg(void *dlg, const char *msg)
{
struct dlgparam *dp = (struct dlgparam *)dlg;
GtkWidget *window, *hbox, *text, *ok;
@ -1998,7 +1998,7 @@ GtkWidget *layout_ctrls(struct dlgparam *dp, struct Shortcuts *scs,
{
GtkWidget *ww;
GtkRequisition req;
char *browsebtn =
const char *browsebtn =
(ctrl->generic.type == CTRL_FILESELECT ?
"Browse..." : "Change...");
@ -3138,7 +3138,8 @@ static void messagebox_handler(union control *ctrl, void *dlg,
if (event == EVENT_ACTION)
dlg_end(dlg, ctrl->generic.context.i);
}
int messagebox(GtkWidget *parentwin, char *title, char *msg, int minwid, ...)
int messagebox(GtkWidget *parentwin, const char *title, const char *msg,
int minwid, ...)
{
GtkWidget *window, *w0, *w1;
struct controlbox *ctrlbox;
@ -3235,7 +3236,7 @@ int messagebox(GtkWidget *parentwin, char *title, char *msg, int minwid, ...)
return dp.retval;
}
int string_width(char *text)
int string_width(const char *text)
{
GtkWidget *label = gtk_label_new(text);
GtkRequisition req;
@ -3355,21 +3356,21 @@ void old_keyfile_warning(void)
*/
}
void fatal_message_box(void *window, char *msg)
void fatal_message_box(void *window, const char *msg)
{
messagebox(window, "PuTTY Fatal Error", msg,
string_width("REASONABLY LONG LINE OF TEXT FOR BASIC SANITY"),
"OK", 'o', 1, 1, NULL);
}
void nonfatal_message_box(void *window, char *msg)
void nonfatal_message_box(void *window, const char *msg)
{
messagebox(window, "PuTTY Error", msg,
string_width("REASONABLY LONG LINE OF TEXT FOR BASIC SANITY"),
"OK", 'o', 1, 1, NULL);
}
void fatalbox(char *p, ...)
void fatalbox(const char *p, ...)
{
va_list ap;
char *msg;
@ -3381,7 +3382,7 @@ void fatalbox(char *p, ...)
cleanup_exit(1);
}
void nonfatal(char *p, ...)
void nonfatal(const char *p, ...)
{
va_list ap;
char *msg;
@ -3404,7 +3405,7 @@ static void licence_clicked(GtkButton *button, gpointer data)
{
char *title;
char *licence =
const char *licence =
"Copyright 1997-2015 Simon Tatham.\n\n"
"Portions copyright Robert de Bath, Joris van Rantwijk, Delian "

View File

@ -175,7 +175,7 @@ static char *x11_guess_derived_font_name(XFontStruct *xfs, int bold, int wide)
if (XGetFontProperty(xfs, fontprop, &ret)) {
char *name = XGetAtomName(disp, (Atom)ret);
if (name && name[0] == '-') {
char *strings[13];
const char *strings[13];
char *dupname, *extrafree = NULL, *ret;
char *p, *q;
int nstr;

View File

@ -133,7 +133,7 @@ struct draw_ctx {
static int send_raw_mouse;
static char *app_name = "pterm";
static const char *app_name = "pterm";
static void start_backend(struct gui_data *inst);
static void exit_callback(void *vinst);
@ -143,7 +143,7 @@ char *x_get_default(const char *key)
return XGetDefault(GDK_DISPLAY(), app_name, key);
}
void connection_fatal(void *frontend, char *p, ...)
void connection_fatal(void *frontend, const char *p, ...)
{
struct gui_data *inst = (struct gui_data *)frontend;
@ -221,7 +221,7 @@ int from_backend_eof(void *frontend)
return TRUE; /* do respond to incoming EOF with outgoing */
}
int get_userpass_input(prompts_t *p, unsigned char *in, int inlen)
int get_userpass_input(prompts_t *p, const unsigned char *in, int inlen)
{
struct gui_data *inst = (struct gui_data *)p->frontend;
int ret;
@ -885,7 +885,7 @@ gint key_event(GtkWidget *widget, GdkEventKey *event, gpointer data)
* NetHack keypad mode.
*/
if (nethack_mode) {
char *keys = NULL;
const char *keys = NULL;
switch (event->keyval) {
case GDK_KP_1: case GDK_KP_End: keys = "bB\002"; break;
case GDK_KP_2: case GDK_KP_Down: keys = "jJ\012"; break;
@ -2603,7 +2603,7 @@ GdkCursor *make_mouse_ptr(struct gui_data *inst, int cursor_val)
return ret;
}
void modalfatalbox(char *p, ...)
void modalfatalbox(const char *p, ...)
{
va_list ap;
fprintf(stderr, "FATAL ERROR: ");
@ -2614,7 +2614,7 @@ void modalfatalbox(char *p, ...)
exit(1);
}
void cmdline_error(char *p, ...)
void cmdline_error(const char *p, ...)
{
va_list ap;
fprintf(stderr, "%s: ", appname);
@ -2695,7 +2695,7 @@ int do_cmdline(int argc, char **argv, int do_everything, int *allow_launch,
#define SECOND_PASS_ONLY { if (!do_everything) continue; }
while (--argc > 0) {
char *p = *++argv;
const char *p = *++argv;
int ret;
/*

View File

@ -84,21 +84,22 @@ void *get_window(void *frontend); /* void * to avoid depending on gtk.h */
/* Things pterm.c needs from gtkdlg.c */
int do_config_box(const char *title, Conf *conf,
int midsession, int protcfginfo);
void fatal_message_box(void *window, char *msg);
void nonfatal_message_box(void *window, char *msg);
void fatal_message_box(void *window, const char *msg);
void nonfatal_message_box(void *window, const char *msg);
void about_box(void *window);
void *eventlogstuff_new(void);
void showeventlog(void *estuff, void *parentwin);
void logevent_dlg(void *estuff, const char *string);
int reallyclose(void *frontend);
#ifdef MAY_REFER_TO_GTK_IN_HEADERS
int messagebox(GtkWidget *parentwin, char *title, char *msg, int minwid, ...);
int string_width(char *text);
int messagebox(GtkWidget *parentwin, const char *title,
const char *msg, int minwid, ...);
int string_width(const char *text);
#endif
/* Things pterm.c needs from {ptermm,uxputty}.c */
char *make_default_wintitle(char *hostname);
int process_nonoption_arg(char *arg, Conf *conf, int *allow_launch);
int process_nonoption_arg(const char *arg, Conf *conf, int *allow_launch);
/* pterm.c needs this special function in xkeysym.c */
int keysym_to_unicode(int keysym);

View File

@ -364,7 +364,8 @@ static void console_prompt_text(FILE *outfp, const char *data, int len)
fflush(outfp);
}
int console_get_userpass_input(prompts_t *p, unsigned char *in, int inlen)
int console_get_userpass_input(prompts_t *p, const unsigned char *in,
int inlen)
{
size_t curr_prompt;
FILE *outfp = NULL;

View File

@ -98,7 +98,7 @@ Filename *filename_deserialise(void *vdata, int maxsize, int *used)
#ifdef DEBUG
static FILE *debug_fp = NULL;
void dputs(char *buf)
void dputs(const char *buf)
{
if (!debug_fp) {
debug_fp = fopen("debug.log", "w");

View File

@ -776,7 +776,8 @@ Socket sk_new(SockAddr addr, int port, int privport, int oobinline,
return (Socket) ret;
}
Socket sk_newlistener(char *srcaddr, int port, Plug plug, int local_host_only, int orig_address_family)
Socket sk_newlistener(const char *srcaddr, int port, Plug plug,
int local_host_only, int orig_address_family)
{
int s;
#ifndef NO_IPV6

View File

@ -23,7 +23,7 @@
SockAddr unix_sock_addr(const char *path);
Socket new_unix_listener(SockAddr listenaddr, Plug plug);
void fatalbox(char *p, ...)
void fatalbox(const char *p, ...)
{
va_list ap;
fprintf(stderr, "FATAL ERROR: ");
@ -33,7 +33,7 @@ void fatalbox(char *p, ...)
fputc('\n', stderr);
exit(1);
}
void modalfatalbox(char *p, ...)
void modalfatalbox(const char *p, ...)
{
va_list ap;
fprintf(stderr, "FATAL ERROR: ");
@ -43,7 +43,7 @@ void modalfatalbox(char *p, ...)
fputc('\n', stderr);
exit(1);
}
void nonfatal(char *p, ...)
void nonfatal(const char *p, ...)
{
va_list ap;
fprintf(stderr, "ERROR: ");
@ -52,7 +52,7 @@ void nonfatal(char *p, ...)
va_end(ap);
fputc('\n', stderr);
}
void connection_fatal(void *frontend, char *p, ...)
void connection_fatal(void *frontend, const char *p, ...)
{
va_list ap;
fprintf(stderr, "FATAL ERROR: ");
@ -62,7 +62,7 @@ void connection_fatal(void *frontend, char *p, ...)
fputc('\n', stderr);
exit(1);
}
void cmdline_error(char *p, ...)
void cmdline_error(const char *p, ...)
{
va_list ap;
fprintf(stderr, "pageant: ");

View File

@ -29,7 +29,7 @@ void *logctx;
static struct termios orig_termios;
void fatalbox(char *p, ...)
void fatalbox(const char *p, ...)
{
struct termios cf;
va_list ap;
@ -46,7 +46,7 @@ void fatalbox(char *p, ...)
}
cleanup_exit(1);
}
void modalfatalbox(char *p, ...)
void modalfatalbox(const char *p, ...)
{
struct termios cf;
va_list ap;
@ -63,7 +63,7 @@ void modalfatalbox(char *p, ...)
}
cleanup_exit(1);
}
void nonfatal(char *p, ...)
void nonfatal(const char *p, ...)
{
struct termios cf;
va_list ap;
@ -75,7 +75,7 @@ void nonfatal(char *p, ...)
fputc('\n', stderr);
postmsg(&cf);
}
void connection_fatal(void *frontend, char *p, ...)
void connection_fatal(void *frontend, const char *p, ...)
{
struct termios cf;
va_list ap;
@ -92,7 +92,7 @@ void connection_fatal(void *frontend, char *p, ...)
}
cleanup_exit(1);
}
void cmdline_error(char *p, ...)
void cmdline_error(const char *p, ...)
{
struct termios cf;
va_list ap;
@ -446,7 +446,7 @@ int from_backend_eof(void *frontend_handle)
return FALSE; /* do not respond to incoming EOF with outgoing */
}
int get_userpass_input(prompts_t *p, unsigned char *in, int inlen)
int get_userpass_input(prompts_t *p, const unsigned char *in, int inlen)
{
int ret;
ret = cmdline_get_passwd_input(p, in, inlen);

View File

@ -230,7 +230,7 @@ static int localproxy_select_result(int fd, int event)
return 1;
}
Socket platform_new_connection(SockAddr addr, char *hostname,
Socket platform_new_connection(SockAddr addr, const char *hostname,
int port, int privport,
int oobinline, int nodelay, int keepalive,
Plug plug, Conf *conf)

View File

@ -33,7 +33,7 @@ void cleanup_exit(int code)
exit(code);
}
int process_nonoption_arg(char *arg, Conf *conf, int *allow_launch)
int process_nonoption_arg(const char *arg, Conf *conf, int *allow_launch)
{
return 0; /* pterm doesn't have any. */
}

View File

@ -706,8 +706,8 @@ static void pty_uxsel_setup(Pty pty)
* freed by the caller.
*/
static const char *pty_init(void *frontend, void **backend_handle, Conf *conf,
char *host, int port, char **realhost, int nodelay,
int keepalive)
const char *host, int port, char **realhost,
int nodelay, int keepalive)
{
int slavefd;
pid_t pid, pgrp;
@ -1008,7 +1008,7 @@ static void pty_try_write(Pty pty)
/*
* Called to send data down the pty.
*/
static int pty_send(void *handle, char *buf, int len)
static int pty_send(void *handle, const char *buf, int len)
{
Pty pty = (Pty)handle;

View File

@ -50,9 +50,11 @@ static int got_host = 0;
const int use_event_log = 1, new_session = 1, saved_sessions = 1;
int process_nonoption_arg(char *arg, Conf *conf, int *allow_launch)
int process_nonoption_arg(const char *arg, Conf *conf, int *allow_launch)
{
char *p, *q = arg;
char *argdup, *p, *q;
argdup = dupstr(arg);
q = argdup;
if (got_host) {
/*
@ -61,7 +63,7 @@ int process_nonoption_arg(char *arg, Conf *conf, int *allow_launch)
* argument, so that it will be deferred until it's a good
* moment to run it.
*/
int ret = cmdline_process_param("-P", arg, 1, conf);
int ret = cmdline_process_param("-P", argdup, 1, conf);
assert(ret == 2);
} else if (!strncmp(q, "telnet:", 7)) {
/*
@ -90,7 +92,7 @@ int process_nonoption_arg(char *arg, Conf *conf, int *allow_launch)
/*
* Otherwise, treat this argument as a host name.
*/
p = arg;
p = argdup;
while (*p && !isspace((unsigned char)*p))
p++;
if (*p)
@ -100,6 +102,9 @@ int process_nonoption_arg(char *arg, Conf *conf, int *allow_launch)
}
if (got_host)
*allow_launch = TRUE;
sfree(argdup);
return 1;
}

View File

@ -289,8 +289,8 @@ static const char *serial_configure(Serial serial, Conf *conf)
*/
static const char *serial_init(void *frontend_handle, void **backend_handle,
Conf *conf,
char *host, int port, char **realhost, int nodelay,
int keepalive)
const char *host, int port, char **realhost,
int nodelay, int keepalive)
{
Serial serial;
const char *err;
@ -462,7 +462,7 @@ static void serial_try_write(Serial serial)
/*
* Called to send data down the serial connection.
*/
static int serial_send(void *handle, char *buf, int len)
static int serial_send(void *handle, const char *buf, int len)
{
Serial serial = (Serial) handle;

View File

@ -68,7 +68,7 @@ Filename *platform_default_filename(const char *name)
char *get_ttymode(void *frontend, const char *mode) { return NULL; }
int get_userpass_input(prompts_t *p, unsigned char *in, int inlen)
int get_userpass_input(prompts_t *p, const unsigned char *in, int inlen)
{
int ret;
ret = cmdline_get_passwd_input(p, in, inlen);
@ -120,7 +120,7 @@ struct RFile {
int fd;
};
RFile *open_existing_file(char *name, uint64 *size,
RFile *open_existing_file(const char *name, uint64 *size,
unsigned long *mtime, unsigned long *atime,
long *perms)
{
@ -174,7 +174,7 @@ struct WFile {
char *name;
};
WFile *open_new_file(char *name, long perms)
WFile *open_new_file(const char *name, long perms)
{
int fd;
WFile *ret;
@ -192,7 +192,7 @@ WFile *open_new_file(char *name, long perms)
}
WFile *open_existing_wfile(char *name, uint64 *size)
WFile *open_existing_wfile(const char *name, uint64 *size)
{
int fd;
WFile *ret;
@ -298,7 +298,7 @@ uint64 get_file_posn(WFile *f)
return ret;
}
int file_type(char *name)
int file_type(const char *name)
{
struct stat statbuf;
@ -321,7 +321,7 @@ struct DirHandle {
DIR *dir;
};
DirHandle *open_directory(char *name)
DirHandle *open_directory(const char *name)
{
DIR *dir;
DirHandle *ret;
@ -356,7 +356,7 @@ void close_directory(DirHandle *dir)
sfree(dir);
}
int test_wildcard(char *name, int cmdline)
int test_wildcard(const char *name, int cmdline)
{
struct stat statbuf;
@ -390,7 +390,7 @@ struct WildcardMatcher {
glob_t globbed;
int i;
};
WildcardMatcher *begin_wildcard_matching(char *name) {
WildcardMatcher *begin_wildcard_matching(const char *name) {
WildcardMatcher *ret = snew(WildcardMatcher);
if (glob(name, 0, NULL, &ret->globbed) < 0) {
@ -413,7 +413,7 @@ void finish_wildcard_matching(WildcardMatcher *dir) {
sfree(dir);
}
int vet_filename(char *name)
int vet_filename(const char *name)
{
if (strchr(name, '/'))
return FALSE;
@ -424,12 +424,12 @@ int vet_filename(char *name)
return TRUE;
}
int create_directory(char *name)
int create_directory(const char *name)
{
return mkdir(name, 0777) == 0;
}
char *dir_file_cat(char *dir, char *file)
char *dir_file_cat(const char *dir, const char *file)
{
return dupcat(dir, "/", file, NULL);
}
@ -559,7 +559,7 @@ int ssh_sftp_loop_iteration(void)
/*
* Read a PSFTP command line from stdin.
*/
char *ssh_sftp_get_cmdline(char *prompt, int no_fds_ok)
char *ssh_sftp_get_cmdline(const char *prompt, int no_fds_ok)
{
char *buf;
int buflen, bufsize, ret;

View File

@ -57,7 +57,7 @@ int mb_to_wc(int codepage, int flags, const char *mbstr, int mblen,
}
int wc_to_mb(int codepage, int flags, const wchar_t *wcstr, int wclen,
char *mbstr, int mblen, char *defchr, int *defused,
char *mbstr, int mblen, const char *defchr, int *defused,
struct unicode_data *ucsdata)
{
/* FIXME: we should remove the defused param completely... */