mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-02 20:12: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:
34
psftp.c
34
psftp.c
@ -68,7 +68,7 @@ struct sftp_packet *sftp_wait_for_reply(struct sftp_request *req)
|
||||
* canonification fails, at least fall back to returning a _valid_
|
||||
* pathname (though it may be ugly, eg /home/simon/../foobar).
|
||||
*/
|
||||
char *canonify(char *name)
|
||||
char *canonify(const char *name)
|
||||
{
|
||||
char *fullname, *canonname;
|
||||
struct sftp_packet *pktin;
|
||||
@ -77,7 +77,7 @@ char *canonify(char *name)
|
||||
if (name[0] == '/') {
|
||||
fullname = dupstr(name);
|
||||
} else {
|
||||
char *slash;
|
||||
const char *slash;
|
||||
if (pwd[strlen(pwd) - 1] == '/')
|
||||
slash = "";
|
||||
else
|
||||
@ -172,8 +172,13 @@ char *canonify(char *name)
|
||||
/*
|
||||
* Return a pointer to the portion of str that comes after the last
|
||||
* slash (or backslash or colon, if `local' is TRUE).
|
||||
*
|
||||
* This function has the annoying strstr() property of taking a const
|
||||
* char * and returning a char *. You should treat it as if it was a
|
||||
* pair of overloaded functions, one mapping mutable->mutable and the
|
||||
* other const->const :-(
|
||||
*/
|
||||
static char *stripslashes(char *str, int local)
|
||||
static char *stripslashes(const char *str, int local)
|
||||
{
|
||||
char *p;
|
||||
|
||||
@ -190,7 +195,7 @@ static char *stripslashes(char *str, int local)
|
||||
if (p) str = p+1;
|
||||
}
|
||||
|
||||
return str;
|
||||
return (char *)str;
|
||||
}
|
||||
|
||||
/*
|
||||
@ -1011,7 +1016,8 @@ int sftp_cmd_ls(struct sftp_command *cmd)
|
||||
struct fxp_names *names;
|
||||
struct fxp_name **ournames;
|
||||
int nnames, namesize;
|
||||
char *dir, *cdir, *unwcdir, *wildcard;
|
||||
const char *dir;
|
||||
char *cdir, *unwcdir, *wildcard;
|
||||
struct sftp_packet *pktin;
|
||||
struct sftp_request *req;
|
||||
int i;
|
||||
@ -1901,7 +1907,7 @@ static int sftp_cmd_pling(struct sftp_command *cmd)
|
||||
static int sftp_cmd_help(struct sftp_command *cmd);
|
||||
|
||||
static struct sftp_cmd_lookup {
|
||||
char *name;
|
||||
const char *name;
|
||||
/*
|
||||
* For help purposes, there are two kinds of command:
|
||||
*
|
||||
@ -1915,8 +1921,8 @@ static struct sftp_cmd_lookup {
|
||||
* contains the help that should double up for this command.
|
||||
*/
|
||||
int listed; /* do we list this in primary help? */
|
||||
char *shorthelp;
|
||||
char *longhelp;
|
||||
const char *shorthelp;
|
||||
const char *longhelp;
|
||||
int (*obey) (struct sftp_command *);
|
||||
} sftp_lookup[] = {
|
||||
/*
|
||||
@ -2139,7 +2145,7 @@ static struct sftp_cmd_lookup {
|
||||
}
|
||||
};
|
||||
|
||||
const struct sftp_cmd_lookup *lookup_command(char *name)
|
||||
const struct sftp_cmd_lookup *lookup_command(const char *name)
|
||||
{
|
||||
int i, j, k, cmp;
|
||||
|
||||
@ -2450,7 +2456,7 @@ static int verbose = 0;
|
||||
/*
|
||||
* Print an error message and perform a fatal exit.
|
||||
*/
|
||||
void fatalbox(char *fmt, ...)
|
||||
void fatalbox(const char *fmt, ...)
|
||||
{
|
||||
char *str, *str2;
|
||||
va_list ap;
|
||||
@ -2464,7 +2470,7 @@ void fatalbox(char *fmt, ...)
|
||||
|
||||
cleanup_exit(1);
|
||||
}
|
||||
void modalfatalbox(char *fmt, ...)
|
||||
void modalfatalbox(const char *fmt, ...)
|
||||
{
|
||||
char *str, *str2;
|
||||
va_list ap;
|
||||
@ -2478,7 +2484,7 @@ void modalfatalbox(char *fmt, ...)
|
||||
|
||||
cleanup_exit(1);
|
||||
}
|
||||
void nonfatal(char *fmt, ...)
|
||||
void nonfatal(const char *fmt, ...)
|
||||
{
|
||||
char *str, *str2;
|
||||
va_list ap;
|
||||
@ -2490,7 +2496,7 @@ void nonfatal(char *fmt, ...)
|
||||
fputs(str2, stderr);
|
||||
sfree(str2);
|
||||
}
|
||||
void connection_fatal(void *frontend, char *fmt, ...)
|
||||
void connection_fatal(void *frontend, const char *fmt, ...)
|
||||
{
|
||||
char *str, *str2;
|
||||
va_list ap;
|
||||
@ -2866,7 +2872,7 @@ static int psftp_connect(char *userhost, char *user, int portnumber)
|
||||
return 0;
|
||||
}
|
||||
|
||||
void cmdline_error(char *p, ...)
|
||||
void cmdline_error(const char *p, ...)
|
||||
{
|
||||
va_list ap;
|
||||
fprintf(stderr, "psftp: ");
|
||||
|
Reference in New Issue
Block a user