diff --git a/Makefile b/Makefile index 6a219bafd..a19db00dd 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ CFG_DIR = $(BASE_DIR)/cfg LIBS = toxcore ncursesw libconfig libcurl -CFLAGS ?= -std=c11 -pthread -Wall -Wpedantic -Wunused -fstack-protector-all -Wvla -Wno-missing-braces -Wmissing-prototypes -Wcast-align -Wcast-qual +CFLAGS ?= -std=c11 -pthread -Wall -Wpedantic -Wunused -fstack-protector-all -Wvla -Wno-missing-braces -Wmissing-prototypes -Wcast-align -Wcast-qual -Wmissing-declarations -Wshadow 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/friendlist.c b/src/friendlist.c index f27f45dab..0c08da40b 100644 --- a/src/friendlist.c +++ b/src/friendlist.c @@ -1127,9 +1127,7 @@ static void blocklist_onDraw(ToxWindow *self, Tox *tox, int y2, int x2) int start = (y2 - FLIST_OFST) * page; int end = y2 - FLIST_OFST + start; - int i; - - for (i = start; i < Blocked.num_blocked && i < end; ++i) { + for (int i = start; i < Blocked.num_blocked && i < end; ++i) { uint32_t f = Blocked.index[i]; bool f_selected = false; @@ -1170,9 +1168,7 @@ static void blocklist_onDraw(ToxWindow *self, Tox *tox, int y2, int x2) wprintw(self->window, "Public key: "); wattroff(self->window, A_BOLD); - int i; - - for (i = 0; i < TOX_PUBLIC_KEY_SIZE; ++i) { + for (int i = 0; i < TOX_PUBLIC_KEY_SIZE; ++i) { wprintw(self->window, "%02X", Blocked.list[selected_num].pub_key[i] & 0xff); } } @@ -1241,9 +1237,7 @@ static void friendlist_onDraw(ToxWindow *self, Toxic *toxic) const size_t num_friends = Friends.num_friends; pthread_mutex_unlock(&Winthread.lock); - int i; - - for (i = start; i < num_friends && i < end; ++i) { + for (int i = start; i < num_friends && i < end; ++i) { pthread_mutex_lock(&Winthread.lock); uint32_t f = Friends.index[i]; bool is_active = Friends.list[f].active; @@ -1402,9 +1396,7 @@ static void friendlist_onDraw(ToxWindow *self, Toxic *toxic) wprintw(self->window, "Public key: "); wattroff(self->window, A_BOLD); - int i; - - for (i = 0; i < TOX_PUBLIC_KEY_SIZE; ++i) { + for (int i = 0; i < TOX_PUBLIC_KEY_SIZE; ++i) { wprintw(self->window, "%02X", Friends.list[selected_num].pub_key[i] & 0xff); } } diff --git a/src/game_life.c b/src/game_life.c index b56a41445..ce6524b04 100644 --- a/src/game_life.c +++ b/src/game_life.c @@ -242,12 +242,12 @@ static int life_get_live_neighbours(const LifeState *state, const int i, const i int count = 0; - for (size_t i = 0; i < 8; ++i) { - if (n[i] == NULL) { + for (size_t idx = 0; idx < 8; ++idx) { + if (n[idx] == NULL) { return 0; // If we're at a boundary kill cell } - if (n[i]->alive) { + if (n[idx]->alive) { ++count; } } diff --git a/src/groupchat_commands.c b/src/groupchat_commands.c index 9a76285a1..b8141ab03 100644 --- a/src/groupchat_commands.c +++ b/src/groupchat_commands.c @@ -485,7 +485,7 @@ void cmd_set_peerlimit(WINDOW *window, ToxWindow *self, Toxic *toxic, int argc, if (argc < 1) { Tox_Err_Group_State_Queries err; - uint32_t maxpeers = tox_group_get_peer_limit(tox, self->num, &err); + maxpeers = tox_group_get_peer_limit(tox, self->num, &err); if (err != TOX_ERR_GROUP_STATE_QUERIES_OK) { line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, "Failed to retrieve peer limit (error %d).", @@ -1105,9 +1105,9 @@ void cmd_whois(WINDOW *window, ToxWindow *self, Toxic *toxic, int argc, char (*a char pk_string[TOX_GROUP_PEER_PUBLIC_KEY_SIZE * 2 + 1] = {0}; - for (size_t i = 0; i < TOX_GROUP_PEER_PUBLIC_KEY_SIZE; ++i) { + for (size_t j = 0; j < TOX_GROUP_PEER_PUBLIC_KEY_SIZE; ++j) { char d[3]; - snprintf(d, sizeof(d), "%02X", peer->public_key[i] & 0xff); + snprintf(d, sizeof(d), "%02X", peer->public_key[j] & 0xff); strcat(pk_string, d); } diff --git a/src/groupchats.c b/src/groupchats.c index 1c40cdbc2..438e0055e 100644 --- a/src/groupchats.c +++ b/src/groupchats.c @@ -120,7 +120,7 @@ static const char *group_cmd_list[] = { "/whois", }; -GroupChat groupchats[MAX_GROUPCHAT_NUM]; +static GroupChat groupchats[MAX_GROUPCHAT_NUM]; static ToxWindow *new_group_chat(Tox *tox, uint32_t groupnumber, const char *groupname, int length); static void groupchat_set_group_name(ToxWindow *self, Toxic *toxic, uint32_t groupnumber); diff --git a/src/notify.c b/src/notify.c index f4a4c4ed9..6ef918413 100644 --- a/src/notify.c +++ b/src/notify.c @@ -167,7 +167,7 @@ static bool is_playing(int source) /* cooldown is in seconds */ #define DEVICE_COOLDOWN 5 /* TODO perhaps load this from config? */ static bool device_opened = false; -time_t last_opened_update = 0; +static time_t last_opened_update = 0; /* Opens primary device. Returns true on succe*/ static void m_open_device(const Client_Config *c_config) diff --git a/src/video_device.c b/src/video_device.c index 2b57de759..4ff0a9527 100644 --- a/src/video_device.c +++ b/src/video_device.c @@ -92,7 +92,7 @@ typedef struct VideoDevice { static const char *dvideo_device_names[2]; /* Default device */ static char *video_devices_names[2][MAX_DEVICES]; /* Container of available devices */ -static int size[2]; /* Size of above containers */ +static int c_size[2]; /* Size of above containers */ static VideoDevice *video_devices_running[2][MAX_DEVICES] = {{NULL}}; /* Running devices */ static uint32_t primary_video_device[2]; /* Primary device */ @@ -136,27 +136,27 @@ static void yuv420tobgr(uint16_t width, uint16_t height, const uint8_t *y, #if !(defined(__OSX__) || defined(__APPLE__)) static void yuv422to420(uint8_t *plane_y, uint8_t *plane_u, uint8_t *plane_v, - uint8_t *input, uint16_t width, uint16_t height) + uint8_t *f_input, uint16_t width, uint16_t height) { - uint8_t *end = input + width * height * 2; + uint8_t *end = f_input + width * height * 2; - while (input != end) { - uint8_t *line_end = input + width * 2; + while (f_input != end) { + uint8_t *line_end = f_input + width * 2; - while (input != line_end) { - *plane_y++ = *input++; - *plane_u++ = *input++; - *plane_y++ = *input++; - *plane_v++ = *input++; + while (f_input != line_end) { + *plane_y++ = *f_input++; + *plane_u++ = *f_input++; + *plane_y++ = *f_input++; + *plane_v++ = *f_input++; } - line_end = input + width * 2; + line_end = f_input + width * 2; - while (input != line_end) { - *plane_y++ = *input++; - input++;//u - *plane_y++ = *input++; - input++;//v + while (f_input != line_end) { + *plane_y++ = *f_input++; + f_input++;//u + *plane_y++ = *f_input++; + f_input++;//v } } } @@ -176,20 +176,20 @@ static int xioctl(int fh, unsigned long request, void *arg) VideoDeviceError init_video_devices(Toxic *toxic) { - size[vdt_input] = 0; + c_size[vdt_input] = 0; #if defined(__OSX__) || defined(__APPLE__) - if (osx_video_init(&video_devices_names[vdt_input][0], &size[vdt_input]) != 0) { + if (osx_video_init(&video_devices_names[vdt_input][0], &c_size[vdt_input]) != 0) { return vde_InternalError; } #else /* not __OSX__ || __APPLE__ */ - for (; size[vdt_input] <= MAX_DEVICES; ++size[vdt_input]) { + for (; c_size[vdt_input] <= MAX_DEVICES; ++c_size[vdt_input]) { int fd; char device_address[] = "/dev/videoXX"; - snprintf(device_address + 10, sizeof(char) * strlen(device_address) - 10, "%i", size[vdt_input]); + snprintf(device_address + 10, sizeof(char) * strlen(device_address) - 10, "%i", c_size[vdt_input]); fd = open(device_address, O_RDWR | O_NONBLOCK, 0); @@ -225,7 +225,7 @@ VideoDeviceError init_video_devices(Toxic *toxic) strcat(video_input_name, ")"); } - video_devices_names[vdt_input][size[vdt_input]] = video_input_name; + video_devices_names[vdt_input][c_size[vdt_input]] = video_input_name; close(fd); } @@ -233,7 +233,7 @@ VideoDeviceError init_video_devices(Toxic *toxic) #endif - size[vdt_output] = 1; + c_size[vdt_output] = 1; // TODO(iphydf): String literals are const char *. This may need to be // copied, or if we're not owning any output device names, it should be // const and video_devices_names needs to be split. @@ -270,7 +270,7 @@ VideoDeviceError terminate_video_devices(void) int i; - for (i = 0; i < size[vdt_input]; ++i) { + for (i = 0; i < c_size[vdt_input]; ++i) { free(video_devices_names[vdt_input][i]); } @@ -290,13 +290,13 @@ VideoDeviceError register_video_device_callback(int32_t friend_number, uint32_t { #if defined(__OSX__) || defined(__APPLE__) - if (size[vdt_input] <= device_idx || !video_devices_running[vdt_input][device_idx]) { + if (c_size[vdt_input] <= device_idx || !video_devices_running[vdt_input][device_idx]) { return vde_InvalidSelection; } #else /* not __OSX__ || __APPLE__ */ - if (size[vdt_input] <= device_idx || !video_devices_running[vdt_input][device_idx] + if (c_size[vdt_input] <= device_idx || !video_devices_running[vdt_input][device_idx] || !video_devices_running[vdt_input][device_idx]->fd) { return vde_InvalidSelection; } @@ -314,7 +314,7 @@ VideoDeviceError register_video_device_callback(int32_t friend_number, uint32_t VideoDeviceError set_primary_video_device(VideoDeviceType type, int32_t selection) { - if (size[type] <= selection || selection < 0) { + if (c_size[type] <= selection || selection < 0) { return vde_InvalidSelection; } @@ -337,7 +337,7 @@ void get_primary_video_device_name(VideoDeviceType type, char *buf, int size) VideoDeviceError open_video_device(VideoDeviceType type, int32_t selection, uint32_t *device_idx, uint32_t *width, uint32_t *height) { - if (size[type] <= selection || selection < 0) { + if (c_size[type] <= selection || selection < 0) { return vde_InvalidSelection; } @@ -487,7 +487,7 @@ VideoDeviceError open_video_device(VideoDeviceType type, int32_t selection, uint device->n_buffers = i; - enum v4l2_buf_type type; + enum v4l2_buf_type btype; for (i = 0; i < device->n_buffers; ++i) { struct v4l2_buffer buf = {0}; @@ -508,10 +508,10 @@ VideoDeviceError open_video_device(VideoDeviceType type, int32_t selection, uint } } - type = V4L2_BUF_TYPE_VIDEO_CAPTURE; + btype = V4L2_BUF_TYPE_VIDEO_CAPTURE; /* Turn on video stream */ - if (-1 == xioctl(device->fd, VIDIOC_STREAMON, &type)) { + if (-1 == xioctl(device->fd, VIDIOC_STREAMON, &btype)) { close_video_device(vdt_input, temp_idx); unlock; return vde_FailedStart; @@ -701,7 +701,7 @@ void *video_thread_poll(void *userdata) // TODO: maybe use thread for every inp if (video_thread_paused) { sleep_thread(10000L); /* Wait for unpause. */ } else { - for (i = 0; i < size[vdt_input]; ++i) { + for (i = 0; i < c_size[vdt_input]; ++i) { lock; if (video_devices_running[vdt_input][i] != NULL) { @@ -863,7 +863,7 @@ VideoDeviceError close_video_device(VideoDeviceType type, uint32_t device_idx) void print_video_devices(ToxWindow *self, const Client_Config *c_config, VideoDeviceType type) { - for (int i = 0; i < size[type]; ++i) { + for (int i = 0; i < c_size[type]; ++i) { line_info_add(self, c_config, false, NULL, NULL, SYS_MSG, 0, 0, "%d: %s", i, video_devices_names[type][i]); } @@ -872,7 +872,7 @@ void print_video_devices(ToxWindow *self, const Client_Config *c_config, VideoDe VideoDeviceError video_selection_valid(VideoDeviceType type, int32_t selection) { - return (size[type] <= selection || selection < 0) ? vde_InvalidSelection : vde_None; + return (c_size[type] <= selection || selection < 0) ? vde_InvalidSelection : vde_None; } #endif /* VIDEO */