From b9f9546e2bf644d60d16bef8ccadae5b392e614d Mon Sep 17 00:00:00 2001 From: iphydf Date: Sat, 20 Jan 2018 18:30:35 +0000 Subject: [PATCH] Fix typedef enums and potential uninitialised value. --- src/audio_call.c | 1 + src/audio_call.h | 4 ++-- src/bootstrap.c | 7 +++++-- src/line_info.h | 2 +- src/log.h | 2 +- src/python_api.c | 2 +- src/settings.h | 4 ++-- src/windows.h | 2 +- 8 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/audio_call.c b/src/audio_call.c index 4206b9a..950f0c4 100644 --- a/src/audio_call.c +++ b/src/audio_call.c @@ -56,6 +56,7 @@ #endif extern FriendsList Friends; +struct CallControl CallControl; #define cbend pthread_exit(NULL) diff --git a/src/audio_call.h b/src/audio_call.h index 8ceb522..7256924 100644 --- a/src/audio_call.h +++ b/src/audio_call.h @@ -79,9 +79,9 @@ struct CallControl { uint32_t video_bit_rate; int32_t video_frame_duration; -} CallControl; +}; -struct CallControl CallControl; +extern struct CallControl CallControl; /* You will have to pass pointer to first member of 'windows' declared in windows.c */ ToxAV *init_audio(ToxWindow *self, Tox *tox); diff --git a/src/bootstrap.c b/src/bootstrap.c index ae6f659..5c62d13 100644 --- a/src/bootstrap.c +++ b/src/bootstrap.c @@ -108,7 +108,10 @@ static struct DHT_Nodes { /* Determine if a node is offline by comparing the age of the nodeslist * to the last time the node was successfully pinged. */ -#define NODE_IS_OFFLINE(last_scan, last_ping) ((last_ping + NODE_OFFLINE_TIMOUT) <= (last_ping)) +static bool node_is_offline(unsigned long long int last_ping) +{ + return last_ping + NODE_OFFLINE_TIMOUT <= last_ping; +} /* Return true if nodeslist pointed to by fp needs to be updated. * This will be the case if the file is empty, has an invalid format, @@ -377,7 +380,7 @@ static int extract_node(const char *line, struct Node *node) long long int last_pinged = extract_val_last_pinged(last_pinged_str + LAST_PING_JSON_KEY_LEN); - if (last_pinged <= 0 || NODE_IS_OFFLINE(Nodes.last_scan, last_pinged)) { + if (last_pinged <= 0 || node_is_offline(last_pinged)) { return -3; } diff --git a/src/line_info.h b/src/line_info.h index 985ba02..e80d1cb 100644 --- a/src/line_info.h +++ b/src/line_info.h @@ -31,7 +31,7 @@ #define MAX_LINE_INFO_QUEUE 1024 #define MAX_LINE_INFO_MSG_SIZE MAX_STR_SIZE + TOXIC_MAX_NAME_LENGTH + 32 /* needs extra room for log loading */ -enum { +typedef enum { SYS_MSG, IN_MSG, OUT_MSG, diff --git a/src/log.h b/src/log.h index fb2889c..1ebbc83 100644 --- a/src/log.h +++ b/src/log.h @@ -30,7 +30,7 @@ struct chatlog { bool log_on; /* specific to current chat window */ }; -enum { +typedef enum { LOG_GROUP, LOG_PROMPT, LOG_CHAT, diff --git a/src/python_api.c b/src/python_api.c index 65dba3e..313197f 100644 --- a/src/python_api.c +++ b/src/python_api.c @@ -67,7 +67,7 @@ static PyObject *python_api_get_nick(PyObject *self, PyObject *args) static PyObject *python_api_get_status(PyObject *self, PyObject *args) { - PyObject *ret; + PyObject *ret = NULL; if (!PyArg_ParseTuple(args, "")) return NULL; diff --git a/src/settings.h b/src/settings.h index bfaf708..c0d74dd 100644 --- a/src/settings.h +++ b/src/settings.h @@ -88,7 +88,7 @@ struct user_settings { #endif }; -enum { +enum settings_values { AUTOLOG_OFF = 0, AUTOLOG_ON = 1, @@ -114,7 +114,7 @@ enum { MPLEX_OFF = 0, MPLEX_ON = 1, -} settings_values; +}; #define LINE_JOIN "-->" #define LINE_QUIT "<--" diff --git a/src/windows.h b/src/windows.h index 9371d99..928b824 100644 --- a/src/windows.h +++ b/src/windows.h @@ -42,7 +42,7 @@ #define CHATBOX_HEIGHT 2 /* Curses foreground colours (background is black) */ -enum { +typedef enum { WHITE, GREEN, CYAN,