Skip to content

Commit

Permalink
cleanup: add missing-declarations and shadow compile flags and fix wa…
Browse files Browse the repository at this point in the history
…rnings
  • Loading branch information
JFreegman committed Feb 4, 2024
1 parent afce6b3 commit ea90877
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 54 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
16 changes: 4 additions & 12 deletions src/friendlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/game_life.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/groupchat_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -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).",
Expand Down Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion src/groupchats.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/notify.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
66 changes: 33 additions & 33 deletions src/video_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down Expand Up @@ -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
}
}
}
Expand All @@ -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);

Expand Down Expand Up @@ -225,15 +225,15 @@ 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);
}
}

#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.
Expand Down Expand Up @@ -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]);
}

Expand All @@ -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;
}
Expand All @@ -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;
}

Expand All @@ -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;
}

Expand Down Expand Up @@ -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};
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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]);
}

Expand All @@ -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 */

0 comments on commit ea90877

Please sign in to comment.