mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Merge pull request #582 from FullName/UnWallWextra
Fix warnings of -Wall -Wextra
This commit is contained in:
commit
d17249a65d
|
@ -90,7 +90,7 @@ void print_friendlist(DHT *dht)
|
||||||
}
|
}
|
||||||
|
|
||||||
int friendok = DHT_getfriendip(dht, dht->friends_list[k].client_id, &p_ip);
|
int friendok = DHT_getfriendip(dht, dht->friends_list[k].client_id, &p_ip);
|
||||||
printf("\nIP: %s:%u", ip_ntoa(&p_ip.ip), ntohs(p_ip.port));
|
printf("\nIP: %s:%u (%d)", ip_ntoa(&p_ip.ip), ntohs(p_ip.port), friendok);
|
||||||
|
|
||||||
printf("\nCLIENTS IN LIST:\n\n");
|
printf("\nCLIENTS IN LIST:\n\n");
|
||||||
|
|
||||||
|
|
|
@ -36,10 +36,9 @@
|
||||||
/* TODO: rewrite */
|
/* TODO: rewrite */
|
||||||
unsigned char *hex_string_to_bin(char hex_string[])
|
unsigned char *hex_string_to_bin(char hex_string[])
|
||||||
{
|
{
|
||||||
size_t len = strlen(hex_string);
|
size_t i, len = strlen(hex_string);
|
||||||
unsigned char *val = malloc(len);
|
unsigned char *val = malloc(len);
|
||||||
char *pos = hex_string;
|
char *pos = hex_string;
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < len; ++i, pos += 2)
|
for (i = 0; i < len; ++i, pos += 2)
|
||||||
sscanf(pos, "%2hhx", &val[i]);
|
sscanf(pos, "%2hhx", &val[i]);
|
||||||
|
|
|
@ -133,10 +133,10 @@ void get_id(Tox *m, char *data)
|
||||||
{
|
{
|
||||||
sprintf(data, "[i] ID: ");
|
sprintf(data, "[i] ID: ");
|
||||||
int offset = strlen(data);
|
int offset = strlen(data);
|
||||||
int i = 0;
|
|
||||||
uint8_t address[TOX_FRIEND_ADDRESS_SIZE];
|
uint8_t address[TOX_FRIEND_ADDRESS_SIZE];
|
||||||
tox_getaddress(m, address);
|
tox_getaddress(m, address);
|
||||||
|
|
||||||
|
uint32_t i = 0;
|
||||||
for (; i < TOX_FRIEND_ADDRESS_SIZE; i++) {
|
for (; i < TOX_FRIEND_ADDRESS_SIZE; i++) {
|
||||||
sprintf(data + 2 * i + offset, "%02X ", address[i]);
|
sprintf(data + 2 * i + offset, "%02X ", address[i]);
|
||||||
}
|
}
|
||||||
|
@ -275,13 +275,13 @@ void line_eval(Tox *m, char *line)
|
||||||
|
|
||||||
char numstring[len - 3];
|
char numstring[len - 3];
|
||||||
char message[len - 3];
|
char message[len - 3];
|
||||||
int i;
|
uint32_t i;
|
||||||
|
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
if (line[i + 3] != ' ') {
|
if (line[i + 3] != ' ') {
|
||||||
numstring[i] = line[i + 3];
|
numstring[i] = line[i + 3];
|
||||||
} else {
|
} else {
|
||||||
int j;
|
uint32_t j;
|
||||||
|
|
||||||
for (j = (i + 1); j < (len + 1); j++)
|
for (j = (i + 1); j < (len + 1); j++)
|
||||||
message[j - i - 1] = line[j + 3];
|
message[j - i - 1] = line[j + 3];
|
||||||
|
@ -299,8 +299,7 @@ void line_eval(Tox *m, char *line)
|
||||||
}
|
}
|
||||||
} else if (inpt_command == 'n') {
|
} else if (inpt_command == 'n') {
|
||||||
uint8_t name[TOX_MAX_NAME_LENGTH];
|
uint8_t name[TOX_MAX_NAME_LENGTH];
|
||||||
int i = 0;
|
size_t i, len = strlen(line);
|
||||||
size_t len = strlen(line);
|
|
||||||
|
|
||||||
for (i = 3; i < len; i++) {
|
for (i = 3; i < len; i++) {
|
||||||
if (line[i] == 0 || line[i] == '\n') break;
|
if (line[i] == 0 || line[i] == '\n') break;
|
||||||
|
@ -317,8 +316,7 @@ void line_eval(Tox *m, char *line)
|
||||||
print_friendlist(m);
|
print_friendlist(m);
|
||||||
} else if (inpt_command == 's') {
|
} else if (inpt_command == 's') {
|
||||||
uint8_t status[TOX_MAX_STATUSMESSAGE_LENGTH];
|
uint8_t status[TOX_MAX_STATUSMESSAGE_LENGTH];
|
||||||
int i = 0;
|
size_t i, len = strlen(line);
|
||||||
size_t len = strlen(line);
|
|
||||||
|
|
||||||
for (i = 3; i < len; i++) {
|
for (i = 3; i < len; i++) {
|
||||||
if (line[i] == 0 || line[i] == '\n') break;
|
if (line[i] == 0 || line[i] == '\n') break;
|
||||||
|
@ -399,8 +397,7 @@ void line_eval(Tox *m, char *line)
|
||||||
void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width)
|
void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width)
|
||||||
{
|
{
|
||||||
strcpy(output, input);
|
strcpy(output, input);
|
||||||
size_t len = strlen(output);
|
size_t i, len = strlen(output);
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
for (i = line_width; i < len; i = i + line_width) {
|
for (i = line_width; i < len; i = i + line_width) {
|
||||||
while (output[i] != ' ' && i != 0) {
|
while (output[i] != ' ' && i != 0) {
|
||||||
|
@ -415,9 +412,8 @@ void wrap(char output[STRING_LENGTH], char input[STRING_LENGTH], int line_width)
|
||||||
|
|
||||||
int count_lines(char *string)
|
int count_lines(char *string)
|
||||||
{
|
{
|
||||||
size_t len = strlen(string);
|
size_t i, len = strlen(string);
|
||||||
int count = 1;
|
int count = 1;
|
||||||
int i;
|
|
||||||
|
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
if (string[i] == '\n')
|
if (string[i] == '\n')
|
||||||
|
@ -511,7 +507,7 @@ static char *data_file_name = NULL;
|
||||||
static int load_data(Tox *m)
|
static int load_data(Tox *m)
|
||||||
{
|
{
|
||||||
FILE *data_file = fopen(data_file_name, "r");
|
FILE *data_file = fopen(data_file_name, "r");
|
||||||
int size = 0;
|
size_t size = 0;
|
||||||
if (data_file) {
|
if (data_file) {
|
||||||
fseek(data_file, 0, SEEK_END);
|
fseek(data_file, 0, SEEK_END);
|
||||||
size = ftell(data_file);
|
size = ftell(data_file);
|
||||||
|
@ -520,6 +516,7 @@ static int load_data(Tox *m)
|
||||||
uint8_t data[size];
|
uint8_t data[size];
|
||||||
if (fread(data, sizeof(uint8_t), size, data_file) != size) {
|
if (fread(data, sizeof(uint8_t), size, data_file) != size) {
|
||||||
fputs("[!] could not read data file!\n", stderr);
|
fputs("[!] could not read data file!\n", stderr);
|
||||||
|
fclose(data_file);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -545,19 +542,22 @@ static int save_data(Tox *m)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int size = tox_size(m);
|
int res = 1;
|
||||||
|
size_t size = tox_size(m);
|
||||||
uint8_t data[size];
|
uint8_t data[size];
|
||||||
tox_save(m, data);
|
tox_save(m, data);
|
||||||
|
|
||||||
if (fwrite(data, sizeof(uint8_t), size, data_file) != size) {
|
if (fwrite(data, sizeof(uint8_t), size, data_file) != size) {
|
||||||
fputs("[!] could not write data file (1)!", stderr);
|
fputs("[!] could not write data file (1)!", stderr);
|
||||||
return 0;
|
res = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fclose(data_file) < 0) {
|
if (fclose(data_file) < 0) {
|
||||||
perror("[!] could not write data file (2)");
|
perror("[!] could not write data file (2)");
|
||||||
return 0;
|
res = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int load_data_or_init(Tox *m, char *path)
|
static int load_data_or_init(Tox *m, char *path)
|
||||||
|
@ -667,7 +667,7 @@ int main(int argc, char *argv[])
|
||||||
nodelay(stdscr, TRUE);
|
nodelay(stdscr, TRUE);
|
||||||
|
|
||||||
new_lines("[i] change username with /n");
|
new_lines("[i] change username with /n");
|
||||||
char name[TOX_MAX_NAME_LENGTH];
|
uint8_t name[TOX_MAX_NAME_LENGTH];
|
||||||
uint16_t namelen = tox_getselfname(m, name, sizeof(name));
|
uint16_t namelen = tox_getselfname(m, name, sizeof(name));
|
||||||
if (namelen > 0) {
|
if (namelen > 0) {
|
||||||
char whoami[128 + TOX_MAX_NAME_LENGTH];
|
char whoami[128 + TOX_MAX_NAME_LENGTH];
|
||||||
|
|
|
@ -200,8 +200,8 @@ static void get_close_nodes_inner(DHT *dht, uint8_t *client_id, Node_format *nod
|
||||||
time_t timestamp, int *num_nodes_ptr)
|
time_t timestamp, int *num_nodes_ptr)
|
||||||
{
|
{
|
||||||
int num_nodes = *num_nodes_ptr;
|
int num_nodes = *num_nodes_ptr;
|
||||||
int i, tout, inlist, ipv46x, j, closest;
|
int tout, inlist, ipv46x, j, closest;
|
||||||
|
uint32_t i;
|
||||||
for (i = 0; i < client_list_length; i++) {
|
for (i = 0; i < client_list_length; i++) {
|
||||||
Client_data *client = &client_list[i];
|
Client_data *client = &client_list[i];
|
||||||
tout = is_timeout(timestamp, client->timestamp, BAD_NODE_TIMEOUT);
|
tout = is_timeout(timestamp, client->timestamp, BAD_NODE_TIMEOUT);
|
||||||
|
@ -726,10 +726,10 @@ static int handle_sendnodes(void *object, IP_Port source, uint8_t *packet, uint3
|
||||||
#ifdef TOX_ENABLE_IPV6
|
#ifdef TOX_ENABLE_IPV6
|
||||||
Node4_format *nodes4_list = (Node4_format *)(plain + sizeof(ping_id));
|
Node4_format *nodes4_list = (Node4_format *)(plain + sizeof(ping_id));
|
||||||
|
|
||||||
int num_nodes_ok = 0;
|
uint32_t num_nodes_ok = 0;
|
||||||
|
|
||||||
for (i = 0; i < num_nodes; i++)
|
for (i = 0; i < num_nodes; i++)
|
||||||
if ((nodes4_list[i].ip_port.ip.uint32 != 0) && (nodes4_list[i].ip_port.ip.uint32 != ~0)) {
|
if ((nodes4_list[i].ip_port.ip.uint32 != 0) && (nodes4_list[i].ip_port.ip.uint32 != (uint32_t)~0)) {
|
||||||
memcpy(nodes_list[num_nodes_ok].client_id, nodes4_list[i].client_id, CLIENT_ID_SIZE);
|
memcpy(nodes_list[num_nodes_ok].client_id, nodes4_list[i].client_id, CLIENT_ID_SIZE);
|
||||||
nodes_list[num_nodes_ok].ip_port.ip.family = AF_INET;
|
nodes_list[num_nodes_ok].ip_port.ip.family = AF_INET;
|
||||||
nodes_list[num_nodes_ok].ip_port.ip.ip4.uint32 = nodes4_list[i].ip_port.ip.uint32;
|
nodes_list[num_nodes_ok].ip_port.ip.ip4.uint32 = nodes4_list[i].ip_port.ip.uint32;
|
||||||
|
@ -1477,14 +1477,14 @@ void DHT_save(DHT *dht, uint8_t *data)
|
||||||
int DHT_load(DHT *dht, uint8_t *data, uint32_t size)
|
int DHT_load(DHT *dht, uint8_t *data, uint32_t size)
|
||||||
{
|
{
|
||||||
if (size < sizeof(dht->close_clientlist)) {
|
if (size < sizeof(dht->close_clientlist)) {
|
||||||
fprintf(stderr, "DHT_load: Expected at least %lu bytes, got %u.\n", sizeof(dht->close_clientlist), size);
|
fprintf(stderr, "DHT_load: Expected at least %u bytes, got %u.\n", sizeof(dht->close_clientlist), size);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t friendlistsize = size - sizeof(dht->close_clientlist);
|
uint32_t friendlistsize = size - sizeof(dht->close_clientlist);
|
||||||
|
|
||||||
if (friendlistsize % sizeof(DHT_Friend) != 0) {
|
if (friendlistsize % sizeof(DHT_Friend) != 0) {
|
||||||
fprintf(stderr, "DHT_load: Expected a multiple of %lu, got %u.\n", sizeof(DHT_Friend), friendlistsize);
|
fprintf(stderr, "DHT_load: Expected a multiple of %u, got %u.\n", sizeof(DHT_Friend), friendlistsize);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1220,7 +1220,7 @@ void doInbound(Messenger *m)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef LOGGING
|
#ifdef LOGGING
|
||||||
#define DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS 60
|
#define DUMPING_CLIENTS_FRIENDS_EVERY_N_SECONDS 60UL
|
||||||
static time_t lastdump = 0;
|
static time_t lastdump = 0;
|
||||||
static char IDString[CLIENT_ID_SIZE * 2 + 1];
|
static char IDString[CLIENT_ID_SIZE * 2 + 1];
|
||||||
static char *ID2String(uint8_t *client_id)
|
static char *ID2String(uint8_t *client_id)
|
||||||
|
|
|
@ -154,14 +154,15 @@ static int receivepacket(sock_t sock, IP_Port *ip_port, uint8_t *data, uint32_t
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
int addrlen = sizeof(addr);
|
int addrlen = sizeof(addr);
|
||||||
#else
|
#else
|
||||||
uint32_t addrlen = sizeof(addr);
|
socklen_t addrlen = sizeof(addr);
|
||||||
#endif
|
#endif
|
||||||
(*(int32_t *)length) = recvfrom(sock, (char *) data, MAX_UDP_PACKET_SIZE, 0, (struct sockaddr *)&addr, &addrlen);
|
*length = 0;
|
||||||
|
int fail_or_len = recvfrom(sock, (char *) data, MAX_UDP_PACKET_SIZE, 0, (struct sockaddr *)&addr, &addrlen);
|
||||||
|
|
||||||
if (*(int32_t *)length <= 0) {
|
if (fail_or_len <= 0) {
|
||||||
#ifdef LOGGING
|
#ifdef LOGGING
|
||||||
|
|
||||||
if ((length < 0) && (errno != EWOULDBLOCK)) {
|
if ((fail_or_len < 0) && (errno != EWOULDBLOCK)) {
|
||||||
sprintf(logbuffer, "Unexpected error reading from socket: %u, %s\n", errno, strerror(errno));
|
sprintf(logbuffer, "Unexpected error reading from socket: %u, %s\n", errno, strerror(errno));
|
||||||
loglog(logbuffer);
|
loglog(logbuffer);
|
||||||
}
|
}
|
||||||
|
@ -170,6 +171,8 @@ static int receivepacket(sock_t sock, IP_Port *ip_port, uint8_t *data, uint32_t
|
||||||
return -1; /* Nothing received or empty packet. */
|
return -1; /* Nothing received or empty packet. */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*length = (uint32_t)fail_or_len;
|
||||||
|
|
||||||
#ifdef TOX_ENABLE_IPV6
|
#ifdef TOX_ENABLE_IPV6
|
||||||
|
|
||||||
if (addr.ss_family == AF_INET) {
|
if (addr.ss_family == AF_INET) {
|
||||||
|
@ -863,15 +866,15 @@ static void loglogdata(char *message, uint8_t *buffer, size_t buflen, IP_Port *i
|
||||||
ip_ntoa(&ip_port->ip), ntohs(ip_port->port), errno,
|
ip_ntoa(&ip_port->ip), ntohs(ip_port->port), errno,
|
||||||
strerror(errno), buflen > 4 ? ntohl(*(uint32_t *)&buffer[1]) : 0,
|
strerror(errno), buflen > 4 ? ntohl(*(uint32_t *)&buffer[1]) : 0,
|
||||||
buflen > 7 ? ntohl(*(uint32_t *)(&buffer[5])) : 0);
|
buflen > 7 ? ntohl(*(uint32_t *)(&buffer[5])) : 0);
|
||||||
else if ((res > 0) && (res <= buflen))
|
else if ((res > 0) && ((size_t)res <= buflen))
|
||||||
snprintf(logbuffer, sizeof(logbuffer), "[%2u] %s %3u%c %s:%u (%u: %s) | %04x%04x\n",
|
snprintf(logbuffer, sizeof(logbuffer), "[%2u] %s %3u%c %s:%u (%u: %s) | %04x%04x\n",
|
||||||
buffer[0], message, res < 999 ? res : 999, res < buflen ? '<' : '=',
|
buffer[0], message, res < 999 ? res : 999, (size_t)res < buflen ? '<' : '=',
|
||||||
ip_ntoa(&ip_port->ip), ntohs(ip_port->port), 0,
|
ip_ntoa(&ip_port->ip), ntohs(ip_port->port), 0,
|
||||||
"OK", buflen > 4 ? ntohl(*(uint32_t *)&buffer[1]) : 0,
|
"OK", buflen > 4 ? ntohl(*(uint32_t *)&buffer[1]) : 0,
|
||||||
buflen > 7 ? ntohl(*(uint32_t *)(&buffer[5])) : 0);
|
buflen > 7 ? ntohl(*(uint32_t *)(&buffer[5])) : 0);
|
||||||
else /* empty or overwrite */
|
else /* empty or overwrite */
|
||||||
snprintf(logbuffer, sizeof(logbuffer), "[%2u] %s %u%c%u %s:%u (%u: %s) | %04x%04x\n",
|
snprintf(logbuffer, sizeof(logbuffer), "[%2u] %s %u%c%u %s:%u (%u: %s) | %04x%04x\n",
|
||||||
buffer[0], message, res, !res ? '0' : '>', buflen,
|
buffer[0], message, res, !res ? '!' : '>', buflen,
|
||||||
ip_ntoa(&ip_port->ip), ntohs(ip_port->port), 0,
|
ip_ntoa(&ip_port->ip), ntohs(ip_port->port), 0,
|
||||||
"OK", buflen > 4 ? ntohl(*(uint32_t *)&buffer[1]) : 0,
|
"OK", buflen > 4 ? ntohl(*(uint32_t *)&buffer[1]) : 0,
|
||||||
buflen > 7 ? ntohl(*(uint32_t *)(&buffer[5])) : 0);
|
buflen > 7 ? ntohl(*(uint32_t *)(&buffer[5])) : 0);
|
||||||
|
|
|
@ -52,14 +52,14 @@ void loginit(uint16_t port)
|
||||||
if (logfile)
|
if (logfile)
|
||||||
fclose(logfile);
|
fclose(logfile);
|
||||||
|
|
||||||
sprintf(logbuffer, "%u-%u.log", ntohs(port), now());
|
sprintf(logbuffer, "%u-%u.log", ntohs(port), (uint32_t)now());
|
||||||
logfile = fopen(logbuffer, "w");
|
logfile = fopen(logbuffer, "w");
|
||||||
starttime = now();
|
starttime = now();
|
||||||
};
|
};
|
||||||
void loglog(char *text)
|
void loglog(char *text)
|
||||||
{
|
{
|
||||||
if (logfile) {
|
if (logfile) {
|
||||||
fprintf(logfile, "%4u ", now() - starttime);
|
fprintf(logfile, "%4u ", (uint32_t)(now() - starttime));
|
||||||
fprintf(logfile, text);
|
fprintf(logfile, text);
|
||||||
fflush(logfile);
|
fflush(logfile);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user