1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-06-23 21:45:30 +00:00

Fixed cppcheck warnings

This commit is contained in:
James Booth 2014-04-26 00:36:36 +01:00
parent ab4ea80a70
commit d6e92f62dc
26 changed files with 41 additions and 206 deletions

View File

@ -181,18 +181,6 @@ chat_session_is_inactive(const char * const recipient)
}
}
gboolean
chat_session_is_active(const char * const recipient)
{
ChatSession session = g_hash_table_lookup(sessions, recipient);
if (session == NULL) {
return FALSE;
} else {
return (session->state == CHAT_STATE_ACTIVE);
}
}
void
chat_session_set_active(const char * const recipient)
{

View File

@ -38,7 +38,6 @@ void chat_session_set_recipient_supports(const char * const recipient,
void chat_session_set_composing(const char * const recipient);
void chat_session_no_activity(const char * const recipient);
gboolean chat_session_is_inactive(const char * const recipient);
gboolean chat_session_is_active(const char * const recipient);
void chat_session_set_active(const char * const recipient);
gboolean chat_session_is_paused(const char * const recipient);
gboolean chat_session_is_gone(const char * const recipient);

View File

@ -1191,12 +1191,11 @@ cmd_alias_remove(char *value)
void
cmd_autocomplete(char *input, int *size)
{
int i = 0;
char *found = NULL;
char inp_cpy[*size];
// autocomplete command
if ((strncmp(input, "/", 1) == 0) && (!str_contains(input, *size, ' '))) {
int i = 0;
char *found = NULL;
char inp_cpy[*size];
for(i = 0; i < *size; i++) {
inp_cpy[i] = input[i];
}

View File

@ -1300,7 +1300,6 @@ gboolean
cmd_status(gchar **args, struct cmd_help_t help)
{
char *usr = args[0];
char *usr_jid = NULL;
jabber_conn_status_t conn_status = jabber_get_connection_status();
win_type_t win_type = ui_current_win_type();
@ -1335,7 +1334,7 @@ cmd_status(gchar **args, struct cmd_help_t help)
break;
case WIN_CONSOLE:
if (usr != NULL) {
usr_jid = roster_barejid_from_name(usr);
char *usr_jid = roster_barejid_from_name(usr);
if (usr_jid == NULL) {
usr_jid = usr;
}
@ -1355,7 +1354,6 @@ gboolean
cmd_info(gchar **args, struct cmd_help_t help)
{
char *usr = args[0];
char *usr_jid = NULL;
jabber_conn_status_t conn_status = jabber_get_connection_status();
win_type_t win_type = ui_current_win_type();
@ -1411,7 +1409,7 @@ cmd_info(gchar **args, struct cmd_help_t help)
break;
case WIN_CONSOLE:
if (usr != NULL) {
usr_jid = roster_barejid_from_name(usr);
char *usr_jid = roster_barejid_from_name(usr);
if (usr_jid == NULL) {
usr_jid = usr;
}

View File

@ -116,7 +116,6 @@ str_replace(const char *string, const char *substr,
{
char *tok = NULL;
char *newstr = NULL;
char *oldstr = NULL;
char *head = NULL;
if (string == NULL)
@ -131,7 +130,7 @@ str_replace(const char *string, const char *substr,
head = newstr;
while ( (tok = strstr ( head, substr ))) {
oldstr = newstr;
char *oldstr = newstr;
newstr = malloc ( strlen ( oldstr ) - strlen ( substr ) +
strlen ( replacement ) + 1 );
@ -171,7 +170,6 @@ char *
prof_getline(FILE *stream)
{
char *buf;
size_t buf_size;
char *result;
char *s = NULL;
size_t s_size = 1;
@ -183,7 +181,7 @@ prof_getline(FILE *stream)
result = fgets(buf, READ_BUF_SIZE, stream);
if (result == NULL)
break;
buf_size = strlen(buf);
size_t buf_size = strlen(buf);
if (buf[buf_size - 1] == '\n') {
buf_size--;
buf[buf_size] = '\0';
@ -416,12 +414,12 @@ cmp_win_num(gconstpointer a, gconstpointer b)
int
get_next_available_win_num(GList *used)
{
int result = 0;
used = g_list_sort(used, cmp_win_num);
// only console used
if (g_list_length(used) == 1) {
return 2;
} else {
int result = 0;
int last_num = 1;
GList *curr = used;
// skip console

View File

@ -138,7 +138,6 @@ account_free(ProfAccount *account)
free(account->muc_service);
free(account->muc_nick);
free(account);
account = NULL;
}
}

View File

@ -209,13 +209,6 @@ prefs_get_priority(void)
return g_key_file_get_integer(prefs, PREF_GROUP_PRESENCE, "priority", NULL);
}
void
prefs_set_priority(gint value)
{
g_key_file_set_integer(prefs, PREF_GROUP_PRESENCE, "priority", value);
_save_prefs();
}
gint
prefs_get_reconnect(void)
{
@ -514,4 +507,4 @@ _get_default_string(preference_t pref)
default:
return NULL;
}
}
}

View File

@ -88,7 +88,6 @@ void prefs_set_notify_remind(gint period);
gint prefs_get_notify_remind(void);
void prefs_set_max_log_size(gint value);
gint prefs_get_max_log_size(void);
void prefs_set_priority(gint value);
gint prefs_get_priority(void);
void prefs_set_reconnect(gint value);
gint prefs_get_reconnect(void);

View File

@ -124,36 +124,6 @@ jid_is_valid_room_form(Jid *jid)
return (jid->fulljid != NULL);
}
/*
* Given a full room JID of the form
* room@server/nick
* Will create two new strings and point room and nick to them e.g.
* *room = "room@server", *nick = "nick"
* The strings must be freed by the caller
* Returns TRUE if the JID was parsed successfully, FALSE otherwise
*/
gboolean
parse_room_jid(const char * const full_room_jid, char **room, char **nick)
{
Jid *jid = jid_create(full_room_jid);
if (jid == NULL) {
return FALSE;
}
if (jid->resourcepart == NULL) {
jid_destroy(jid);
return FALSE;
}
*room = strdup(jid->barejid);
*nick = strdup(jid->resourcepart);
jid_destroy(jid);
return TRUE;
}
/*
* Given a barejid, and resourcepart, create and return a full JID of the form
* barejid/resourcepart
@ -173,28 +143,6 @@ create_fulljid(const char * const barejid, const char * const resource)
return result;
}
/*
* Get the room name part of the full JID, e.g.
* Full JID = "test@conference.server/person"
* returns "test@conference.server"
*/
char *
get_room_from_full_jid(const char * const full_room_jid)
{
char **tokens = g_strsplit(full_room_jid, "/", 0);
char *room_part = NULL;
if (tokens != NULL) {
if (tokens[0] != NULL) {
room_part = strdup(tokens[0]);
}
g_strfreev(tokens);
}
return room_part;
}
/*
* Get the nickname part of the full JID, e.g.
* Full JID = "test@conference.server/person"

View File

@ -42,9 +42,6 @@ void jid_destroy(Jid *jid);
gboolean jid_is_valid_room_form(Jid *jid);
char * create_fulljid(const char * const barejid, const char * const resource);
char * get_room_from_full_jid(const char * const full_room_jid);
char * get_nick_from_full_jid(const char * const full_room_jid);
gboolean parse_room_jid(const char * const full_room_jid, char **room,
char **nick);
#endif

View File

@ -158,7 +158,6 @@ void
log_msg(log_level_t level, const char * const area, const char * const msg)
{
if (level >= level_filter && logp != NULL) {
long result;
dt = g_date_time_new_now(tz);
char *level_str = _log_string_from_level(level);
@ -172,7 +171,7 @@ log_msg(log_level_t level, const char * const area, const char * const msg)
g_free(date_fmt);
if (prefs_get_boolean(PREF_LOG_ROTATE)) {
result = ftell(logp);
long result = ftell(logp);
if (result != -1 && result >= prefs_get_max_log_size()) {
_rotate_log_file();
}
@ -348,7 +347,6 @@ chat_log_get_previous(const gchar * const login, const gchar * const recipient,
char *filename = _get_log_filename(recipient, login, log_date, FALSE);
FILE *logp = fopen(filename, "r");
char *line;
if (logp != NULL) {
GString *gs_header = g_string_new("");
g_string_append_printf(gs_header, "%d/%d/%d:",
@ -359,6 +357,7 @@ chat_log_get_previous(const gchar * const login, const gchar * const recipient,
history = g_slist_append(history, header);
g_string_free(gs_header, TRUE);
char *line;
while ((line = prof_getline(logp)) != NULL) {
history = g_slist_append(history, line);
}

View File

@ -494,10 +494,8 @@ muc_complete_roster_nick_change(const char * const room,
if (chat_room != NULL) {
char *old_nick = g_hash_table_lookup(chat_room->nick_changes, nick);
char *old_nick_cpy;
if (old_nick != NULL) {
old_nick_cpy = strdup(old_nick);
char *old_nick_cpy = strdup(old_nick);
g_hash_table_remove(chat_room->nick_changes, nick);
return old_nick_cpy;
@ -543,4 +541,4 @@ gint _compare_participants(PContact a, PContact b)
g_free(key_b);
return result;
}
}

View File

@ -436,13 +436,12 @@ _otr_decrypt_message(const char * const from, const char * const message, gboole
{
char *decrypted = NULL;
OtrlTLV *tlvs = NULL;
OtrlTLV *tlv = NULL;
int result = otrlib_decrypt_message(user_state, &ops, jid, from, message, &decrypted, &tlvs);
// internal libotr message
if (result == 1) {
tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED);
OtrlTLV *tlv = otrl_tlv_find(tlvs, OTRL_TLV_DISCONNECTED);
if (tlv) {
ConnContext *context = otrlib_context_find(user_state, from, jid);

View File

@ -184,21 +184,21 @@ char *
autocomplete_param_with_func(char *input, int *size, char *command,
autocomplete_func func)
{
char *found = NULL;
GString *auto_msg = NULL;
char *result = NULL;
char inp_cpy[*size];
int i;
char command_cpy[strlen(command) + 2];
sprintf(command_cpy, "%s ", command);
int len = strlen(command_cpy);
if ((strncmp(input, command_cpy, len) == 0) && (*size > len)) {
int i;
char inp_cpy[*size];
for(i = len; i < *size; i++) {
inp_cpy[i-len] = input[i];
}
inp_cpy[(*size) - len] = '\0';
found = func(inp_cpy);
char *found = func(inp_cpy);
if (found != NULL) {
auto_msg = g_string_new(command_cpy);
g_string_append(auto_msg, found);
@ -215,20 +215,20 @@ char *
autocomplete_param_with_ac(char *input, int *size, char *command,
Autocomplete ac)
{
char *found = NULL;
GString *auto_msg = NULL;
char *result = NULL;
char inp_cpy[*size];
int i;
char *command_cpy = malloc(strlen(command) + 2);
sprintf(command_cpy, "%s ", command);
int len = strlen(command_cpy);
if ((strncmp(input, command_cpy, len) == 0) && (*size > len)) {
int i;
char inp_cpy[*size];
for(i = len; i < *size; i++) {
inp_cpy[i-len] = input[i];
}
inp_cpy[(*size) - len] = '\0';
found = autocomplete_complete(ac, inp_cpy);
char *found = autocomplete_complete(ac, inp_cpy);
if (found != NULL) {
auto_msg = g_string_new(command_cpy);
g_string_append(auto_msg, found);
@ -246,10 +246,8 @@ char *
autocomplete_param_no_with_func(char *input, int *size, char *command,
int arg_number, autocomplete_func func)
{
char *result = NULL;
if (strncmp(input, command, strlen(command)) == 0 && (*size > strlen(command))) {
int i = 0;
char *found = NULL;
GString *result_str = NULL;
// copy and null terminate input
@ -270,12 +268,12 @@ autocomplete_param_no_with_func(char *input, int *size, char *command,
// autocomplete param
if (comp_str != NULL) {
found = func(comp_str);
char *found = func(comp_str);
if (found != NULL) {
result_str = g_string_new("");
g_string_append(result_str, start_str);
g_string_append(result_str, found);
result = result_str->str;
char *result = result_str->str;
g_string_free(result_str, FALSE);
return result;
}

View File

@ -437,6 +437,5 @@ options_destroy(GHashTable *options)
{
if (options != NULL) {
g_hash_table_destroy(options);
options = NULL;
}
}
}

View File

@ -643,7 +643,6 @@ static void
_cons_show_bookmarks(const GList *list)
{
ProfWin *console = wins_get_console();
Bookmark *item;
if (list == NULL) {
cons_show("");
@ -654,7 +653,7 @@ _cons_show_bookmarks(const GList *list)
/* TODO: show status (connected or not) and window number */
while (list != NULL) {
item = list->data;
Bookmark *item = list->data;
win_print_time(console, '-');
wprintw(console->win, " %s", item->jid);

View File

@ -1050,8 +1050,6 @@ _ui_current_page_off(void)
static void
_ui_print_system_msg_from_recipient(const char * const from, const char *message)
{
int num = 0;
if (from == NULL || message == NULL)
return;
@ -1059,6 +1057,7 @@ _ui_print_system_msg_from_recipient(const char * const from, const char *message
ProfWin *window = wins_get_by_recipient(jid->barejid);
if (window == NULL) {
int num = 0;
window = wins_new(jid->barejid, WIN_CHAT);
if (window != NULL) {
num = wins_get_num(window);

View File

@ -109,8 +109,6 @@ inp_block(void)
wint_t
inp_get_char(char *input, int *size)
{
int inp_x = 0;
int i;
wint_t ch;
int display_size = 0;
@ -148,7 +146,7 @@ inp_get_char(char *input, int *size)
return ERR;
}
inp_x = getcurx(inp_win);
int inp_x = getcurx(inp_win);
// handle insert if not at end of input
if (inp_x < display_size) {
@ -160,6 +158,7 @@ inp_get_char(char *input, int *size)
for (offset = &input[*size - 1]; offset >= next_ch; offset--) {
*(offset + utf_len) = *offset;
}
int i;
for (i = 0; i < utf_len; i++) {
*(next_ch + i) = bytes[i];
}
@ -181,6 +180,7 @@ inp_get_char(char *input, int *size)
// wcrtomb can return (size_t) -1
if (utf_len < MB_CUR_MAX) {
int i;
for (i = 0 ; i < utf_len; i++) {
input[(*size)++] = bytes[i];
}
@ -709,4 +709,4 @@ _printable(const wint_t ch)
bytes[utf_len] = '\0';
gunichar unichar = g_utf8_get_char(bytes);
return g_unichar_isprint(unichar) && (ch != KEY_MOUSE);
}
}

View File

@ -64,7 +64,6 @@ win_free(ProfWin* window)
delwin(window->win);
free(window->from);
free(window);
window = NULL;
}
void

View File

@ -206,7 +206,6 @@ static void
_jabber_process_events(void)
{
int reconnect_sec;
int elapsed_sec;
switch (jabber_conn.conn_status)
{
@ -218,7 +217,7 @@ _jabber_process_events(void)
case JABBER_DISCONNECTED:
reconnect_sec = prefs_get_reconnect();
if ((reconnect_sec != 0) && (reconnect_timer != NULL)) {
elapsed_sec = g_timer_elapsed(reconnect_timer, NULL);
int elapsed_sec = g_timer_elapsed(reconnect_timer, NULL);
if (elapsed_sec > reconnect_sec) {
_jabber_reconnect();
}

View File

@ -439,13 +439,13 @@ _disco_info_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanz
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
if (g_strcmp0(id, "discoinforeq") == 0) {
GSList *identities = NULL;
GSList *features = NULL;
xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
if (query != NULL) {
xmpp_stanza_t *child = xmpp_stanza_get_children(query);
GSList *identities = NULL;
GSList *features = NULL;
while (child != NULL) {
const char *stanza_name = xmpp_stanza_get_name(child);
if (g_strcmp0(stanza_name, STANZA_NAME_FEATURE) == 0) {
@ -606,9 +606,6 @@ _disco_items_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stan
log_debug("Recieved diso#items response");
const char *id = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_ID);
const char *from = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
const char *stanza_name = NULL;
const char *item_jid = NULL;
const char *item_name = NULL;
GSList *items = NULL;
if ((g_strcmp0(id, "confreq") == 0) || (g_strcmp0(id, "discoitemsreq") == 0)) {
@ -618,13 +615,13 @@ _disco_items_result_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stan
if (query != NULL) {
xmpp_stanza_t *child = xmpp_stanza_get_children(query);
while (child != NULL) {
stanza_name = xmpp_stanza_get_name(child);
const char *stanza_name = xmpp_stanza_get_name(child);
if ((stanza_name != NULL) && (g_strcmp0(stanza_name, STANZA_NAME_ITEM) == 0)) {
item_jid = xmpp_stanza_get_attribute(child, STANZA_ATTR_JID);
const char *item_jid = xmpp_stanza_get_attribute(child, STANZA_ATTR_JID);
if (item_jid != NULL) {
DiscoItem *item = malloc(sizeof(struct disco_item_t));
item->jid = strdup(item_jid);
item_name = xmpp_stanza_get_attribute(child, STANZA_ATTR_NAME);
const char *item_name = xmpp_stanza_get_attribute(child, STANZA_ATTR_NAME);
if (item_name != NULL) {
item->name = strdup(item_name);
} else {

View File

@ -237,8 +237,6 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
xmpp_ctx_t *ctx = connection_get_ctx();
xmpp_stanza_t *xns_muc_user = xmpp_stanza_get_child_by_ns(stanza, STANZA_NS_MUC_USER);
char *room = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_FROM);
char *invitor = NULL;
char *reason = NULL;
if (room == NULL) {
log_warning("Message received with no from attribute, ignoring");
@ -258,8 +256,9 @@ _muc_user_handler(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
if (jidp == NULL) {
return 1;
}
invitor = jidp->barejid;
char *invitor = jidp->barejid;
char *reason = NULL;
xmpp_stanza_t *reason_st = xmpp_stanza_get_child_by_name(invite, STANZA_NAME_REASON);
if (reason_st != NULL) {
reason = xmpp_stanza_get_text(reason_st);

View File

@ -139,12 +139,6 @@ _presence_sub_request_count(void)
return autocomplete_length(sub_requests_ac);
}
void
presence_free_sub_requests(void)
{
autocomplete_free(sub_requests_ac);
}
void
presence_clear_sub_requests(void)
{
@ -625,7 +619,7 @@ _get_caps_key(xmpp_stanza_t * const stanza)
if ((hash_type != NULL) && (strcmp(hash_type, "sha-1") == 0)) {
log_debug("Hash type %s supported.", hash_type);
caps_key = strdup(node);
char *id = generate_unique_id("caps");
id = generate_unique_id("caps");
_send_caps_request(node, caps_key, id, from);

View File

@ -25,7 +25,6 @@
void presence_sub_requests_init(void);
void presence_add_handlers(void);
void presence_free_sub_requests(void);
void presence_clear_sub_requests(void);
#endif

View File

@ -830,62 +830,6 @@ stanza_contains_caps(xmpp_stanza_t * const stanza)
return TRUE;
}
gboolean
stanza_is_version_request(xmpp_stanza_t * const stanza)
{
char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE);
if (g_strcmp0(type, STANZA_TYPE_GET) != 0) {
return FALSE;
}
xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
if (query == NULL) {
return FALSE;
}
char *ns = xmpp_stanza_get_ns(query);
if (ns == NULL) {
return FALSE;
}
if (strcmp(ns, STANZA_NS_VERSION) != 0) {
return FALSE;
}
return TRUE;
}
gboolean
stanza_is_caps_request(xmpp_stanza_t * const stanza)
{
char *type = xmpp_stanza_get_attribute(stanza, STANZA_ATTR_TYPE);
if (g_strcmp0(type, STANZA_TYPE_GET) != 0) {
return FALSE;
}
xmpp_stanza_t *query = xmpp_stanza_get_child_by_name(stanza, STANZA_NAME_QUERY);
if (query == NULL) {
return FALSE;
}
char *ns = xmpp_stanza_get_ns(query);
if (ns == NULL) {
return FALSE;
}
if (strcmp(ns, XMPP_NS_DISCO_INFO) != 0) {
return FALSE;
}
return TRUE;
}
char *
stanza_caps_get_hash(xmpp_stanza_t * const stanza)
{
@ -957,8 +901,6 @@ stanza_get_error_message(xmpp_stanza_t *stanza)
// otherwise check each defined-condition RFC-6120 8.3.3
} else {
xmpp_stanza_t *cond_stanza = NULL;
gchar *defined_conditions[] = {
STANZA_NAME_BAD_REQUEST,
STANZA_NAME_CONFLICT,
@ -985,7 +927,7 @@ stanza_get_error_message(xmpp_stanza_t *stanza)
int i;
for (i = 0; i < ARRAY_SIZE(defined_conditions); i++) {
cond_stanza = xmpp_stanza_get_child_by_name(error_stanza, defined_conditions[i]);
xmpp_stanza_t *cond_stanza = xmpp_stanza_get_child_by_name(error_stanza, defined_conditions[i]);
if (cond_stanza != NULL) {
char *result = strdup(xmpp_stanza_get_name(cond_stanza));
return result;

View File

@ -192,9 +192,6 @@ int stanza_get_idle_time(xmpp_stanza_t * const stanza);
char * stanza_get_caps_str(xmpp_stanza_t * const stanza);
gboolean stanza_contains_caps(xmpp_stanza_t * const stanza);
char * stanza_caps_get_hash(xmpp_stanza_t * const stanza);
gboolean stanza_is_caps_request(xmpp_stanza_t * const stanza);
gboolean stanza_is_version_request(xmpp_stanza_t * const stanza);
DataForm * stanza_create_form(xmpp_stanza_t * const stanza);
void stanza_destroy_form(DataForm *form);