mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-14 05:53:01 +01:00
cleanup: Avoid casting away constness from pointers.
This commit is contained in:
parent
1cace1e81d
commit
71f6a8d4d6
@ -56,7 +56,7 @@ static void print_ac_matches(ToxWindow *self, Tox *m, char **list, size_t n_matc
|
||||
*
|
||||
* Returns the length of the match.
|
||||
*/
|
||||
static size_t get_str_match(ToxWindow *self, char *match, size_t match_sz, const char **matches, size_t n_items,
|
||||
static size_t get_str_match(ToxWindow *self, char *match, size_t match_sz, const char *const *matches, size_t n_items,
|
||||
size_t max_size)
|
||||
{
|
||||
UNUSED_VAR(self);
|
||||
@ -96,7 +96,7 @@ static size_t get_str_match(ToxWindow *self, char *match, size_t match_sz, const
|
||||
*
|
||||
* Note: This function should not be called directly. Use complete_line() and complete_path() instead.
|
||||
*/
|
||||
static int complete_line_helper(ToxWindow *self, const char **list, const size_t n_items, bool dir_search)
|
||||
static int complete_line_helper(ToxWindow *self, const char *const *list, const size_t n_items, bool dir_search)
|
||||
{
|
||||
ChatContext *ctx = self->chatwin;
|
||||
|
||||
@ -181,7 +181,7 @@ static int complete_line_helper(ToxWindow *self, const char **list, const size_t
|
||||
}
|
||||
|
||||
char match[MAX_STR_SIZE];
|
||||
size_t match_len = get_str_match(self, match, sizeof(match), (const char **) matches, n_matches, MAX_STR_SIZE);
|
||||
size_t match_len = get_str_match(self, match, sizeof(match), (const char *const *) matches, n_matches, MAX_STR_SIZE);
|
||||
|
||||
free_ptr_array((void **) matches);
|
||||
|
||||
@ -259,12 +259,12 @@ static int complete_line_helper(ToxWindow *self, const char **list, const size_t
|
||||
return diff;
|
||||
}
|
||||
|
||||
int complete_line(ToxWindow *self, const char **list, size_t n_items)
|
||||
int complete_line(ToxWindow *self, const char *const *list, size_t n_items)
|
||||
{
|
||||
return complete_line_helper(self, list, n_items, false);
|
||||
}
|
||||
|
||||
static int complete_path(ToxWindow *self, const char **list, const size_t n_items)
|
||||
static int complete_path(ToxWindow *self, const char *const *list, const size_t n_items)
|
||||
{
|
||||
return complete_line_helper(self, list, n_items, true);
|
||||
}
|
||||
@ -385,7 +385,7 @@ int dir_match(ToxWindow *self, Tox *m, const wchar_t *line, const wchar_t *cmd)
|
||||
print_ac_matches(self, m, dirnames, dircount);
|
||||
}
|
||||
|
||||
int ret = complete_path(self, (const char **) dirnames, dircount);
|
||||
int ret = complete_path(self, (const char *const *) dirnames, dircount);
|
||||
|
||||
free_ptr_array((void **) dirnames);
|
||||
|
||||
|
@ -321,11 +321,11 @@ int load_blocklist(char *path)
|
||||
#define S_WEIGHT 100000
|
||||
static int index_name_cmp(const void *n1, const void *n2)
|
||||
{
|
||||
int res = qsort_strcasecmp_hlpr(Friends.list[*(int *) n1].name, Friends.list[*(int *) n2].name);
|
||||
int res = qsort_strcasecmp_hlpr(Friends.list[*(const int *) n1].name, Friends.list[*(const int *) n2].name);
|
||||
|
||||
/* Use weight to make qsort always put online friends before offline */
|
||||
res = Friends.list[*(int *) n1].connection_status ? (res - S_WEIGHT) : (res + S_WEIGHT);
|
||||
res = Friends.list[*(int *) n2].connection_status ? (res + S_WEIGHT) : (res - S_WEIGHT);
|
||||
res = Friends.list[*(const int *) n1].connection_status ? (res - S_WEIGHT) : (res + S_WEIGHT);
|
||||
res = Friends.list[*(const int *) n2].connection_status ? (res + S_WEIGHT) : (res - S_WEIGHT);
|
||||
|
||||
return res;
|
||||
}
|
||||
@ -349,7 +349,7 @@ void sort_friendlist_index(void)
|
||||
|
||||
static int index_name_cmp_block(const void *n1, const void *n2)
|
||||
{
|
||||
return qsort_strcasecmp_hlpr(Blocked.list[*(int *) n1].name, Blocked.list[*(int *) n2].name);
|
||||
return qsort_strcasecmp_hlpr(Blocked.list[*(const int *) n1].name, Blocked.list[*(const int *) n2].name);
|
||||
}
|
||||
|
||||
static void sort_blocklist_index(void)
|
||||
|
@ -288,7 +288,7 @@ int qsort_strcasecmp_hlpr(const void *str1, const void *str2)
|
||||
/* case-insensitive string compare function for use with qsort */
|
||||
int qsort_ptr_char_array_helper(const void *str1, const void *str2)
|
||||
{
|
||||
return strcasecmp(*(char **)str1, *(char **)str2);
|
||||
return strcasecmp(*(const char *const *)str1, *(const char *const *)str2);
|
||||
}
|
||||
|
||||
static const char invalid_chars[] = {'/', '\n', '\t', '\v', '\r', '\0'};
|
||||
|
@ -93,7 +93,7 @@ typedef struct VideoDevice {
|
||||
} VideoDevice;
|
||||
|
||||
const char *dvideo_device_names[2]; /* Default device */
|
||||
const char *video_devices_names[2][MAX_DEVICES]; /* Container of available devices */
|
||||
char *video_devices_names[2][MAX_DEVICES]; /* Container of available devices */
|
||||
static int size[2]; /* Size of above containers */
|
||||
VideoDevice *video_devices_running[2][MAX_DEVICES] = {{NULL}}; /* Running devices */
|
||||
uint32_t primary_video_device[2]; /* Primary device */
|
||||
@ -187,7 +187,7 @@ VideoDeviceError init_video_devices(void)
|
||||
|
||||
#if defined(__OSX__) || defined(__APPLE__)
|
||||
|
||||
if (osx_video_init((char **)video_devices_names[vdt_input], &size[vdt_input]) != 0) {
|
||||
if (osx_video_init(&video_devices_names[vdt_input][0], &size[vdt_input]) != 0) {
|
||||
return vde_InternalError;
|
||||
}
|
||||
|
||||
@ -229,6 +229,9 @@ VideoDeviceError init_video_devices(void)
|
||||
#endif
|
||||
|
||||
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.
|
||||
char *video_output_name = "Toxic Video Receiver";
|
||||
video_devices_names[vdt_output][0] = video_output_name;
|
||||
|
||||
@ -262,7 +265,7 @@ VideoDeviceError terminate_video_devices(void)
|
||||
int i;
|
||||
|
||||
for (i = 0; i < size[vdt_input]; ++i) {
|
||||
free((void *)video_devices_names[vdt_input][i]);
|
||||
free(video_devices_names[vdt_input][i]);
|
||||
}
|
||||
|
||||
if (pthread_mutex_destroy(&video_mutex) != 0) {
|
||||
|
@ -196,7 +196,7 @@ void on_conference_invite(Tox *m, uint32_t friendnumber, Tox_Conference_Type typ
|
||||
|
||||
for (uint8_t i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i] != NULL && windows[i]->onConferenceInvite != NULL) {
|
||||
windows[i]->onConferenceInvite(windows[i], m, friendnumber, type, (char *) conference_pub_key, length);
|
||||
windows[i]->onConferenceInvite(windows[i], m, friendnumber, type, (const char *) conference_pub_key, length);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -281,7 +281,7 @@ void on_file_recv_chunk(Tox *m, uint32_t friendnumber, uint32_t filenumber, uint
|
||||
|
||||
for (uint8_t i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i] != NULL && windows[i]->onFileRecvChunk != NULL) {
|
||||
windows[i]->onFileRecvChunk(windows[i], m, friendnumber, filenumber, position, (char *) data, length);
|
||||
windows[i]->onFileRecvChunk(windows[i], m, friendnumber, filenumber, position, (const char *) data, length);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -322,7 +322,7 @@ void on_file_recv(Tox *m, uint32_t friendnumber, uint32_t filenumber, uint32_t k
|
||||
|
||||
for (uint8_t i = 0; i < MAX_WINDOWS_NUM; ++i) {
|
||||
if (windows[i] != NULL && windows[i]->onFileRecv != NULL) {
|
||||
windows[i]->onFileRecv(windows[i], m, friendnumber, filenumber, file_size, (char *) filename,
|
||||
windows[i]->onFileRecv(windows[i], m, friendnumber, filenumber, file_size, (const char *) filename,
|
||||
filename_length);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user