From e7387043851d04fed07e011ca482d25c8ee354a3 Mon Sep 17 00:00:00 2001 From: Chris Wareham Date: Tue, 14 Aug 2012 11:49:53 +0100 Subject: [PATCH] Fix most of the following classes of warnings in the ToolTalk libraries: - Const strings referenced by non-const variables. - Incorrect format specifers for printing addresses - Unused variables - Signed comparison to unsigned Also fix an incorrect enumeration value in a switch statement. --- cde/lib/tt/lib/api/c/api_file.C | 2 +- cde/lib/tt/lib/api/c/api_storage.C | 6 +++--- cde/lib/tt/lib/api/dnd/ttdnd.c | 2 -- cde/lib/tt/lib/db/db_server.h | 4 ++-- cde/lib/tt/lib/db/db_server_clnt.C | 6 +++--- cde/lib/tt/lib/db/old_db_server_functions.C | 2 +- cde/lib/tt/lib/db/tt_db_client.C | 4 +--- cde/lib/tt/lib/db/tt_db_file.C | 2 +- cde/lib/tt/lib/db/tt_db_key.C | 2 +- cde/lib/tt/lib/db/tt_db_rpc_message_routines.C | 2 +- cde/lib/tt/lib/db/tt_db_rpc_routines.C | 14 +++++++------- cde/lib/tt/lib/mp/mp_auth.C | 16 ++++++++-------- cde/lib/tt/lib/mp/mp_auth_functions.C | 2 +- cde/lib/tt/lib/mp/mp_auth_functions.h | 6 +++--- cde/lib/tt/lib/mp/mp_c_procid.C | 1 - cde/lib/tt/lib/mp/mp_c_session.C | 1 - cde/lib/tt/lib/mp/mp_pattern.C | 1 - cde/lib/tt/lib/mp/mp_rpc_client.C | 2 -- cde/lib/tt/lib/tttk/ttdesktop.C | 2 ++ cde/lib/tt/lib/tttk/tttk2free.C | 6 +++--- cde/lib/tt/lib/util/tt_audit.C | 5 +++-- cde/lib/tt/lib/util/tt_audit.h | 2 +- cde/lib/tt/lib/util/tt_enumname.C | 2 +- cde/lib/tt/lib/util/tt_host.C | 2 +- cde/lib/tt/lib/util/tt_host_equiv.C | 1 - cde/lib/tt/lib/util/tt_trace.C | 7 ++++--- cde/lib/tt/lib/util/tt_trace.h | 2 +- cde/lib/tt/lib/util/tt_trace_stream.C | 2 +- cde/lib/tt/lib/util/tt_xdr_utils.C | 2 +- 29 files changed, 51 insertions(+), 57 deletions(-) diff --git a/cde/lib/tt/lib/api/c/api_file.C b/cde/lib/tt/lib/api/c/api_file.C index 0608ed54..643cc7fb 100644 --- a/cde/lib/tt/lib/api/c/api_file.C +++ b/cde/lib/tt/lib/api/c/api_file.C @@ -416,7 +416,7 @@ extern "C" { } Tt_status -_ttds_file_server(const char *filename, char **hostname) +_ttds_file_server(const char *filename, const char **hostname) { _Tt_c_file_ptr file; _Tt_db_results dbresults; diff --git a/cde/lib/tt/lib/api/c/api_storage.C b/cde/lib/tt/lib/api/c/api_storage.C index 298394b7..45d53e8b 100644 --- a/cde/lib/tt/lib/api/c/api_storage.C +++ b/cde/lib/tt/lib/api/c/api_storage.C @@ -173,13 +173,13 @@ void _Tt_api_stg_stack_elm:: print(FILE *f) const { - (void)fprintf(f,"_Tt_api_stg_stack_elm at %lx <",this); + (void)fprintf(f,"_Tt_api_stg_stack_elm at %p <",this); switch (entry_type) { case STACK_MARK: - (void)fprintf(f,"mark %ld>\n",addr); + (void)fprintf(f,"mark %p>\n",addr); break; case STACK_STORAGE: - (void)fprintf(f,"addr 0x%lx>\n",(long)addr); + (void)fprintf(f,"addr 0x%p>\n",addr); break; } } diff --git a/cde/lib/tt/lib/api/dnd/ttdnd.c b/cde/lib/tt/lib/api/dnd/ttdnd.c index 256acb4f..780028bf 100644 --- a/cde/lib/tt/lib/api/dnd/ttdnd.c +++ b/cde/lib/tt/lib/api/dnd/ttdnd.c @@ -68,7 +68,6 @@ ttdnd_init( { int mark = tt_mark(); const char *t, **vt; - int validtypecount, i; if (tt_ptr_error(tt_open())>TT_WRN_LAST) { @@ -238,7 +237,6 @@ _ttdnd_get_contents_callback(m, p) Tt_message m; Tt_pattern p; { - int xid; int chunknumber; int maxchunk; char *type; diff --git a/cde/lib/tt/lib/db/db_server.h b/cde/lib/tt/lib/db/db_server.h index 6ac3e1d6..63b66cb8 100644 --- a/cde/lib/tt/lib/db/db_server.h +++ b/cde/lib/tt/lib/db/db_server.h @@ -276,7 +276,7 @@ bool_t xdr_Tt_oidaccess_results(XDR*, _Tt_oidaccess_results*); struct _Tt_prop { struct { u_int propname_len; - char *propname_val; + const char *propname_val; } propname; long recnum; struct { @@ -862,7 +862,7 @@ bool_t xdr_tt_garbage_collect_results(XDR *, _tt_garbage_collect_results *); #include "db/tt_db_client_utils.h" -extern int *_tt_min_auth_level_1(char**, CLIENT*, clnt_stat *status); +extern int *_tt_min_auth_level_1(const char**, CLIENT*, clnt_stat *status); extern _Tt_isam_results *_tt_isaddindex_1(_Tt_isaddindex_args*, CLIENT*); extern _Tt_isam_results *_tt_isbuild_1(_Tt_isbuild_args*, CLIENT*); extern _Tt_isam_results *_tt_isclose_1(int*, CLIENT*); diff --git a/cde/lib/tt/lib/db/db_server_clnt.C b/cde/lib/tt/lib/db/db_server_clnt.C index 2ba4c36c..fe0320dd 100644 --- a/cde/lib/tt/lib/db/db_server_clnt.C +++ b/cde/lib/tt/lib/db/db_server_clnt.C @@ -1138,7 +1138,7 @@ _tt_get_all_sessions_1(_tt_get_all_sessions_args *argp, CLIENT * clnt) { static _tt_get_all_sessions_results res; - clnt_stat result = clnt_call(clnt, TT_GET_ALL_SESSIONS, + clnt_call(clnt, TT_GET_ALL_SESSIONS, (xdrproc_t) xdr_tt_get_all_sessions_args, (caddr_t) argp, (xdrproc_t) xdr_tt_get_all_sessions_results, @@ -1153,7 +1153,7 @@ _tt_garbage_collect_1(void * /*NOTUSED*/, CLIENT *clnt) { static _tt_garbage_collect_results res; - clnt_stat result = clnt_call(clnt, TT_GARBAGE_COLLECT, + clnt_call(clnt, TT_GARBAGE_COLLECT, (xdrproc_t) xdr_void, (caddr_t) NULL, (xdrproc_t) xdr_tt_garbage_collect_results, (caddr_t) &res, @@ -1167,7 +1167,7 @@ _tt_delete_session_1(_tt_delete_session_args * args, CLIENT *clnt) { static _tt_delete_session_results res; - clnt_stat result = clnt_call(clnt, TT_DELETE_SESSION, + clnt_call(clnt, TT_DELETE_SESSION, (xdrproc_t) xdr_tt_delete_session_args, (caddr_t) args, (xdrproc_t) xdr_tt_delete_session_results, diff --git a/cde/lib/tt/lib/db/old_db_server_functions.C b/cde/lib/tt/lib/db/old_db_server_functions.C index 88a95562..795a88bb 100644 --- a/cde/lib/tt/lib/db/old_db_server_functions.C +++ b/cde/lib/tt/lib/db/old_db_server_functions.C @@ -1523,7 +1523,7 @@ _tt_db_results *_tt_queue_message_1 (_tt_queue_msg_args *args, _tt_get_rpc_strings(args->ptypes, message_info->ptypes); // Get the XDR size of the new message info structure - u_int length; + u_int length = 0; if (!message_info->xdr((XDR *)xdrsz)) { results = TT_DB_ERR_ILLEGAL_MESSAGE; } diff --git a/cde/lib/tt/lib/db/tt_db_client.C b/cde/lib/tt/lib/db/tt_db_client.C index 5dfe9131..24d369cd 100644 --- a/cde/lib/tt/lib/db/tt_db_client.C +++ b/cde/lib/tt/lib/db/tt_db_client.C @@ -193,7 +193,7 @@ _Tt_db_results _Tt_db_client::connectToDB (const _Tt_string &hostname) // If dbVersion == 1, then we are talking to an old DB server static _tt_auth_level_results results; - char *path = ""; + const char *path = ""; clnt_stat rpc_status; int *result = (int *)NULL; result = _tt_min_auth_level_1(&path, dbServer, &rpc_status); @@ -1247,7 +1247,6 @@ _Tt_db_client::dequeueMessages (const _Tt_string &file, const _Tt_string_list_ptr &ptypes, _Tt_message_list_ptr &messages) { - _Tt_db_results retval; _tt_dequeue_msgs_args args; args.file = (char *)file; @@ -1265,7 +1264,6 @@ _Tt_db_client::dequeueMessages (const _Tt_string &file, } _tt_get_rpc_messages(results->messages, messages); - retval = results->results; if (dbVersion==1) { _tt_free_rpc_messages(results->messages); } else { diff --git a/cde/lib/tt/lib/db/tt_db_file.C b/cde/lib/tt/lib/db/tt_db_file.C index 15e45251..f3124f9f 100644 --- a/cde/lib/tt/lib/db/tt_db_file.C +++ b/cde/lib/tt/lib/db/tt_db_file.C @@ -562,7 +562,7 @@ _Tt_string _Tt_db_file::getNetworkPath (const _Tt_string &file) _Tt_string hostname; _Tt_string partition; - _Tt_db_results results = _tt_db_network_path(file, + _tt_db_network_path(file, local_path, hostname, partition, diff --git a/cde/lib/tt/lib/db/tt_db_key.C b/cde/lib/tt/lib/db/tt_db_key.C index 5d5e8ff9..5d9de810 100644 --- a/cde/lib/tt/lib/db/tt_db_key.C +++ b/cde/lib/tt/lib/db/tt_db_key.C @@ -44,7 +44,7 @@ _Tt_db_key::_Tt_db_key (short version_number) { - static long last_time_sec = 0; + static unsigned int last_time_sec = 0; static long counter = 0; key.version = version_number; diff --git a/cde/lib/tt/lib/db/tt_db_rpc_message_routines.C b/cde/lib/tt/lib/db/tt_db_rpc_message_routines.C index dde12b40..2f1e880d 100644 --- a/cde/lib/tt/lib/db/tt_db_rpc_message_routines.C +++ b/cde/lib/tt/lib/db/tt_db_rpc_message_routines.C @@ -82,7 +82,7 @@ _tt_get_rpc_messages (const _tt_message_list &rpc_messages, if (rpc_messages.messages_len) { messages = new _Tt_message_list; - for (int i=0; i < rpc_messages.messages_len; i++) { + for (unsigned int i=0; i < rpc_messages.messages_len; i++) { _Tt_message_ptr message_ptr; _tt_get_rpc_message(rpc_messages.messages_val [i], diff --git a/cde/lib/tt/lib/db/tt_db_rpc_routines.C b/cde/lib/tt/lib/db/tt_db_rpc_routines.C index db4a8161..a7aa823b 100644 --- a/cde/lib/tt/lib/db/tt_db_rpc_routines.C +++ b/cde/lib/tt/lib/db/tt_db_rpc_routines.C @@ -73,7 +73,7 @@ void _tt_free_rpc_message (const _tt_message &rpc_message) void _tt_free_rpc_messages (const _tt_message_list &rpc_messages) { if (rpc_messages.messages_val) { - for (int i=0; i < rpc_messages.messages_len; i++) { + for (unsigned int i=0; i < rpc_messages.messages_len; i++) { _tt_free_rpc_message(rpc_messages.messages_val [i]); } @@ -84,7 +84,7 @@ void _tt_free_rpc_messages (const _tt_message_list &rpc_messages) void _tt_free_rpc_strings (const _tt_string_list &rpc_strings) { if (rpc_strings.values_val) { - for (int i=0; i < rpc_strings.values_len; i++) { + for (unsigned int i=0; i < rpc_strings.values_len; i++) { if (rpc_strings.values_val [i].value) { free(rpc_strings.values_val [i].value); } @@ -101,7 +101,7 @@ void _tt_free_rpc_property (const _tt_property &rpc_prop) } if (rpc_prop.values.values_val) { - for (int i=0; i < rpc_prop.values.values_len; i++) { + for (unsigned int i=0; i < rpc_prop.values.values_len; i++) { if (rpc_prop.values.values_val [i].value.value_val) { free(rpc_prop.values.values_val [i].value.value_val); } @@ -114,7 +114,7 @@ void _tt_free_rpc_property (const _tt_property &rpc_prop) void _tt_free_rpc_properties (const _tt_property_list &rpc_props) { if (rpc_props.properties_val) { - for (int i=0; i < rpc_props.properties_len; i++) { + for (unsigned int i=0; i < rpc_props.properties_len; i++) { _tt_free_rpc_property(rpc_props.properties_val [i]); } @@ -137,7 +137,7 @@ void _tt_get_rpc_strings (const _tt_string_list &rpc_strings, strings = new _Tt_string_list; if (rpc_strings.values_len) { - for (int i=0; i < rpc_strings.values_len; i++) { + for (unsigned int i=0; i < rpc_strings.values_len; i++) { (void)strings->append(_Tt_string(rpc_strings.values_val [i].value)); } } @@ -151,7 +151,7 @@ void _tt_get_rpc_property (const _tt_property &rpc_prop, if (rpc_prop.name) { prop->name = rpc_prop.name; - for (int i=0; i < rpc_prop.values.values_len; i++) { + for (unsigned int i=0; i < rpc_prop.values.values_len; i++) { int prop_value_length = rpc_prop.values.values_val [i].value.value_len; if (prop_value_length) { _Tt_string prop_value(prop_value_length); @@ -171,7 +171,7 @@ void _tt_get_rpc_properties (const _tt_property_list &rpc_props, props = new _Tt_db_property_list; if (rpc_props.properties_len) { - for (int i=0; i < rpc_props.properties_len; i++) { + for (unsigned int i=0; i < rpc_props.properties_len; i++) { _Tt_db_property_ptr prop; _tt_get_rpc_property (rpc_props.properties_val [i], prop); diff --git a/cde/lib/tt/lib/mp/mp_auth.C b/cde/lib/tt/lib/mp/mp_auth.C index 24ba925c..458d57eb 100644 --- a/cde/lib/tt/lib/mp/mp_auth.C +++ b/cde/lib/tt/lib/mp/mp_auth.C @@ -57,7 +57,7 @@ _Tt_auth:: Tt_status _Tt_auth:: generate_auth_cookie() { - static char *funcname = "_Tt_auth::make_auth_cookie()"; + static const char *funcname = "_Tt_auth::make_auth_cookie()"; _tt_AuthFileEntry *entry; int exists; char *filename; @@ -79,7 +79,7 @@ generate_auth_cookie() _TT_ICEAUTH_DEFAULT_RETRIES, _TT_ICEAUTH_DEFAULT_TIMEOUT, _TT_ICEAUTH_DEFAULT_DEADTIME))) { - char *reason = "unknown error"; + const char *reason = "unknown error"; _tt_UnlockAuthFile(filename); if (retval == _tt_AuthLockTimeout) { @@ -151,7 +151,7 @@ cleanup: Tt_status _Tt_auth:: read_auth_entries(FILE *fp, _tt_AuthFileEntryList **headp) { - static char *funcname = "_Tt_auth::read_auth_entries()"; + static const char *funcname = "_Tt_auth::read_auth_entries()"; _tt_AuthFileEntry *entry; _tt_AuthFileEntryList *head; _tt_AuthFileEntryList *el_new; @@ -189,7 +189,7 @@ read_auth_entries(FILE *fp, _tt_AuthFileEntryList **headp) Tt_status _Tt_auth:: read_auth_file(char *filename) { - static char *funcname = "Tt_auth::read_auth_file()"; + static const char *funcname = "Tt_auth::read_auth_file()"; FILE *authfp; Tt_status status = TT_OK; @@ -213,7 +213,7 @@ read_auth_file(char *filename) Tt_status _Tt_auth:: modify_auth_entry(_tt_AuthFileEntry *entry, _tt_AuthFileEntryList **headp) { - static char *funcname = "Tt_auth::modify_auth_entry()"; + static const char *funcname = "Tt_auth::modify_auth_entry()"; _tt_AuthFileEntryList *list, *prev, *el_new; for (prev=NULL, list=*headp; list; list=list->next) { @@ -253,8 +253,8 @@ modify_auth_entry(_tt_AuthFileEntry *entry, _tt_AuthFileEntryList **headp) Tt_status _Tt_auth:: write_auth_file(char *filename) { - static char *funcname = "Tt_auth::write_auth_file()"; - static char *suffix = "-n"; + static const char *funcname = "Tt_auth::write_auth_file()"; + static const char *suffix = "-n"; FILE *fp; _tt_AuthFileEntryList *list; char *tmpnam; @@ -300,7 +300,7 @@ retrieve_auth_cookie() _tt_AuthFileEntry *entry = NULL; entry = _tt_GetAuthFileEntry(_TT_ICEAUTH_PROTOCOL_NAME, - (char*) _sessionid, + _sessionid, _TT_ICEAUTH_AUTH_NAME); if (NULL == entry) return TT_AUTHFILE_ENTRY_MISSING; diff --git a/cde/lib/tt/lib/mp/mp_auth_functions.C b/cde/lib/tt/lib/mp/mp_auth_functions.C index 3e47e132..22f44737 100644 --- a/cde/lib/tt/lib/mp/mp_auth_functions.C +++ b/cde/lib/tt/lib/mp/mp_auth_functions.C @@ -340,7 +340,7 @@ _tt_WriteAuthFileEntry(FILE *auth_file, _tt_AuthFileEntry *auth) _tt_AuthFileEntry * -_tt_GetAuthFileEntry(char *protocol_name, char *network_id, char *auth_name) +_tt_GetAuthFileEntry(const char *protocol_name, const char *network_id, const char *auth_name) { FILE *auth_file; char *filename; diff --git a/cde/lib/tt/lib/mp/mp_auth_functions.h b/cde/lib/tt/lib/mp/mp_auth_functions.h index 47f34bbe..020c463b 100644 --- a/cde/lib/tt/lib/mp/mp_auth_functions.h +++ b/cde/lib/tt/lib/mp/mp_auth_functions.h @@ -126,9 +126,9 @@ extern int _tt_WriteAuthFileEntry ( ); extern _tt_AuthFileEntry *_tt_GetAuthFileEntry ( - char * /* protocol_name */, - char * /* network_id */, - char * /* auth_name */ + const char * /* protocol_name */, + const char * /* network_id */, + const char * /* auth_name */ ); extern char *_tt_GenerateMagicCookie ( diff --git a/cde/lib/tt/lib/mp/mp_c_procid.C b/cde/lib/tt/lib/mp/mp_c_procid.C index 92b3a058..7c7561ac 100644 --- a/cde/lib/tt/lib/mp/mp_c_procid.C +++ b/cde/lib/tt/lib/mp/mp_c_procid.C @@ -340,7 +340,6 @@ commit() Tt_status _Tt_c_procid:: init() { - int rpc_version = TT_RPC_VERSION; Tt_status status; if (_default_session.is_null()) { diff --git a/cde/lib/tt/lib/mp/mp_c_session.C b/cde/lib/tt/lib/mp/mp_c_session.C index 78a37532..3cab78a0 100644 --- a/cde/lib/tt/lib/mp/mp_c_session.C +++ b/cde/lib/tt/lib/mp/mp_c_session.C @@ -79,7 +79,6 @@ c_init() { _Tt_string start_ttcmd; int tried = 0; - int done = 0; Tt_status status; if (env() == _TT_ENV_X11) { diff --git a/cde/lib/tt/lib/mp/mp_pattern.C b/cde/lib/tt/lib/mp/mp_pattern.C index dc89c151..2ed3e9db 100644 --- a/cde/lib/tt/lib/mp/mp_pattern.C +++ b/cde/lib/tt/lib/mp/mp_pattern.C @@ -222,7 +222,6 @@ _Tt_pattern::add_netfile( ) { _Tt_string abspath; - Tt_status status = TT_OK; int __scopes = scopes(); if ((__scopes&(1<set_is_entered(0); } - const char *s; + const char *s = 0; int printmsg = 1; // // We do not print msg if it is a (often incomplete) update @@ -347,7 +347,7 @@ _Tt_trace::entry( // void _Tt_trace::entry( - char *argskey, + const char *argskey, _Tt_entry_pt func, va_list ap ) @@ -373,7 +373,8 @@ _Tt_trace::entry( (*_pstream)->set_is_entered(0); } - char c, *preview; + char c; + const char *preview; int num_args = strlen(argskey); // print the API name and open paren diff --git a/cde/lib/tt/lib/util/tt_trace.h b/cde/lib/tt/lib/util/tt_trace.h index 4b138018..2a049e95 100644 --- a/cde/lib/tt/lib/util/tt_trace.h +++ b/cde/lib/tt/lib/util/tt_trace.h @@ -130,7 +130,7 @@ class _Tt_trace : public _Tt_allocated { // API tracing entry call void entry( - char *argskey, + const char *argskey, _Tt_entry_pt func, va_list ap ); diff --git a/cde/lib/tt/lib/util/tt_trace_stream.C b/cde/lib/tt/lib/util/tt_trace_stream.C index 72aed923..fefc45ef 100644 --- a/cde/lib/tt/lib/util/tt_trace_stream.C +++ b/cde/lib/tt/lib/util/tt_trace_stream.C @@ -138,7 +138,7 @@ operator <<( os << _tt_enumname( msg.message_class() ); os << " <" << msg.api_id() << "> "; os << _tt_enumname( msg.state() ); - char *conjunction = " because "; + const char *conjunction = " because "; switch (msg.state()) { case TT_CREATED: case TT_SENT: diff --git a/cde/lib/tt/lib/util/tt_xdr_utils.C b/cde/lib/tt/lib/util/tt_xdr_utils.C index 833c1193..d43f9d9e 100644 --- a/cde/lib/tt/lib/util/tt_xdr_utils.C +++ b/cde/lib/tt/lib/util/tt_xdr_utils.C @@ -129,7 +129,7 @@ _tt_xdr_sizeof(xdrproc_t f, void *data) _Tt_xdr_size_stream:: _Tt_xdr_size_stream() { - memset ((char *)&ops, 0, sizeof ops); + memset (&ops, 0, sizeof ops); #if defined(OPT_BUG_SUNOS_4) || defined(OPT_BUG_HPUX) ops.x_putlong = (int (*)(...))tt_x_putlong; ops.x_putbytes = (int (*)(...))tt_x_putbytes; -- 2.25.1