From 985d19caf20058db3c764f0f6fbeafa8bcc59fcc Mon Sep 17 00:00:00 2001 From: Guus Sliepen Date: Sat, 7 Oct 2017 17:46:52 +0200 Subject: [PATCH] Convert sizeof foo to sizeof(foo). While technically sizeof is an operator and doesn't need the parentheses around expressions it operates on, except if they are type names, code formatters don't seem to handle this very well. --- src/bsd/device.c | 16 ++++++++-------- src/conf.c | 22 +++++++++++----------- src/connection.c | 2 +- src/graph.c | 2 +- src/logger.c | 4 ++-- src/multicast_device.c | 24 ++++++++++++------------ src/net.c | 2 +- src/net_packet.c | 6 +++--- src/net_setup.c | 6 +++--- src/net_socket.c | 8 ++++---- src/node.c | 4 ++-- src/process.c | 16 ++++++++-------- src/protocol.c | 6 +++--- src/protocol_subnet.c | 4 ++-- src/proxy.c | 10 +++++----- src/route.c | 16 ++++++++-------- src/solaris/device.c | 8 ++++---- src/subnet.c | 20 ++++++++++---------- src/tincd.c | 6 +++--- src/uml_device.c | 22 +++++++++++----------- src/utils.c | 4 ++-- src/xalloc.h | 2 +- 22 files changed, 105 insertions(+), 105 deletions(-) diff --git a/src/bsd/device.c b/src/bsd/device.c index 95e65f9c..f6614b29 100644 --- a/src/bsd/device.c +++ b/src/bsd/device.c @@ -75,7 +75,7 @@ static bool setup_utun(void) { } struct ctl_info info = {}; - strlcpy(info.ctl_name, UTUN_CONTROL_NAME, sizeof info.ctl_name); + strlcpy(info.ctl_name, UTUN_CONTROL_NAME, sizeof(info.ctl_name)); if(ioctl(device_fd, CTLIOCGINFO, &info) == -1) { logger(LOG_ERR, "ioctl(CTLIOCGINFO) failed: %s", strerror(errno)); @@ -92,7 +92,7 @@ static bool setup_utun(void) { struct sockaddr_ctl sc = { .sc_id = info.ctl_id, - .sc_len = sizeof sc, + .sc_len = sizeof(sc), .sc_family = AF_SYSTEM, .ss_sysaddr = AF_SYS_CONTROL, .sc_unit = unit + 1, @@ -104,7 +104,7 @@ static bool setup_utun(void) { } char name[64] = ""; - socklen_t len = sizeof name; + socklen_t len = sizeof(name); if(getsockopt(device_fd, SYSPROTO_CONTROL, UTUN_OPT_IFNAME, name, &len)) { iface = xstrdup(device); } else { @@ -225,7 +225,7 @@ static bool setup_device(void) { #ifdef TUNSIFHEAD { const int zero = 0; - if(ioctl(device_fd, TUNSIFHEAD, &zero, sizeof zero) == -1) { + if(ioctl(device_fd, TUNSIFHEAD, &zero, sizeof(zero)) == -1) { logger(LOG_ERR, "System call `%s' failed: %s", "ioctl", strerror(errno)); return false; } @@ -234,7 +234,7 @@ static bool setup_device(void) { #if defined(TUNSIFMODE) && defined(IFF_BROADCAST) && defined(IFF_MULTICAST) { const int mode = IFF_BROADCAST | IFF_MULTICAST; - ioctl(device_fd, TUNSIFMODE, &mode, sizeof mode); + ioctl(device_fd, TUNSIFMODE, &mode, sizeof(mode)); } #endif @@ -244,7 +244,7 @@ static bool setup_device(void) { #ifdef TUNSIFHEAD { const int one = 1; - if(ioctl(device_fd, TUNSIFHEAD, &one, sizeof one) == -1) { + if(ioctl(device_fd, TUNSIFHEAD, &one, sizeof(one)) == -1) { logger(LOG_ERR, "System call `%s' failed: %s", "ioctl", strerror(errno)); return false; } @@ -253,7 +253,7 @@ static bool setup_device(void) { #if defined(TUNSIFMODE) && defined(IFF_BROADCAST) && defined(IFF_MULTICAST) { const int mode = IFF_BROADCAST | IFF_MULTICAST; - ioctl(device_fd, TUNSIFMODE, &mode, sizeof mode); + ioctl(device_fd, TUNSIFMODE, &mode, sizeof(mode)); } #endif @@ -429,7 +429,7 @@ static bool write_packet(vpn_packet_t *packet) { return false; } - memcpy(packet->data + 10, &type, sizeof type); + memcpy(packet->data + 10, &type, sizeof(type)); if(write(device_fd, packet->data + 10, packet->len - 10) < 0) { logger(LOG_ERR, "Can't write to %s %s: %s", device_info, device, diff --git a/src/conf.c b/src/conf.c index 1c250d7b..82bc5216 100644 --- a/src/conf.c +++ b/src/conf.c @@ -303,7 +303,7 @@ bool read_config_file(avl_tree_t *config_tree, const char *fname) { } for(;;) { - line = readline(fp, buffer, sizeof buffer); + line = readline(fp, buffer, sizeof(buffer)); if(!line) { if(feof(fp)) @@ -375,14 +375,14 @@ bool read_server_config(void) { read_config_options(config_tree, NULL); - snprintf(fname, sizeof fname, "%s/tinc.conf", confbase); + snprintf(fname, sizeof(fname), "%s/tinc.conf", confbase); errno = 0; x = read_config_file(config_tree, fname); // We will try to read the conf files in the "conf.d" dir if (x) { char dname[PATH_MAX]; - snprintf(dname, sizeof dname, "%s/conf.d", confbase); + snprintf(dname, sizeof(dname), "%s/conf.d", confbase); DIR *dir = opendir (dname); // If we can find this dir if (dir) { @@ -392,7 +392,7 @@ bool read_server_config(void) { size_t l = strlen(ep->d_name); // And we try to read the ones that end with ".conf" if (l > 5 && !strcmp(".conf", & ep->d_name[ l - 5 ])) { - snprintf(fname, sizeof fname, "%s/%s", dname, ep->d_name); + snprintf(fname, sizeof(fname), "%s/%s", dname, ep->d_name); x = read_config_file(config_tree, fname); } } @@ -413,7 +413,7 @@ bool read_connection_config(connection_t *c) { read_config_options(c->config_tree, c->name); - snprintf(fname, sizeof fname, "%s/hosts/%s", confbase, c->name); + snprintf(fname, sizeof(fname), "%s/hosts/%s", confbase, c->name); x = read_config_file(c->config_tree, fname); return x; @@ -429,11 +429,11 @@ static void disable_old_keys(const char *filename) { if(!r) return; - snprintf(tmpfile, sizeof tmpfile, "%s.tmp", filename); + snprintf(tmpfile, sizeof(tmpfile), "%s.tmp", filename); w = fopen(tmpfile, "w"); - while(fgets(buf, sizeof buf, r)) { + while(fgets(buf, sizeof(buf), r)) { if(!strncmp(buf, "-----BEGIN RSA", 14)) { buf[11] = 'O'; buf[12] = 'L'; @@ -465,7 +465,7 @@ static void disable_old_keys(const char *filename) { #ifdef HAVE_MINGW // We cannot atomically replace files on Windows. char bakfile[PATH_MAX] = ""; - snprintf(bakfile, sizeof bakfile, "%s.bak", filename); + snprintf(bakfile, sizeof(bakfile), "%s.bak", filename); if(rename(filename, bakfile) || rename(tmpfile, filename)) { rename(bakfile, filename); #else @@ -502,7 +502,7 @@ FILE *ask_and_open(const char *filename, const char *what) { what, filename); fflush(stdout); - fn = readline(stdin, line, sizeof line); + fn = readline(stdin, line, sizeof(line)); if(!fn) { fprintf(stderr, "Error while reading stdin: %s\n", @@ -521,8 +521,8 @@ FILE *ask_and_open(const char *filename, const char *what) { if(fn[0] != '/') { #endif /* The directory is a relative path or a filename. */ - getcwd(directory, sizeof directory); - snprintf(abspath, sizeof abspath, "%s/%s", directory, fn); + getcwd(directory, sizeof(directory)); + snprintf(abspath, sizeof(abspath), "%s/%s", directory, fn); fn = abspath; } diff --git a/src/connection.c b/src/connection.c index d27e6fd3..46b11c85 100644 --- a/src/connection.c +++ b/src/connection.c @@ -141,7 +141,7 @@ void dump_connections(void) { for(node = connection_tree->head; node; node = node->next) { c = node->data; logger(LOG_DEBUG, " %s at %s options %x socket %d status %04x outbuf %d/%d/%d", - c->name, c->hostname, c->options, c->socket, bitfield_to_int(&c->status, sizeof c->status), + c->name, c->hostname, c->options, c->socket, bitfield_to_int(&c->status, sizeof(c->status)), c->outbufsize, c->outbufstart, c->outbuflen); } diff --git a/src/graph.c b/src/graph.c index 8ffd70e4..5b90c625 100644 --- a/src/graph.c +++ b/src/graph.c @@ -293,7 +293,7 @@ static void sssp_bfs(void) { if(!n->status.reachable) { update_node_udp(n, NULL); - memset(&n->status, 0, sizeof n->status); + memset(&n->status, 0, sizeof(n->status)); n->options = 0; } else if(n->connection) { send_ans_key(n); diff --git a/src/logger.c b/src/logger.c index 3f60edba..77c81339 100644 --- a/src/logger.c +++ b/src/logger.c @@ -97,7 +97,7 @@ void logger(int priority, const char *format, ...) { break; case LOGMODE_FILE: now = time(NULL); - strftime(timestr, sizeof timestr, "%Y-%m-%d %H:%M:%S", localtime(&now)); + strftime(timestr, sizeof(timestr), "%Y-%m-%d %H:%M:%S", localtime(&now)); fprintf(logfile, "%s %s[%ld]: ", timestr, logident, (long)logpid); vfprintf(logfile, format, ap); fprintf(logfile, "\n"); @@ -109,7 +109,7 @@ void logger(int priority, const char *format, ...) { char message[4096]; const char *messages[] = {message}; vsnprintf(message, sizeof(message), format, ap); - message[sizeof message - 1] = 0; + message[sizeof(message) - 1] = 0; ReportEvent(loghandle, priority, 0, 0, NULL, 1, 0, messages, NULL); } #else diff --git a/src/multicast_device.c b/src/multicast_device.c index ceaa3efc..5053036e 100644 --- a/src/multicast_device.c +++ b/src/multicast_device.c @@ -87,7 +87,7 @@ static bool setup_device(void) { #endif static const int one = 1; - setsockopt(device_fd, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof one); + setsockopt(device_fd, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof(one)); if(bind(device_fd, ai->ai_addr, ai->ai_addrlen)) { closesocket(device_fd); @@ -101,20 +101,20 @@ static bool setup_device(void) { case AF_INET: { struct ip_mreq mreq; struct sockaddr_in in; - memcpy(&in, ai->ai_addr, sizeof in); + memcpy(&in, ai->ai_addr, sizeof(in)); mreq.imr_multiaddr.s_addr = in.sin_addr.s_addr; mreq.imr_interface.s_addr = htonl(INADDR_ANY); - if(setsockopt(device_fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&mreq, sizeof mreq)) { + if(setsockopt(device_fd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (void *)&mreq, sizeof(mreq))) { logger(LOG_ERR, "Cannot join multicast group %s %s: %s", host, port, sockstrerror(sockerrno)); closesocket(device_fd); free(host); return false; } #ifdef IP_MULTICAST_LOOP - setsockopt(device_fd, IPPROTO_IP, IP_MULTICAST_LOOP, (const void *)&one, sizeof one); + setsockopt(device_fd, IPPROTO_IP, IP_MULTICAST_LOOP, (const void *)&one, sizeof(one)); #endif #ifdef IP_MULTICAST_TTL - setsockopt(device_fd, IPPROTO_IP, IP_MULTICAST_TTL, (void *)&ttl, sizeof ttl); + setsockopt(device_fd, IPPROTO_IP, IP_MULTICAST_TTL, (void *)&ttl, sizeof(ttl)); #endif } break; #endif @@ -123,20 +123,20 @@ static bool setup_device(void) { case AF_INET6: { struct ipv6_mreq mreq; struct sockaddr_in6 in6; - memcpy(&in6, ai->ai_addr, sizeof in6); - memcpy(&mreq.ipv6mr_multiaddr, &in6.sin6_addr, sizeof mreq.ipv6mr_multiaddr); + memcpy(&in6, ai->ai_addr, sizeof(in6)); + memcpy(&mreq.ipv6mr_multiaddr, &in6.sin6_addr, sizeof(mreq.ipv6mr_multiaddr)); mreq.ipv6mr_interface = in6.sin6_scope_id; - if(setsockopt(device_fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, (void *)&mreq, sizeof mreq)) { + if(setsockopt(device_fd, IPPROTO_IPV6, IPV6_JOIN_GROUP, (void *)&mreq, sizeof(mreq))) { logger(LOG_ERR, "Cannot join multicast group %s %s: %s", host, port, sockstrerror(sockerrno)); closesocket(device_fd); free(host); return false; } #ifdef IPV6_MULTICAST_LOOP - setsockopt(device_fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, (const void *)&one, sizeof one); + setsockopt(device_fd, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, (const void *)&one, sizeof(one)); #endif #ifdef IPV6_MULTICAST_HOPS - setsockopt(device_fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, (void *)&ttl, sizeof ttl); + setsockopt(device_fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, (void *)&ttl, sizeof(ttl)); #endif } break; #endif @@ -173,7 +173,7 @@ static bool read_packet(vpn_packet_t *packet) { return false; } - if(!memcmp(&ignore_src, packet->data + 6, sizeof ignore_src)) { + if(!memcmp(&ignore_src, packet->data + 6, sizeof(ignore_src))) { ifdebug(SCARY_THINGS) logger(LOG_DEBUG, "Ignoring loopback packet of %d bytes from %s", lenin, device_info); packet->len = 0; return true; @@ -201,7 +201,7 @@ static bool write_packet(vpn_packet_t *packet) { device_total_out += packet->len; - memcpy(&ignore_src, packet->data + 6, sizeof ignore_src); + memcpy(&ignore_src, packet->data + 6, sizeof(ignore_src)); return true; } diff --git a/src/net.c b/src/net.c index b82dae80..cac15f90 100644 --- a/src/net.c +++ b/src/net.c @@ -255,7 +255,7 @@ static void check_dead_connections(void) { } else { if(c->status.remove) { logger(LOG_WARNING, "Old connection_t for %s (%s) status %04x still lingering, deleting...", - c->name, c->hostname, bitfield_to_int(&c->status, sizeof c->status)); + c->name, c->hostname, bitfield_to_int(&c->status, sizeof(c->status))); connection_del(c); continue; } diff --git a/src/net_packet.c b/src/net_packet.c index 18eaf34b..849c65ac 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -264,7 +264,7 @@ static void receive_packet(node_t *n, vpn_packet_t *packet) { static bool try_mac(const node_t *n, const vpn_packet_t *inpkt) { unsigned char hmac[EVP_MAX_MD_SIZE]; - if(!n->indigest || !n->inmaclength || !n->inkey || inpkt->len < sizeof inpkt->seqno + n->inmaclength) + if(!n->indigest || !n->inmaclength || !n->inkey || inpkt->len < sizeof(inpkt->seqno) + n->inmaclength) return false; HMAC(n->indigest, n->inkey, n->inkeylength, (unsigned char *) &inpkt->seqno, inpkt->len - n->inmaclength, (unsigned char *)hmac, NULL); @@ -394,7 +394,7 @@ static void receive_udppacket(node_t *n, vpn_packet_t *inpkt) { void receive_tcppacket(connection_t *c, const char *buffer, int len) { vpn_packet_t outpkt; - if(len > sizeof outpkt.data) + if(len > sizeof(outpkt.data)) return; outpkt.len = len; @@ -522,7 +522,7 @@ static void send_udppacket(node_t *n, vpn_packet_t *origpkt) { if(origpriority == -1 && n->prevedge) { sock = rand() % listen_sockets; - memset(&broadcast, 0, sizeof broadcast); + memset(&broadcast, 0, sizeof(broadcast)); if(listen_socket[sock].sa.sa.sa_family == AF_INET6) { broadcast.in6.sin6_family = AF_INET6; broadcast.in6.sin6_addr.s6_addr[0x0] = 0xff; diff --git a/src/net_setup.c b/src/net_setup.c index 2371f7ee..d0ab464d 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -326,7 +326,7 @@ char *get_name(void) { free(name); return false; } - if(gethostname(hostname, sizeof hostname) || !*hostname) { + if(gethostname(hostname, sizeof(hostname)) || !*hostname) { fprintf(stderr, "Could not get hostname: %s\n", strerror(errno)); free(name); return false; @@ -801,7 +801,7 @@ static bool setup_myself(void) { } for(i = 0; i < listen_sockets; i++) { - salen = sizeof sa; + salen = sizeof(sa); if(getsockname(i + 3, &sa.sa, &salen) < 0) { logger(LOG_ERR, "Could not get address of listen fd %d: %s", i + 3, sockstrerror(errno)); return false; @@ -906,7 +906,7 @@ static bool setup_myself(void) { if(!port_specified) { sockaddr_t sa; - socklen_t salen = sizeof sa; + socklen_t salen = sizeof(sa); if(!getsockname(listen_socket[0].udp, &sa.sa, &salen)) { free(myport); sockaddr2str(&sa, NULL, &myport); diff --git a/src/net_socket.c b/src/net_socket.c index 9d5837f9..1497a8d0 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -140,7 +140,7 @@ int setup_listen_socket(const sockaddr_t *sa) { #if defined(SOL_IPV6) && defined(IPV6_V6ONLY) if(sa->sa.sa_family == AF_INET6) - setsockopt(nfd, SOL_IPV6, IPV6_V6ONLY, (void *)&option, sizeof option); + setsockopt(nfd, SOL_IPV6, IPV6_V6ONLY, (void *)&option, sizeof(option)); #endif if(get_config_string(lookup_config(config_tree, "BindToInterface"), &iface)) { @@ -230,7 +230,7 @@ int setup_vpn_in_socket(const sockaddr_t *sa) { #if defined(IPPROTO_IPV6) && defined(IPV6_V6ONLY) if(sa->sa.sa_family == AF_INET6) - setsockopt(nfd, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&option, sizeof option); + setsockopt(nfd, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&option, sizeof(option)); #endif #if defined(IP_DONTFRAG) && !defined(IP_DONTFRAGMENT) @@ -404,7 +404,7 @@ begin: // If we cannot resolve the address, maybe we are using a proxy that can? if(!c->outgoing->ai && proxytype != PROXY_NONE && is_valid_host_port(address, port)) { - memset(&c->address, 0, sizeof c->address); + memset(&c->address, 0, sizeof(c->address)); c->address.sa.sa_family = AF_UNKNOWN; c->address.unknown.address = address; c->address.unknown.port = port; @@ -468,7 +468,7 @@ connect: #if defined(SOL_IPV6) && defined(IPV6_V6ONLY) int option = 1; if(c->address.sa.sa_family == AF_INET6) - setsockopt(c->socket, SOL_IPV6, IPV6_V6ONLY, (void *)&option, sizeof option); + setsockopt(c->socket, SOL_IPV6, IPV6_V6ONLY, (void *)&option, sizeof(option)); #endif bind_to_interface(c->socket); diff --git a/src/node.c b/src/node.c index 19f37306..23ebd8de 100644 --- a/src/node.c +++ b/src/node.c @@ -159,7 +159,7 @@ void update_node_udp(node_t *n, const sockaddr_t *sa) { avl_insert(node_udp_tree, n); ifdebug(PROTOCOL) logger(LOG_DEBUG, "UDP address of %s set to %s", n->name, n->hostname); } else { - memset(&n->address, 0, sizeof n->address); + memset(&n->address, 0, sizeof(n->address)); n->hostname = NULL; ifdebug(PROTOCOL) logger(LOG_DEBUG, "UDP address of %s cleared", n->name); } @@ -176,7 +176,7 @@ void dump_nodes(void) { logger(LOG_DEBUG, " %s at %s cipher %d digest %d maclength %d compression %d options %x status %04x nexthop %s via %s pmtu %d (min %d max %d)", n->name, n->hostname, n->outcipher ? EVP_CIPHER_nid(n->outcipher) : 0, n->outdigest ? EVP_MD_type(n->outdigest) : 0, n->outmaclength, n->outcompression, - n->options, bitfield_to_int(&n->status, sizeof n->status), n->nexthop ? n->nexthop->name : "-", + n->options, bitfield_to_int(&n->status, sizeof(n->status)), n->nexthop ? n->nexthop->name : "-", n->via ? n->via->name : "-", n->mtu, n->minmtu, n->maxmtu); } diff --git a/src/process.c b/src/process.c index bd85a80f..9969146f 100644 --- a/src/process.c +++ b/src/process.c @@ -72,25 +72,25 @@ bool install_service(void) { } if(!strchr(program_name, '\\')) { - GetCurrentDirectory(sizeof command - 1, command + 1); - strncat(command, "\\", sizeof command - strlen(command)); + GetCurrentDirectory(sizeof(command) - 1, command + 1); + strncat(command, "\\", sizeof(command) - strlen(command)); } - strncat(command, program_name, sizeof command - strlen(command)); + strncat(command, program_name, sizeof(command) - strlen(command)); - strncat(command, "\"", sizeof command - strlen(command)); + strncat(command, "\"", sizeof(command) - strlen(command)); for(argp = g_argv + 1; *argp; argp++) { space = strchr(*argp, ' '); - strncat(command, " ", sizeof command - strlen(command)); + strncat(command, " ", sizeof(command) - strlen(command)); if(space) - strncat(command, "\"", sizeof command - strlen(command)); + strncat(command, "\"", sizeof(command) - strlen(command)); - strncat(command, *argp, sizeof command - strlen(command)); + strncat(command, *argp, sizeof(command) - strlen(command)); if(space) - strncat(command, "\"", sizeof command - strlen(command)); + strncat(command, "\"", sizeof(command) - strlen(command)); } service = CreateService(manager, identname, identname, diff --git a/src/protocol.c b/src/protocol.c index eadca13f..3c966831 100644 --- a/src/protocol.c +++ b/src/protocol.c @@ -75,11 +75,11 @@ bool send_request(connection_t *c, const char *format, ...) { input buffer anyway */ va_start(args, format); - len = vsnprintf(buffer, sizeof buffer, format, args); - buffer[sizeof buffer - 1] = 0; + len = vsnprintf(buffer, sizeof(buffer), format, args); + buffer[sizeof(buffer) - 1] = 0; va_end(args); - if(len < 0 || len > sizeof buffer - 1) { + if(len < 0 || len > sizeof(buffer) - 1) { logger(LOG_ERR, "Output buffer overflow while sending request to %s (%s)", c->name, c->hostname); return false; diff --git a/src/protocol_subnet.c b/src/protocol_subnet.c index 62656c38..15ec8bf4 100644 --- a/src/protocol_subnet.c +++ b/src/protocol_subnet.c @@ -35,7 +35,7 @@ bool send_add_subnet(connection_t *c, const subnet_t *subnet) { char netstr[MAXNETSTR]; - if(!net2str(netstr, sizeof netstr, subnet)) + if(!net2str(netstr, sizeof(netstr), subnet)) return false; return send_request(c, "%d %x %s %s", ADD_SUBNET, rand(), subnet->owner->name, netstr); @@ -144,7 +144,7 @@ bool add_subnet_h(connection_t *c) { bool send_del_subnet(connection_t *c, const subnet_t *s) { char netstr[MAXNETSTR]; - if(!net2str(netstr, sizeof netstr, s)) + if(!net2str(netstr, sizeof(netstr), s)) return false; return send_request(c, "%d %x %s %s", DEL_SUBNET, rand(), s->owner->name, netstr); diff --git a/src/proxy.c b/src/proxy.c index ba48218c..75e41ded 100644 --- a/src/proxy.c +++ b/src/proxy.c @@ -35,7 +35,7 @@ char *proxypass; static void update_address_ipv4(connection_t *c, void *address, void *port) { sockaddrfree(&c->address); - memset(&c->address, 0, sizeof c->address); + memset(&c->address, 0, sizeof(c->address)); c->address.sa.sa_family = AF_INET; if(address) memcpy(&c->address.in.sin_addr, address, sizeof(ipv4_t)); @@ -48,7 +48,7 @@ static void update_address_ipv4(connection_t *c, void *address, void *port) { static void update_address_ipv6(connection_t *c, void *address, void *port) { sockaddrfree(&c->address); - memset(&c->address, 0, sizeof c->address); + memset(&c->address, 0, sizeof(c->address)); c->address.sa.sa_family = AF_INET6; if(address) memcpy(&c->address.in6.sin6_addr, address, sizeof(ipv6_t)); @@ -92,9 +92,9 @@ bool send_proxyrequest(connection_t *c) { strcpy(s4req + 8, proxyuser); else s4req[8] = 0; - s4req[sizeof s4req - 1] = 0; + s4req[sizeof(s4req) - 1] = 0; c->allow_request = PROXY; - return send_meta(c, s4req, sizeof s4req); + return send_meta(c, s4req, sizeof(s4req)); } case PROXY_SOCKS5: { @@ -158,7 +158,7 @@ bool send_proxyrequest(connection_t *c) { if(i > len) abort(); c->allow_request = PROXY; - return send_meta(c, s5req, sizeof s5req); + return send_meta(c, s5req, sizeof(s5req)); } case PROXY_HTTP: { diff --git a/src/route.c b/src/route.c index 107ad749..ef687595 100644 --- a/src/route.c +++ b/src/route.c @@ -104,9 +104,9 @@ static bool checklength(node_t *source, vpn_packet_t *packet, length_t length) { static void swap_mac_addresses(vpn_packet_t *packet) { mac_t tmp; - memcpy(&tmp, &packet->data[0], sizeof tmp); - memcpy(&packet->data[0], &packet->data[6], sizeof tmp); - memcpy(&packet->data[6], &tmp, sizeof tmp); + memcpy(&tmp, &packet->data[0], sizeof(tmp)); + memcpy(&packet->data[0], &packet->data[6], sizeof(tmp)); + memcpy(&packet->data[6], &tmp, sizeof(tmp)); } /* RFC 792 */ @@ -483,7 +483,7 @@ void age_subnets(void) { if(s->expires && s->expires <= now) { ifdebug(TRAFFIC) { char netstr[MAXNETSTR]; - if(net2str(netstr, sizeof netstr, s)) + if(net2str(netstr, sizeof(netstr), s)) logger(LOG_INFO, "Subnet %s expired", netstr); } @@ -562,7 +562,7 @@ static void route_ipv4_unicast(node_t *source, vpn_packet_t *packet) { node_t *via; ipv4_t dest; - memcpy(&dest, &packet->data[30], sizeof dest); + memcpy(&dest, &packet->data[30], sizeof(dest)); subnet = lookup_subnet_ipv4(&dest); if(!subnet) { @@ -641,7 +641,7 @@ static void route_ipv6_unicast(node_t *source, vpn_packet_t *packet) { node_t *via; ipv6_t dest; - memcpy(&dest, &packet->data[38], sizeof dest); + memcpy(&dest, &packet->data[38], sizeof(dest)); subnet = lookup_subnet_ipv6(&dest); if(!subnet) { @@ -938,13 +938,13 @@ static void route_mac(node_t *source, vpn_packet_t *packet) { if(source == myself) { mac_t src; - memcpy(&src, &packet->data[6], sizeof src); + memcpy(&src, &packet->data[6], sizeof(src)); learn_mac(&src); } /* Lookup destination address */ - memcpy(&dest, &packet->data[0], sizeof dest); + memcpy(&dest, &packet->data[0], sizeof(dest)); subnet = lookup_subnet_mac(NULL, &dest); if(!subnet) { diff --git a/src/solaris/device.c b/src/solaris/device.c index 0074615d..73046b8c 100644 --- a/src/solaris/device.c +++ b/src/solaris/device.c @@ -115,7 +115,7 @@ static bool setup_device(void) { struct strioctl strioc_ppa = { .ic_cmd = TUNNEWPPA, - .ic_len = sizeof ppa, + .ic_len = sizeof(ppa), .ic_dp = (char *)&ppa, }; @@ -156,7 +156,7 @@ static bool setup_device(void) { { /* Remove muxes just in case they are left over from a crashed tincd */ struct lifreq ifr = {}; - strncpy(ifr.lifr_name, iface, sizeof ifr.lifr_name); + strncpy(ifr.lifr_name, iface, sizeof(ifr.lifr_name)); if(ioctl(ip_fd, SIOCGLIFMUXID, &ifr) >= 0) { int muxid = ifr.lifr_arp_muxid; ioctl(ip_fd, I_PUNLINK, muxid); @@ -229,7 +229,7 @@ static bool setup_device(void) { /* Set ifname to arp */ struct strioctl strioc_if = { .ic_cmd = SIOCSLIFNAME, - .ic_len = sizeof ifr, + .ic_len = sizeof(ifr), .ic_dp = (char *)&ifr, }; @@ -285,7 +285,7 @@ static bool setup_device(void) { static void close_device(void) { if(iface) { struct lifreq ifr = {}; - strncpy(ifr.lifr_name, iface, sizeof ifr.lifr_name); + strncpy(ifr.lifr_name, iface, sizeof(ifr.lifr_name)); if(ioctl(ip_fd, SIOCGLIFMUXID, &ifr) >= 0) { int muxid = ifr.lifr_arp_muxid; ioctl(ip_fd, I_PUNLINK, muxid); diff --git a/src/subnet.c b/src/subnet.c index b4a636b3..43a7ad21 100644 --- a/src/subnet.c +++ b/src/subnet.c @@ -413,7 +413,7 @@ subnet_t *lookup_subnet_mac(const node_t *owner, const mac_t *address) { continue; if(owner && cache_mac_subnet[i] && cache_mac_subnet[i]->owner != owner) continue; - if(!memcmp(address, &cache_mac_address[i], sizeof *address)) + if(!memcmp(address, &cache_mac_address[i], sizeof(*address))) return cache_mac_subnet[i]; } @@ -425,7 +425,7 @@ subnet_t *lookup_subnet_mac(const node_t *owner, const mac_t *address) { if(!p || p->type != SUBNET_MAC) continue; - if(!memcmp(address, &p->net.mac.address, sizeof *address)) { + if(!memcmp(address, &p->net.mac.address, sizeof(*address))) { r = p; if(p->owner->status.reachable) break; @@ -435,7 +435,7 @@ subnet_t *lookup_subnet_mac(const node_t *owner, const mac_t *address) { // Cache the result cache_mac_slot = !cache_mac_slot; - memcpy(&cache_mac_address[cache_mac_slot], address, sizeof *address); + memcpy(&cache_mac_address[cache_mac_slot], address, sizeof(*address)); cache_mac_subnet[cache_mac_slot] = r; cache_mac_valid[cache_mac_slot] = true; @@ -452,7 +452,7 @@ subnet_t *lookup_subnet_ipv4(const ipv4_t *address) { for(i = 0; i < 2; i++) { if(!cache_ipv4_valid[i]) continue; - if(!memcmp(address, &cache_ipv4_address[i], sizeof *address)) + if(!memcmp(address, &cache_ipv4_address[i], sizeof(*address))) return cache_ipv4_subnet[i]; } @@ -474,7 +474,7 @@ subnet_t *lookup_subnet_ipv4(const ipv4_t *address) { // Cache the result cache_ipv4_slot = !cache_ipv4_slot; - memcpy(&cache_ipv4_address[cache_ipv4_slot], address, sizeof *address); + memcpy(&cache_ipv4_address[cache_ipv4_slot], address, sizeof(*address)); cache_ipv4_subnet[cache_ipv4_slot] = r; cache_ipv4_valid[cache_ipv4_slot] = true; @@ -491,7 +491,7 @@ subnet_t *lookup_subnet_ipv6(const ipv6_t *address) { for(i = 0; i < 2; i++) { if(!cache_ipv6_valid[i]) continue; - if(!memcmp(address, &cache_ipv6_address[i], sizeof *address)) + if(!memcmp(address, &cache_ipv6_address[i], sizeof(*address))) return cache_ipv6_subnet[i]; } @@ -513,7 +513,7 @@ subnet_t *lookup_subnet_ipv6(const ipv6_t *address) { // Cache the result cache_ipv6_slot = !cache_ipv6_slot; - memcpy(&cache_ipv6_address[cache_ipv6_slot], address, sizeof *address); + memcpy(&cache_ipv6_address[cache_ipv6_slot], address, sizeof(*address)); cache_ipv6_subnet[cache_ipv6_slot] = r; cache_ipv6_valid[cache_ipv6_slot] = true; @@ -550,7 +550,7 @@ void subnet_update(node_t *owner, subnet_t *subnet, bool up) { if(!subnet) { for(node = owner->subnet_tree->head; node; node = node->next) { subnet = node->data; - if(!net2str(netstr, sizeof netstr, subnet)) + if(!net2str(netstr, sizeof(netstr), subnet)) continue; // Strip the weight from the subnet, and put it in its own environment variable char *weight = strchr(netstr, '#'); @@ -570,7 +570,7 @@ void subnet_update(node_t *owner, subnet_t *subnet, bool up) { execute_script(name, envp); } } else { - if(net2str(netstr, sizeof netstr, subnet)) { + if(net2str(netstr, sizeof(netstr), subnet)) { // Strip the weight from the subnet, and put it in its own environment variable char *weight = strchr(netstr, '#'); if(weight) @@ -599,7 +599,7 @@ void dump_subnets(void) { for(node = subnet_tree->head; node; node = node->next) { subnet = node->data; - if(!net2str(netstr, sizeof netstr, subnet)) + if(!net2str(netstr, sizeof(netstr), subnet)) continue; logger(LOG_DEBUG, " %s owner %s", netstr, subnet->owner->name); } diff --git a/src/tincd.c b/src/tincd.c index e338850a..c731e1d3 100644 --- a/src/tincd.c +++ b/src/tincd.c @@ -418,7 +418,7 @@ static bool keygen(int bits) { } else fprintf(stderr, "Done.\n"); - snprintf(filename, sizeof filename, "%s/rsa_key.priv", confbase); + snprintf(filename, sizeof(filename), "%s/rsa_key.priv", confbase); f = ask_and_open(filename, "private RSA key"); if(!f) { @@ -438,10 +438,10 @@ static bool keygen(int bits) { char *name = get_name(); if(name) { - snprintf(filename, sizeof filename, "%s/hosts/%s", confbase, name); + snprintf(filename, sizeof(filename), "%s/hosts/%s", confbase, name); free(name); } else { - snprintf(filename, sizeof filename, "%s/rsa_key.pub", confbase); + snprintf(filename, sizeof(filename), "%s/rsa_key.pub", confbase); } f = ask_and_open(filename, "public RSA key"); diff --git a/src/uml_device.c b/src/uml_device.c index 2db5896c..5dcf8aa9 100644 --- a/src/uml_device.c +++ b/src/uml_device.c @@ -81,7 +81,7 @@ static bool setup_device(void) { fcntl(write_fd, F_SETFD, FD_CLOEXEC); #endif - setsockopt(write_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof one); + setsockopt(write_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); if(fcntl(write_fd, F_SETFL, O_NONBLOCK) < 0) { logger(LOG_ERR, "System call `%s' failed: %s", "fcntl", strerror(errno)); @@ -99,7 +99,7 @@ static bool setup_device(void) { fcntl(data_fd, F_SETFD, FD_CLOEXEC); #endif - setsockopt(data_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof one); + setsockopt(data_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); if(fcntl(data_fd, F_SETFL, O_NONBLOCK) < 0) { logger(LOG_ERR, "System call `%s' failed: %s", "fcntl", strerror(errno)); @@ -112,9 +112,9 @@ static bool setup_device(void) { gettimeofday(&tv, NULL); name.usecs = tv.tv_usec; data_sun.sun_family = AF_UNIX; - memcpy(&data_sun.sun_path, &name, sizeof name); + memcpy(&data_sun.sun_path, &name, sizeof(name)); - if(bind(data_fd, (struct sockaddr *)&data_sun, sizeof data_sun) < 0) { + if(bind(data_fd, (struct sockaddr *)&data_sun, sizeof(data_sun)) < 0) { logger(LOG_ERR, "Could not bind data %s: %s", device_info, strerror(errno)); running = false; return false; @@ -130,7 +130,7 @@ static bool setup_device(void) { fcntl(device_fd, F_SETFD, FD_CLOEXEC); #endif - setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof one); + setsockopt(listen_fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)); if(fcntl(listen_fd, F_SETFL, O_NONBLOCK) < 0) { logger(LOG_ERR, "System call `%s' failed: %s", "fcntl", strerror(errno)); @@ -138,8 +138,8 @@ static bool setup_device(void) { } listen_sun.sun_family = AF_UNIX; - strncpy(listen_sun.sun_path, device, sizeof listen_sun.sun_path); - if(bind(listen_fd, (struct sockaddr *)&listen_sun, sizeof listen_sun) < 0) { + strncpy(listen_sun.sun_path, device, sizeof(listen_sun.sun_path)); + if(bind(listen_fd, (struct sockaddr *)&listen_sun, sizeof(listen_sun)) < 0) { logger(LOG_ERR, "Could not bind %s to %s: %s", device_info, device, strerror(errno)); return false; } @@ -185,7 +185,7 @@ static bool read_packet(vpn_packet_t *packet) { switch(state) { case 0: { struct sockaddr sa; - socklen_t salen = sizeof sa; + socklen_t salen = sizeof(sa); request_fd = accept(listen_fd, &sa, &salen); if(request_fd < 0) { @@ -212,7 +212,7 @@ static bool read_packet(vpn_packet_t *packet) { } case 1: { - if((lenin = read(request_fd, &request, sizeof request)) != sizeof request) { + if((lenin = read(request_fd, &request, sizeof(request))) != sizeof request) { logger(LOG_ERR, "Error while reading request from %s %s: %s", device_info, device, strerror(errno)); running = false; @@ -226,13 +226,13 @@ static bool read_packet(vpn_packet_t *packet) { return false; } - if(connect(write_fd, &request.sock, sizeof request.sock) < 0) { + if(connect(write_fd, &request.sock, sizeof(request.sock)) < 0) { logger(LOG_ERR, "Could not bind write %s: %s", device_info, strerror(errno)); running = false; return false; } - write(request_fd, &data_sun, sizeof data_sun); + write(request_fd, &data_sun, sizeof(data_sun)); device_fd = data_fd; logger(LOG_INFO, "Connection with UML established"); diff --git a/src/utils.c b/src/utils.c index 555ea50d..656f1ea4 100644 --- a/src/utils.c +++ b/src/utils.c @@ -73,8 +73,8 @@ const char *winerror(int err) { unsigned int bitfield_to_int(const void *bitfield, size_t size) { unsigned int value = 0; - if(size > sizeof value) - size = sizeof value; + if(size > sizeof(value)) + size = sizeof(value); memcpy(&value, bitfield, size); return value; } diff --git a/src/xalloc.h b/src/xalloc.h index 468d6bb1..9d3a71e5 100644 --- a/src/xalloc.h +++ b/src/xalloc.h @@ -55,7 +55,7 @@ static inline char *xstrdup(const char *s) { static inline int xvasprintf(char **strp, const char *fmt, va_list ap) { #ifdef HAVE_MINGW char buf[1024]; - int result = vsnprintf(buf, sizeof buf, fmt, ap); + int result = vsnprintf(buf, sizeof(buf), fmt, ap); if(result < 0) abort(); *strp = xstrdup(buf); -- 2.20.1