Fix some minor issues found by cppcheck.
This commit is contained in:
parent
060ab1cd7c
commit
18646deca1
5 changed files with 29 additions and 25 deletions
|
@ -252,8 +252,8 @@ int cmd_invite(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// If a daemon is running, ensure no other nodes know about this name
|
// If a daemon is running, ensure no other nodes know about this name
|
||||||
bool found = false;
|
|
||||||
if(connect_tincd(false)) {
|
if(connect_tincd(false)) {
|
||||||
|
bool found = false;
|
||||||
sendline(fd, "%d %d", CONTROL, REQ_DUMP_NODES);
|
sendline(fd, "%d %d", CONTROL, REQ_DUMP_NODES);
|
||||||
|
|
||||||
while(recvline(fd, line, sizeof line)) {
|
while(recvline(fd, line, sizeof line)) {
|
||||||
|
@ -686,7 +686,7 @@ make_names:
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy the safe variable to the right config file
|
// Copy the safe variable to the right config file
|
||||||
fprintf(variables[i].type & VAR_HOST ? fh : f, "%s = %s\n", l, value);
|
fprintf((variables[i].type & VAR_HOST) ? fh : f, "%s = %s\n", l, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
|
|
|
@ -356,7 +356,7 @@ bool ans_key_h(connection_t *c, const char *request) {
|
||||||
char key[MAX_STRING_SIZE];
|
char key[MAX_STRING_SIZE];
|
||||||
char address[MAX_STRING_SIZE] = "";
|
char address[MAX_STRING_SIZE] = "";
|
||||||
char port[MAX_STRING_SIZE] = "";
|
char port[MAX_STRING_SIZE] = "";
|
||||||
int cipher, digest, maclength, compression, keylen;
|
int cipher, digest, maclength, compression;
|
||||||
node_t *from, *to;
|
node_t *from, *to;
|
||||||
|
|
||||||
if(sscanf(request, "%*d "MAX_STRING" "MAX_STRING" "MAX_STRING" %d %d %d %d "MAX_STRING" "MAX_STRING,
|
if(sscanf(request, "%*d "MAX_STRING" "MAX_STRING" "MAX_STRING" %d %d %d %d "MAX_STRING" "MAX_STRING,
|
||||||
|
@ -489,7 +489,7 @@ bool ans_key_h(connection_t *c, const char *request) {
|
||||||
|
|
||||||
/* Process key */
|
/* Process key */
|
||||||
|
|
||||||
keylen = hex2bin(key, key, sizeof key);
|
int keylen = hex2bin(key, key, sizeof key);
|
||||||
|
|
||||||
if(keylen != (from->outcipher ? cipher_keylength(from->outcipher) : 1)) {
|
if(keylen != (from->outcipher ? cipher_keylength(from->outcipher) : 1)) {
|
||||||
logger(DEBUG_ALWAYS, LOG_ERR, "Node %s (%s) uses wrong keylength!", from->name, from->hostname);
|
logger(DEBUG_ALWAYS, LOG_ERR, "Node %s (%s) uses wrong keylength!", from->name, from->hostname);
|
||||||
|
|
|
@ -510,7 +510,7 @@ static void route_broadcast(node_t *source, vpn_packet_t *packet) {
|
||||||
static void fragment_ipv4_packet(node_t *dest, vpn_packet_t *packet, length_t ether_size) {
|
static void fragment_ipv4_packet(node_t *dest, vpn_packet_t *packet, length_t ether_size) {
|
||||||
struct ip ip;
|
struct ip ip;
|
||||||
vpn_packet_t fragment;
|
vpn_packet_t fragment;
|
||||||
int len, maxlen, todo;
|
int maxlen, todo;
|
||||||
uint8_t *offset;
|
uint8_t *offset;
|
||||||
uint16_t ip_off, origf;
|
uint16_t ip_off, origf;
|
||||||
|
|
||||||
|
@ -537,7 +537,7 @@ static void fragment_ipv4_packet(node_t *dest, vpn_packet_t *packet, length_t et
|
||||||
ip_off &= IP_OFFMASK;
|
ip_off &= IP_OFFMASK;
|
||||||
|
|
||||||
while(todo) {
|
while(todo) {
|
||||||
len = todo > maxlen ? maxlen : todo;
|
int len = todo > maxlen ? maxlen : todo;
|
||||||
memcpy(DATA(&fragment) + ether_size + ip_size, offset, len);
|
memcpy(DATA(&fragment) + ether_size + ip_size, offset, len);
|
||||||
todo -= len;
|
todo -= len;
|
||||||
offset += len;
|
offset += len;
|
||||||
|
|
|
@ -513,7 +513,7 @@ bool recvline(int fd, char *line, size_t len) {
|
||||||
char *newline = NULL;
|
char *newline = NULL;
|
||||||
|
|
||||||
if(!fd)
|
if(!fd)
|
||||||
abort();
|
return false;
|
||||||
|
|
||||||
while(!(newline = memchr(buffer, '\n', blen))) {
|
while(!(newline = memchr(buffer, '\n', blen))) {
|
||||||
int result = recv(fd, buffer + blen, sizeof buffer - blen, 0);
|
int result = recv(fd, buffer + blen, sizeof buffer - blen, 0);
|
||||||
|
@ -951,11 +951,11 @@ static int cmd_stop(int argc, char *argv[]) {
|
||||||
if(!connect_tincd(true)) {
|
if(!connect_tincd(true)) {
|
||||||
if(pid) {
|
if(pid) {
|
||||||
if(kill(pid, SIGTERM)) {
|
if(kill(pid, SIGTERM)) {
|
||||||
fprintf(stderr, "Could not send TERM signal to process with PID %u: %s\n", pid, strerror(errno));
|
fprintf(stderr, "Could not send TERM signal to process with PID %d: %s\n", pid, strerror(errno));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "Sent TERM signal to process with PID %u.\n", pid);
|
fprintf(stderr, "Sent TERM signal to process with PID %d.\n", pid);
|
||||||
waitpid(pid, NULL, 0);
|
waitpid(pid, NULL, 0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1030,7 +1030,6 @@ static int dump_invitations(void) {
|
||||||
FILE *f = fopen(fname, "r");
|
FILE *f = fopen(fname, "r");
|
||||||
if(!f) {
|
if(!f) {
|
||||||
fprintf(stderr, "Cannot open %s: %s\n", fname, strerror(errno));
|
fprintf(stderr, "Cannot open %s: %s\n", fname, strerror(errno));
|
||||||
fclose(f);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2826,8 +2825,6 @@ static int cmd_shell(int argc, char *argv[]) {
|
||||||
|
|
||||||
while(p && *p) {
|
while(p && *p) {
|
||||||
if(nargc >= maxargs) {
|
if(nargc >= maxargs) {
|
||||||
fprintf(stderr, "next %p '%s', p %p '%s'\n", next, next, p, p);
|
|
||||||
abort();
|
|
||||||
maxargs *= 2;
|
maxargs *= 2;
|
||||||
nargv = xrealloc(nargv, maxargs * sizeof *nargv);
|
nargv = xrealloc(nargv, maxargs * sizeof *nargv);
|
||||||
}
|
}
|
||||||
|
|
33
src/top.c
33
src/top.c
|
@ -158,40 +158,47 @@ static int cmpu64(uint64_t a, uint64_t b) {
|
||||||
static int sortfunc(const void *a, const void *b) {
|
static int sortfunc(const void *a, const void *b) {
|
||||||
const nodestats_t *na = *(const nodestats_t **)a;
|
const nodestats_t *na = *(const nodestats_t **)a;
|
||||||
const nodestats_t *nb = *(const nodestats_t **)b;
|
const nodestats_t *nb = *(const nodestats_t **)b;
|
||||||
|
int result;
|
||||||
|
|
||||||
switch(sortmode) {
|
switch(sortmode) {
|
||||||
case 1:
|
case 1:
|
||||||
if(cumulative)
|
if(cumulative)
|
||||||
return -cmpu64(na->in_packets, nb->in_packets) ?: na->i - nb->i;
|
result = -cmpu64(na->in_packets, nb->in_packets);
|
||||||
else
|
else
|
||||||
return -cmpfloat(na->in_packets_rate, nb->in_packets_rate) ?: na->i - nb->i;
|
result = -cmpfloat(na->in_packets_rate, nb->in_packets_rate);
|
||||||
case 2:
|
case 2:
|
||||||
if(cumulative)
|
if(cumulative)
|
||||||
return -cmpu64(na->in_bytes, nb->in_bytes) ?: na->i - nb->i;
|
result = -cmpu64(na->in_bytes, nb->in_bytes);
|
||||||
else
|
else
|
||||||
return -cmpfloat(na->in_bytes_rate, nb->in_bytes_rate) ?: na->i - nb->i;
|
result = -cmpfloat(na->in_bytes_rate, nb->in_bytes_rate);
|
||||||
case 3:
|
case 3:
|
||||||
if(cumulative)
|
if(cumulative)
|
||||||
return -cmpu64(na->out_packets, nb->out_packets) ?: na->i - nb->i;
|
result = -cmpu64(na->out_packets, nb->out_packets);
|
||||||
else
|
else
|
||||||
return -cmpfloat(na->out_packets_rate, nb->out_packets_rate) ?: na->i - nb->i;
|
result = -cmpfloat(na->out_packets_rate, nb->out_packets_rate);
|
||||||
case 4:
|
case 4:
|
||||||
if(cumulative)
|
if(cumulative)
|
||||||
return -cmpu64(na->out_bytes, nb->out_bytes) ?: na->i - nb->i;
|
result = -cmpu64(na->out_bytes, nb->out_bytes);
|
||||||
else
|
else
|
||||||
return -cmpfloat(na->out_bytes_rate, nb->out_bytes_rate) ?: na->i - nb->i;
|
result = -cmpfloat(na->out_bytes_rate, nb->out_bytes_rate);
|
||||||
case 5:
|
case 5:
|
||||||
if(cumulative)
|
if(cumulative)
|
||||||
return -cmpu64(na->in_packets + na->out_packets, nb->in_packets + nb->out_packets) ?: na->i - nb->i;
|
result = -cmpu64(na->in_packets + na->out_packets, nb->in_packets + nb->out_packets);
|
||||||
else
|
else
|
||||||
return -cmpfloat(na->in_packets_rate + na->out_packets_rate, nb->in_packets_rate + nb->out_packets_rate) ?: na->i - nb->i;
|
result = -cmpfloat(na->in_packets_rate + na->out_packets_rate, nb->in_packets_rate + nb->out_packets_rate);
|
||||||
case 6:
|
case 6:
|
||||||
if(cumulative)
|
if(cumulative)
|
||||||
return -cmpu64(na->in_bytes + na->out_bytes, nb->in_bytes + nb->out_bytes) ?: na->i - nb->i;
|
result = -cmpu64(na->in_bytes + na->out_bytes, nb->in_bytes + nb->out_bytes);
|
||||||
else
|
else
|
||||||
return -cmpfloat(na->in_bytes_rate + na->out_bytes_rate, nb->in_bytes_rate + nb->out_bytes_rate) ?: na->i - nb->i;
|
result = -cmpfloat(na->in_bytes_rate + na->out_bytes_rate, nb->in_bytes_rate + nb->out_bytes_rate);
|
||||||
default:
|
default:
|
||||||
return strcmp(na->name, nb->name) ?: na->i - nb->i;
|
result = strcmp(na->name, nb->name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(result)
|
||||||
|
return result;
|
||||||
|
else
|
||||||
|
return na->i - nb->i;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void redraw(void) {
|
static void redraw(void) {
|
||||||
|
|
Loading…
Reference in a new issue