1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-17 19:11:00 -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

@ -44,15 +44,15 @@ struct cmdline_saved_param_set {
*/
static struct cmdline_saved_param_set saves[NPRIORITIES];
static void cmdline_save_param(char *p, char *value, int pri)
static void cmdline_save_param(const char *p, const char *value, int pri)
{
if (saves[pri].nsaved >= saves[pri].savesize) {
saves[pri].savesize = saves[pri].nsaved + 32;
saves[pri].params = sresize(saves[pri].params, saves[pri].savesize,
struct cmdline_saved_param);
}
saves[pri].params[saves[pri].nsaved].p = p;
saves[pri].params[saves[pri].nsaved].value = value;
saves[pri].params[saves[pri].nsaved].p = dupstr(p);
saves[pri].params[saves[pri].nsaved].value = dupstr(value);
saves[pri].nsaved++;
}
@ -85,8 +85,8 @@ void cmdline_cleanup(void)
* return means that we aren't capable of processing the prompt and
* someone else should do it.
*/
int cmdline_get_passwd_input(prompts_t *p, unsigned char *in, int inlen) {
int cmdline_get_passwd_input(prompts_t *p, const unsigned char *in, int inlen)
{
static int tried_once = 0;
/*
@ -125,7 +125,7 @@ int cmdline_get_passwd_input(prompts_t *p, unsigned char *in, int inlen) {
*/
int cmdline_tooltype = 0;
static int cmdline_check_unavailable(int flag, char *p)
static int cmdline_check_unavailable(int flag, const char *p)
{
if (cmdline_tooltype & flag) {
cmdline_error("option \"%s\" not available in this tool", p);
@ -159,7 +159,8 @@ static int cmdline_check_unavailable(int flag, char *p)
if (need_save < 0) return x; \
} while (0)
int cmdline_process_param(char *p, char *value, int need_save, Conf *conf)
int cmdline_process_param(const char *p, char *value,
int need_save, Conf *conf)
{
int ret = 0;
@ -328,7 +329,8 @@ int cmdline_process_param(char *p, char *value, int need_save, Conf *conf)
sfree(host);
}
if (!strcmp(p, "-m")) {
char *filename, *command;
const char *filename;
char *command;
int cmdlen, cmdsize;
FILE *fp;
int c, d;
@ -578,8 +580,13 @@ int cmdline_process_param(char *p, char *value, int need_save, Conf *conf)
void cmdline_run_saved(Conf *conf)
{
int pri, i;
for (pri = 0; pri < NPRIORITIES; pri++)
for (i = 0; i < saves[pri].nsaved; i++)
for (pri = 0; pri < NPRIORITIES; pri++) {
for (i = 0; i < saves[pri].nsaved; i++) {
cmdline_process_param(saves[pri].params[i].p,
saves[pri].params[i].value, 0, conf);
sfree(saves[pri].params[i].p);
sfree(saves[pri].params[i].value);
}
saves[pri].nsaved = 0;
}
}