From 437dd8baeb0fb06c31dbef1c2b5f41bce5a50a34 Mon Sep 17 00:00:00 2001 From: jfreegman Date: Sat, 29 Feb 2020 14:14:56 -0500 Subject: [PATCH] Some misc fixes --- Makefile | 2 +- src/avatars.c | 2 +- src/groupchat.c | 11 ++++++++--- src/line_info.c | 2 +- src/misc_tools.c | 7 +++++-- src/misc_tools.h | 2 +- src/name_lookup.c | 2 +- 7 files changed, 18 insertions(+), 10 deletions(-) diff --git a/Makefile b/Makefile index dacc76b..2051316 100644 --- a/Makefile +++ b/Makefile @@ -6,7 +6,7 @@ CFG_DIR = $(BASE_DIR)/cfg LIBS = toxcore ncursesw libconfig libcurl CFLAGS ?= -g -CFLAGS += -std=gnu99 -pthread -Wall -fstack-protector-all +CFLAGS += -std=gnu99 -pthread -Wall -Wpedantic -fstack-protector-all CFLAGS += '-DTOXICVER="$(VERSION)"' -DHAVE_WIDECHAR -D_XOPEN_SOURCE_EXTENDED -D_FILE_OFFSET_BITS=64 CFLAGS += '-DPACKAGE_DATADIR="$(abspath $(DATADIR))"' CFLAGS += ${USER_CFLAGS} diff --git a/src/avatars.c b/src/avatars.c index 17d8305..6e52786 100644 --- a/src/avatars.c +++ b/src/avatars.c @@ -112,7 +112,7 @@ int avatar_set(Tox *m, const char *path, size_t path_len) return -1; } - char PNG_signature[8] = {0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A}; + unsigned char PNG_signature[8] = {0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A}; if (check_file_signature(PNG_signature, sizeof(PNG_signature), fp) != 0) { fclose(fp); diff --git a/src/groupchat.c b/src/groupchat.c index 0ed5b23..c8c7ea1 100644 --- a/src/groupchat.c +++ b/src/groupchat.c @@ -301,7 +301,7 @@ static void group_update_name_list(uint32_t groupnum) { GroupChat *chat = &groupchats[groupnum]; - if (!chat) { + if (!chat->active) { return; } @@ -359,7 +359,7 @@ static void update_peer_list(Tox *m, uint32_t groupnum, uint32_t num_peers) { GroupChat *chat = &groupchats[groupnum]; - if (!chat) { + if (!chat->active) { return; } @@ -403,6 +403,11 @@ static void groupchat_onGroupNameListChange(ToxWindow *self, Tox *m, uint32_t gr } GroupChat *chat = &groupchats[groupnum]; + + if (!chat->active) { + return; + } + Tox_Err_Conference_Peer_Query err; uint32_t num_peers = tox_conference_peer_count(m, groupnum, &err); @@ -427,7 +432,7 @@ static void groupchat_onGroupPeerNameChange(ToxWindow *self, Tox *m, uint32_t gr GroupChat *chat = &groupchats[groupnum]; - if (!chat) { + if (!chat->active) { return; } diff --git a/src/line_info.c b/src/line_info.c index 71a15f4..d17a58b 100644 --- a/src/line_info.c +++ b/src/line_info.c @@ -381,7 +381,7 @@ void line_info_print(ToxWindow *self) if (type == OUT_MSG && timed_out(line->timestamp, NOREAD_FLAG_TIMEOUT)) { wattron(win, COLOR_PAIR(RED)); - wprintw(win, " x", line->msg); + wprintw(win, " x"); wattroff(win, COLOR_PAIR(RED)); if (line->noread_flag == false) { diff --git a/src/misc_tools.c b/src/misc_tools.c index c99df59..66c9fbf 100644 --- a/src/misc_tools.c +++ b/src/misc_tools.c @@ -491,7 +491,10 @@ bool file_exists(const char *path) File_Type file_type(const char *path) { struct stat s; - stat(path, &s); + + if (stat(path, &s) == -1) { + return FILE_TYPE_OTHER; + } switch (s.st_mode & S_IFMT) { case S_IFDIR: @@ -521,7 +524,7 @@ off_t file_size(const char *path) Returns 0 if they are the same, 1 if they differ, and -1 on error. On success this function will seek back to the beginning of fp */ -int check_file_signature(const char *signature, size_t size, FILE *fp) +int check_file_signature(const unsigned char *signature, size_t size, FILE *fp) { char buf[size]; diff --git a/src/misc_tools.h b/src/misc_tools.h index b6a4964..81c9fec 100644 --- a/src/misc_tools.h +++ b/src/misc_tools.h @@ -169,7 +169,7 @@ off_t file_size(const char *path); Returns 0 if they are the same, 1 if they differ, and -1 on error. On success this function will seek back to the beginning of fp */ -int check_file_signature(const char *signature, size_t size, FILE *fp); +int check_file_signature(const unsigned char *signature, size_t size, FILE *fp); /* sets window title in tab bar. */ void set_window_title(ToxWindow *self, const char *title, int len); diff --git a/src/name_lookup.c b/src/name_lookup.c index 06c3ef9..7e9dfb2 100644 --- a/src/name_lookup.c +++ b/src/name_lookup.c @@ -292,7 +292,7 @@ void *lookup_thread_func(void *data) int proxy_ret = set_curl_proxy(c_handle, arg_opts.proxy_address, arg_opts.proxy_port, arg_opts.proxy_type); if (proxy_ret != 0) { - lookup_error(self, "Failed to set proxy (error %d)\n"); + lookup_error(self, "Failed to set proxy (error %d)\n", proxy_ret); goto on_exit; }