mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-07-15 01:57:40 -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:
69
dialog.c
69
dialog.c
@ -13,7 +13,7 @@
|
||||
#include "putty.h"
|
||||
#include "dialog.h"
|
||||
|
||||
int ctrl_path_elements(char *path)
|
||||
int ctrl_path_elements(const char *path)
|
||||
{
|
||||
int i = 1;
|
||||
while (*path) {
|
||||
@ -25,7 +25,7 @@ int ctrl_path_elements(char *path)
|
||||
|
||||
/* Return the number of matching path elements at the starts of p1 and p2,
|
||||
* or INT_MAX if the paths are identical. */
|
||||
int ctrl_path_compare(char *p1, char *p2)
|
||||
int ctrl_path_compare(const char *p1, const char *p2)
|
||||
{
|
||||
int i = 0;
|
||||
while (*p1 || *p2) {
|
||||
@ -86,7 +86,7 @@ void ctrl_free_set(struct controlset *s)
|
||||
* path. If that path doesn't exist, return the index where it
|
||||
* should be inserted.
|
||||
*/
|
||||
static int ctrl_find_set(struct controlbox *b, char *path, int start)
|
||||
static int ctrl_find_set(struct controlbox *b, const char *path, int start)
|
||||
{
|
||||
int i, last, thisone;
|
||||
|
||||
@ -112,7 +112,7 @@ static int ctrl_find_set(struct controlbox *b, char *path, int start)
|
||||
* path, or -1 if no such controlset exists. If -1 is passed as
|
||||
* input, finds the first.
|
||||
*/
|
||||
int ctrl_find_path(struct controlbox *b, char *path, int index)
|
||||
int ctrl_find_path(struct controlbox *b, const char *path, int index)
|
||||
{
|
||||
if (index < 0)
|
||||
index = ctrl_find_set(b, path, 1);
|
||||
@ -127,7 +127,7 @@ int ctrl_find_path(struct controlbox *b, char *path, int index)
|
||||
|
||||
/* Set up a panel title. */
|
||||
struct controlset *ctrl_settitle(struct controlbox *b,
|
||||
char *path, char *title)
|
||||
const char *path, const char *title)
|
||||
{
|
||||
|
||||
struct controlset *s = snew(struct controlset);
|
||||
@ -151,8 +151,8 @@ struct controlset *ctrl_settitle(struct controlbox *b,
|
||||
}
|
||||
|
||||
/* Retrieve a pointer to a controlset, creating it if absent. */
|
||||
struct controlset *ctrl_getset(struct controlbox *b,
|
||||
char *path, char *name, char *boxtitle)
|
||||
struct controlset *ctrl_getset(struct controlbox *b, const char *path,
|
||||
const char *name, const char *boxtitle)
|
||||
{
|
||||
struct controlset *s;
|
||||
int index = ctrl_find_set(b, path, 1);
|
||||
@ -257,8 +257,8 @@ union control *ctrl_columns(struct controlset *s, int ncolumns, ...)
|
||||
return c;
|
||||
}
|
||||
|
||||
union control *ctrl_editbox(struct controlset *s, char *label, char shortcut,
|
||||
int percentage,
|
||||
union control *ctrl_editbox(struct controlset *s, const char *label,
|
||||
char shortcut, int percentage,
|
||||
intorptr helpctx, handler_fn handler,
|
||||
intorptr context, intorptr context2)
|
||||
{
|
||||
@ -272,8 +272,8 @@ union control *ctrl_editbox(struct controlset *s, char *label, char shortcut,
|
||||
return c;
|
||||
}
|
||||
|
||||
union control *ctrl_combobox(struct controlset *s, char *label, char shortcut,
|
||||
int percentage,
|
||||
union control *ctrl_combobox(struct controlset *s, const char *label,
|
||||
char shortcut, int percentage,
|
||||
intorptr helpctx, handler_fn handler,
|
||||
intorptr context, intorptr context2)
|
||||
{
|
||||
@ -293,7 +293,7 @@ union control *ctrl_combobox(struct controlset *s, char *label, char shortcut,
|
||||
* title is expected to be followed by a shortcut _iff_ `shortcut'
|
||||
* is NO_SHORTCUT.
|
||||
*/
|
||||
union control *ctrl_radiobuttons(struct controlset *s, char *label,
|
||||
union control *ctrl_radiobuttons(struct controlset *s, const char *label,
|
||||
char shortcut, int ncolumns, intorptr helpctx,
|
||||
handler_fn handler, intorptr context, ...)
|
||||
{
|
||||
@ -339,9 +339,9 @@ union control *ctrl_radiobuttons(struct controlset *s, char *label,
|
||||
return c;
|
||||
}
|
||||
|
||||
union control *ctrl_pushbutton(struct controlset *s,char *label,char shortcut,
|
||||
intorptr helpctx, handler_fn handler,
|
||||
intorptr context)
|
||||
union control *ctrl_pushbutton(struct controlset *s, const char *label,
|
||||
char shortcut, intorptr helpctx,
|
||||
handler_fn handler, intorptr context)
|
||||
{
|
||||
union control *c = ctrl_new(s, CTRL_BUTTON, helpctx, handler, context);
|
||||
c->button.label = label ? dupstr(label) : NULL;
|
||||
@ -351,9 +351,9 @@ union control *ctrl_pushbutton(struct controlset *s,char *label,char shortcut,
|
||||
return c;
|
||||
}
|
||||
|
||||
union control *ctrl_listbox(struct controlset *s,char *label,char shortcut,
|
||||
intorptr helpctx, handler_fn handler,
|
||||
intorptr context)
|
||||
union control *ctrl_listbox(struct controlset *s, const char *label,
|
||||
char shortcut, intorptr helpctx,
|
||||
handler_fn handler, intorptr context)
|
||||
{
|
||||
union control *c = ctrl_new(s, CTRL_LISTBOX, helpctx, handler, context);
|
||||
c->listbox.label = label ? dupstr(label) : NULL;
|
||||
@ -368,8 +368,8 @@ union control *ctrl_listbox(struct controlset *s,char *label,char shortcut,
|
||||
return c;
|
||||
}
|
||||
|
||||
union control *ctrl_droplist(struct controlset *s, char *label, char shortcut,
|
||||
int percentage, intorptr helpctx,
|
||||
union control *ctrl_droplist(struct controlset *s, const char *label,
|
||||
char shortcut, int percentage, intorptr helpctx,
|
||||
handler_fn handler, intorptr context)
|
||||
{
|
||||
union control *c = ctrl_new(s, CTRL_LISTBOX, helpctx, handler, context);
|
||||
@ -385,9 +385,9 @@ union control *ctrl_droplist(struct controlset *s, char *label, char shortcut,
|
||||
return c;
|
||||
}
|
||||
|
||||
union control *ctrl_draglist(struct controlset *s,char *label,char shortcut,
|
||||
intorptr helpctx, handler_fn handler,
|
||||
intorptr context)
|
||||
union control *ctrl_draglist(struct controlset *s, const char *label,
|
||||
char shortcut, intorptr helpctx,
|
||||
handler_fn handler, intorptr context)
|
||||
{
|
||||
union control *c = ctrl_new(s, CTRL_LISTBOX, helpctx, handler, context);
|
||||
c->listbox.label = label ? dupstr(label) : NULL;
|
||||
@ -402,10 +402,10 @@ union control *ctrl_draglist(struct controlset *s,char *label,char shortcut,
|
||||
return c;
|
||||
}
|
||||
|
||||
union control *ctrl_filesel(struct controlset *s,char *label,char shortcut,
|
||||
char const *filter, int write, char *title,
|
||||
intorptr helpctx, handler_fn handler,
|
||||
intorptr context)
|
||||
union control *ctrl_filesel(struct controlset *s, const char *label,
|
||||
char shortcut, const char *filter, int write,
|
||||
const char *title, intorptr helpctx,
|
||||
handler_fn handler, intorptr context)
|
||||
{
|
||||
union control *c = ctrl_new(s, CTRL_FILESELECT, helpctx, handler, context);
|
||||
c->fileselect.label = label ? dupstr(label) : NULL;
|
||||
@ -416,9 +416,9 @@ union control *ctrl_filesel(struct controlset *s,char *label,char shortcut,
|
||||
return c;
|
||||
}
|
||||
|
||||
union control *ctrl_fontsel(struct controlset *s,char *label,char shortcut,
|
||||
intorptr helpctx, handler_fn handler,
|
||||
intorptr context)
|
||||
union control *ctrl_fontsel(struct controlset *s, const char *label,
|
||||
char shortcut, intorptr helpctx,
|
||||
handler_fn handler, intorptr context)
|
||||
{
|
||||
union control *c = ctrl_new(s, CTRL_FONTSELECT, helpctx, handler, context);
|
||||
c->fontselect.label = label ? dupstr(label) : NULL;
|
||||
@ -433,16 +433,17 @@ union control *ctrl_tabdelay(struct controlset *s, union control *ctrl)
|
||||
return c;
|
||||
}
|
||||
|
||||
union control *ctrl_text(struct controlset *s, char *text, intorptr helpctx)
|
||||
union control *ctrl_text(struct controlset *s, const char *text,
|
||||
intorptr helpctx)
|
||||
{
|
||||
union control *c = ctrl_new(s, CTRL_TEXT, helpctx, NULL, P(NULL));
|
||||
c->text.label = dupstr(text);
|
||||
return c;
|
||||
}
|
||||
|
||||
union control *ctrl_checkbox(struct controlset *s, char *label, char shortcut,
|
||||
intorptr helpctx, handler_fn handler,
|
||||
intorptr context)
|
||||
union control *ctrl_checkbox(struct controlset *s, const char *label,
|
||||
char shortcut, intorptr helpctx,
|
||||
handler_fn handler, intorptr context)
|
||||
{
|
||||
union control *c = ctrl_new(s, CTRL_CHECKBOX, helpctx, handler, context);
|
||||
c->checkbox.label = label ? dupstr(label) : NULL;
|
||||
|
Reference in New Issue
Block a user