1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-09 15:23:50 -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

26
psftp.h
View File

@ -45,7 +45,7 @@ int ssh_sftp_loop_iteration(void);
* FALSE, a back end is not (intentionally) active at all (e.g.
* psftp before an `open' command).
*/
char *ssh_sftp_get_cmdline(char *prompt, int backend_required);
char *ssh_sftp_get_cmdline(const char *prompt, int backend_required);
/*
* The main program in psftp.c. Called from main() in the platform-
@ -59,13 +59,13 @@ int psftp_main(int argc, char *argv[]);
* probably only ever be supported on Windows, so these functions
* can safely be stubs on all other platforms.
*/
void gui_update_stats(char *name, unsigned long size,
void gui_update_stats(const char *name, unsigned long size,
int percentage, unsigned long elapsed,
unsigned long done, unsigned long eta,
unsigned long ratebs);
void gui_send_errcount(int list, int errs);
void gui_send_char(int is_stderr, int c);
void gui_enable(char *arg);
void gui_enable(const char *arg);
/*
* It's likely that a given platform's implementation of file
@ -87,15 +87,15 @@ typedef struct RFile RFile;
typedef struct WFile WFile;
/* Output params size, perms, mtime and atime can all be NULL if
* desired. perms will be -1 if the OS does not support POSIX permissions. */
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);
WFile *open_existing_wfile(char *name, uint64 *size);
WFile *open_existing_wfile(const char *name, uint64 *size);
/* Returns <0 on error, 0 on eof, or number of bytes read, as usual */
int read_from_file(RFile *f, void *buffer, int length);
/* Closes and frees the RFile */
void close_rfile(RFile *f);
WFile *open_new_file(char *name, long perms);
WFile *open_new_file(const char *name, long perms);
/* Returns <0 on error, 0 on eof, or number of bytes written, as usual */
int write_to_file(WFile *f, void *buffer, int length);
void set_file_times(WFile *f, unsigned long mtime, unsigned long atime);
@ -117,13 +117,13 @@ uint64 get_file_posn(WFile *f);
enum {
FILE_TYPE_NONEXISTENT, FILE_TYPE_FILE, FILE_TYPE_DIRECTORY, FILE_TYPE_WEIRD
};
int file_type(char *name);
int file_type(const char *name);
/*
* Read all the file names out of a directory.
*/
typedef struct DirHandle DirHandle;
DirHandle *open_directory(char *name);
DirHandle *open_directory(const char *name);
/* The string returned from this will need freeing if not NULL */
char *read_filename(DirHandle *dir);
void close_directory(DirHandle *dir);
@ -145,13 +145,13 @@ void close_directory(DirHandle *dir);
enum {
WCTYPE_NONEXISTENT, WCTYPE_FILENAME, WCTYPE_WILDCARD
};
int test_wildcard(char *name, int cmdline);
int test_wildcard(const char *name, int cmdline);
/*
* Actually return matching file names for a local wildcard.
*/
typedef struct WildcardMatcher WildcardMatcher;
WildcardMatcher *begin_wildcard_matching(char *name);
WildcardMatcher *begin_wildcard_matching(const char *name);
/* The string returned from this will need freeing if not NULL */
char *wildcard_get_filename(WildcardMatcher *dir);
void finish_wildcard_matching(WildcardMatcher *dir);
@ -164,17 +164,17 @@ void finish_wildcard_matching(WildcardMatcher *dir);
*
* Returns TRUE if the filename is kosher, FALSE if dangerous.
*/
int vet_filename(char *name);
int vet_filename(const char *name);
/*
* Create a directory. Returns 0 on error, !=0 on success.
*/
int create_directory(char *name);
int create_directory(const char *name);
/*
* Concatenate a directory name and a file name. The way this is
* done will depend on the OS.
*/
char *dir_file_cat(char *dir, char *file);
char *dir_file_cat(const char *dir, const char *file);
#endif /* PUTTY_PSFTP_H */