Proper struct initialization

Detected by clang -Wmissing-field-initializers
This commit is contained in:
thorkill 2015-06-29 23:30:18 +02:00
parent 7099a4437e
commit bc8dbfc9fd
12 changed files with 105 additions and 59 deletions

View file

@ -65,7 +65,8 @@ static bool setup_device(void) {
fcntl(device_fd, F_SETFD, FD_CLOEXEC);
#endif
struct ifreq ifr = {{{0}}};
struct ifreq ifr;
memset(&ifr, 0x0, sizeof(struct ifreq));
get_config_string(lookup_config(config_tree, "DeviceType"), &type);

View file

@ -447,11 +447,17 @@ int main_loop(void) {
timeout_add(&periodictimer, periodic_handler, &periodictimer, &(struct timeval){pingtimeout, rand() % 100000});
#ifndef HAVE_MINGW
signal_t sighup = {0};
signal_t sigterm = {0};
signal_t sigquit = {0};
signal_t sigint = {0};
signal_t sigalrm = {0};
signal_t sighup;
signal_t sigterm;
signal_t sigquit;
signal_t sigint;
signal_t sigalrm;
memset(&sighup, 0x0, sizeof(signal_t));
memset(&sigterm, 0x0, sizeof(signal_t));
memset(&sigquit, 0x0, sizeof(signal_t));
memset(&sigint, 0x0, sizeof(signal_t));
memset(&sigalrm, 0x0, sizeof(signal_t));
signal_add(&sighup, sighup_handler, &sighup, SIGHUP);
signal_add(&sigterm, sigterm_handler, &sigterm, SIGTERM);

View file

@ -687,7 +687,11 @@ static bool add_listen_address(char *address, bool bindto) {
*address = 0;
}
struct addrinfo *ai, hint = {0};
struct addrinfo *ai, hint;
ai = NULL;
memset(&hint, 0x0, sizeof(struct addrinfo));
hint.ai_family = addressfamily;
hint.ai_socktype = SOCK_STREAM;
hint.ai_protocol = IPPROTO_TCP;

View file

@ -33,9 +33,13 @@ bool hostnames = false;
Return NULL on failure.
*/
struct addrinfo *str2addrinfo(const char *address, const char *service, int socktype) {
struct addrinfo *ai, hint = {0};
struct addrinfo *ai, hint;
int err;
ai = NULL;
memset(&hint, 0x0, sizeof(struct addrinfo));
hint.ai_family = addressfamily;
hint.ai_socktype = socktype;
@ -53,10 +57,15 @@ struct addrinfo *str2addrinfo(const char *address, const char *service, int sock
}
sockaddr_t str2sockaddr(const char *address, const char *port) {
struct addrinfo *ai, hint = {0};
sockaddr_t result = {{0}};
struct addrinfo *ai, hint;
sockaddr_t result;
int err;
ai = NULL;
memset(&hint, 0x0, sizeof(struct addrinfo));
memset(&result, 0x0, sizeof(sockaddr_t));
hint.ai_family = AF_UNSPEC;
hint.ai_flags = AI_NUMERICHOST;
hint.ai_socktype = SOCK_STREAM;

View file

@ -130,7 +130,9 @@ void node_del(node_t *n) {
}
node_t *lookup_node(char *name) {
node_t n = {NULL};
node_t n;
memset(&n, 0x0, sizeof(node_t));
n.name = name;

View file

@ -179,7 +179,10 @@ static void age_past_requests(void *data) {
}
bool seen_request(const char *request) {
past_request_t *new, p = {NULL};
past_request_t *new, p;
new = NULL;
memset(&p, 0x0, sizeof(past_request_t));
p.request = request;

View file

@ -70,12 +70,16 @@ bool add_edge_h(connection_t *c, const char *request) {
char to_port[MAX_STRING_SIZE];
char address_local[MAX_STRING_SIZE];
char port_local[MAX_STRING_SIZE];
sockaddr_t address, local_address = {{0}};
sockaddr_t address, local_address;
uint32_t options;
int weight;
memset(&address, 0x0, sizeof(sockaddr_t));
memset(&local_address, 0x0, sizeof(sockaddr_t));
int parameter_count = sscanf(request, "%*d %*x "MAX_STRING" "MAX_STRING" "MAX_STRING" "MAX_STRING" %x %d "MAX_STRING" "MAX_STRING,
from_name, to_name, to_address, to_port, &options, &weight, address_local, port_local);
if (parameter_count != 6 && parameter_count != 8) {
logger(DEBUG_ALWAYS, LOG_ERR, "Got bad %s from %s (%s)", "ADD_EDGE", c->name,
c->hostname);

View file

@ -45,7 +45,11 @@ bool add_subnet_h(connection_t *c, const char *request) {
char subnetstr[MAX_STRING_SIZE];
char name[MAX_STRING_SIZE];
node_t *owner;
subnet_t s = {NULL}, *new, *old;
subnet_t s, *new, *old;
new = NULL;
old = NULL;
memset(&s, 0x0, sizeof(subnet_t));
if(sscanf(request, "%*d %*x " MAX_STRING " " MAX_STRING, name, subnetstr) != 2) {
logger(DEBUG_ALWAYS, LOG_ERR, "Got bad %s from %s (%s)", "ADD_SUBNET", c->name,
@ -155,7 +159,10 @@ bool del_subnet_h(connection_t *c, const char *request) {
char subnetstr[MAX_STRING_SIZE];
char name[MAX_STRING_SIZE];
node_t *owner;
subnet_t s = {NULL}, *find;
subnet_t s, *find;
find = NULL;
memset(&s, 0x0, sizeof(subnet_t));
if(sscanf(request, "%*d %*x " MAX_STRING " " MAX_STRING, name, subnetstr) != 2) {
logger(DEBUG_ALWAYS, LOG_ERR, "Got bad %s from %s (%s)", "DEL_SUBNET", c->name,

View file

@ -251,13 +251,17 @@ static void learn_mac(mac_t *address) {
/* RFC 792 */
static void route_ipv4_unreachable(node_t *source, vpn_packet_t *packet, length_t ether_size, uint8_t type, uint8_t code) {
struct ip ip = {0};
struct icmp icmp = {0};
struct ip ip;
struct icmp icmp;
struct in_addr ip_src;
struct in_addr ip_dst;
uint32_t oldlen;
memset(&ip, 0x0, sizeof(struct ip));
memset(&icmp, 0x0, sizeof(struct icmp));
if(ratelimit(3))
return;
@ -445,9 +449,12 @@ static void route_ipv4(node_t *source, vpn_packet_t *packet) {
static void route_ipv6_unreachable(node_t *source, vpn_packet_t *packet, length_t ether_size, uint8_t type, uint8_t code) {
struct ip6_hdr ip6;
struct icmp6_hdr icmp6 = {0};
struct icmp6_hdr icmp6;
uint16_t checksum;
memset(&ip6, 0x0, sizeof(struct ip6_hdr));
memset(&icmp6, 0x0, sizeof(struct icmp6_hdr));
struct {
struct in6_addr ip6_src; /* source address */
struct in6_addr ip6_dst; /* destination address */

View file

@ -25,10 +25,13 @@
/* Splay operation */
static splay_node_t *splay_top_down(splay_tree_t *tree, const void *data, int *result) {
splay_node_t left = {NULL}, right = {NULL};
splay_node_t *leftbottom = &left, *rightbottom = &right, *child, *grandchild;
splay_node_t left, right;
splay_node_t *leftbottom = &left, *rightbottom = &right, *child = NULL, *grandchild = NULL;
splay_node_t *root = tree->root;
int c;
int c = -1;
memset(&left, 0x0, sizeof(splay_node_t));
memset(&right, 0x0, sizeof(splay_node_t));
if(!root) {
if(result)

View file

@ -139,7 +139,7 @@ int main(int argc, char *argv[]) {
return 1;
}
struct pollfd pfd[2] = {{fd[0], POLLIN}, {fd[1], POLLIN}};
struct pollfd pfd[2] = {{fd[0], POLLIN, NULL}, {fd[1], POLLIN, NULL}};
fprintf(stderr, "SPTPS/TCP authenticate for %lg seconds: ", duration);
for(clock_start(); clock_countto(duration);) {

View file

@ -2326,46 +2326,46 @@ static const struct {
int (*function)(int argc, char *argv[]);
bool hidden;
} commands[] = {
{"start", cmd_start},
{"stop", cmd_stop},
{"restart", cmd_restart},
{"reload", cmd_reload},
{"dump", cmd_dump},
{"list", cmd_dump},
{"purge", cmd_purge},
{"debug", cmd_debug},
{"retry", cmd_retry},
{"connect", cmd_connect},
{"disconnect", cmd_disconnect},
{"top", cmd_top},
{"pcap", cmd_pcap},
{"log", cmd_log},
{"pid", cmd_pid},
{"start", cmd_start, false},
{"stop", cmd_stop, false},
{"restart", cmd_restart, false},
{"reload", cmd_reload, false},
{"dump", cmd_dump, false},
{"list", cmd_dump, false},
{"purge", cmd_purge, false},
{"debug", cmd_debug, false},
{"retry", cmd_retry, false},
{"connect", cmd_connect, false},
{"disconnect", cmd_disconnect, false},
{"top", cmd_top, false},
{"pcap", cmd_pcap, false},
{"log", cmd_log, false},
{"pid", cmd_pid, false},
{"config", cmd_config, true},
{"add", cmd_config},
{"del", cmd_config},
{"get", cmd_config},
{"set", cmd_config},
{"init", cmd_init},
{"generate-keys", cmd_generate_keys},
{"add", cmd_config, false},
{"del", cmd_config, false},
{"get", cmd_config, false},
{"set", cmd_config, false},
{"init", cmd_init, false},
{"generate-keys", cmd_generate_keys, false},
#ifndef DISABLE_LEGACY
{"generate-rsa-keys", cmd_generate_rsa_keys},
{"generate-rsa-keys", cmd_generate_rsa_keys, false},
#endif
{"generate-ed25519-keys", cmd_generate_ed25519_keys},
{"help", cmd_help},
{"version", cmd_version},
{"info", cmd_info},
{"edit", cmd_edit},
{"export", cmd_export},
{"export-all", cmd_export_all},
{"import", cmd_import},
{"exchange", cmd_exchange},
{"exchange-all", cmd_exchange_all},
{"invite", cmd_invite},
{"join", cmd_join},
{"network", cmd_network},
{"fsck", cmd_fsck},
{NULL, NULL},
{"generate-ed25519-keys", cmd_generate_ed25519_keys, false},
{"help", cmd_help, false},
{"version", cmd_version, false},
{"info", cmd_info, false},
{"edit", cmd_edit, false},
{"export", cmd_export, false},
{"export-all", cmd_export_all, false},
{"import", cmd_import, false},
{"exchange", cmd_exchange, false},
{"exchange-all", cmd_exchange_all, false},
{"invite", cmd_invite, false},
{"join", cmd_join, false},
{"network", cmd_network, false},
{"fsck", cmd_fsck, false},
{NULL, NULL, NULL},
};
#ifdef HAVE_READLINE