From: Todd C. Miller Date: Wed, 25 Oct 2017 16:05:06 +0000 (-0600) Subject: Replace remaining sizeof foo with sizeof(foo). X-Git-Tag: release-1.1pre16~59 X-Git-Url: https://git.tinc-vpn.org/git/browse?a=commitdiff_plain;h=87f96aec8c48327d879c20ff2b789c88a675173d;p=tinc Replace remaining sizeof foo with sizeof(foo). --- diff --git a/src/cygwin/device.c b/src/cygwin/device.c index 8229c3d6..1265f9d5 100644 --- a/src/cygwin/device.c +++ b/src/cygwin/device.c @@ -161,7 +161,7 @@ static bool setup_device(void) { /* Get MAC address from tap device */ - if(!DeviceIoControl(device_handle, TAP_IOCTL_GET_MAC, mymac.x, sizeof(mymac.x), mymac.x, sizeof mymac.x, &len, 0)) { + if(!DeviceIoControl(device_handle, TAP_IOCTL_GET_MAC, mymac.x, sizeof(mymac.x), mymac.x, sizeof(mymac.x), &len, 0)) { logger(DEBUG_ALWAYS, LOG_ERR, "Could not get MAC address from Windows tap device %s (%s): %s", device, iface, winerror(GetLastError())); return false; } diff --git a/src/gcrypt/cipher.c b/src/gcrypt/cipher.c index 1440f2e6..f8668da7 100644 --- a/src/gcrypt/cipher.c +++ b/src/gcrypt/cipher.c @@ -55,7 +55,7 @@ static struct { static bool nametocipher(const char *name, int *algo, int *mode) { size_t i; - for(i = 0; i < sizeof(ciphertable) / sizeof * ciphertable; i++) { + for(i = 0; i < sizeof(ciphertable) / sizeof(*ciphertable); i++) { if(ciphertable[i].name && !strcasecmp(name, ciphertable[i].name)) { *algo = ciphertable[i].algo; *mode = ciphertable[i].mode; @@ -69,7 +69,7 @@ static bool nametocipher(const char *name, int *algo, int *mode) { static bool nidtocipher(int nid, int *algo, int *mode) { size_t i; - for(i = 0; i < sizeof(ciphertable) / sizeof * ciphertable; i++) { + for(i = 0; i < sizeof(ciphertable) / sizeof(*ciphertable); i++) { if(nid == ciphertable[i].nid) { *algo = ciphertable[i].algo; *mode = ciphertable[i].mode; @@ -83,7 +83,7 @@ static bool nidtocipher(int nid, int *algo, int *mode) { static bool ciphertonid(int algo, int mode, int *nid) { size_t i; - for(i = 0; i < sizeof(ciphertable) / sizeof * ciphertable; i++) { + for(i = 0; i < sizeof(ciphertable) / sizeof(*ciphertable); i++) { if(algo == ciphertable[i].algo && mode == ciphertable[i].mode) { *nid = ciphertable[i].nid; return true; diff --git a/src/gcrypt/digest.c b/src/gcrypt/digest.c index ac5dc744..fce48ee2 100644 --- a/src/gcrypt/digest.c +++ b/src/gcrypt/digest.c @@ -37,7 +37,7 @@ static struct { static bool nametodigest(const char *name, int *algo) { int i; - for(i = 0; i < sizeof(digesttable) / sizeof * digesttable; i++) { + for(i = 0; i < sizeof(digesttable) / sizeof(*digesttable); i++) { if(digesttable[i].name && !strcasecmp(name, digesttable[i].name)) { *algo = digesttable[i].algo; return true; @@ -50,7 +50,7 @@ static bool nametodigest(const char *name, int *algo) { static bool nidtodigest(int nid, int *algo) { int i; - for(i = 0; i < sizeof(digesttable) / sizeof * digesttable; i++) { + for(i = 0; i < sizeof(digesttable) / sizeof(*digesttable); i++) { if(nid == digesttable[i].nid) { *algo = digesttable[i].algo; return true; @@ -63,7 +63,7 @@ static bool nidtodigest(int nid, int *algo) { static bool digesttonid(int algo, int *nid) { int i; - for(i = 0; i < sizeof(digesttable) / sizeof * digesttable; i++) { + for(i = 0; i < sizeof(digesttable) / sizeof(*digesttable); i++) { if(algo == digesttable[i].algo) { *nid = digesttable[i].nid; return true; diff --git a/src/invitation.c b/src/invitation.c index bcb79a48..d6f00a55 100644 --- a/src/invitation.c +++ b/src/invitation.c @@ -1234,7 +1234,7 @@ next: char hisname[4096] = ""; int code, hismajor, hisminor = 0; - if(!recvline(sock, line, sizeof(line)) || sscanf(line, "%d %4095s %d.%d", &code, hisname, &hismajor, &hisminor) < 3 || code != 0 || hismajor != PROT_MAJOR || !check_id(hisname) || !recvline(sock, line, sizeof line) || !rstrip(line) || sscanf(line, "%d ", &code) != 1 || code != ACK || strlen(line) < 3) { + if(!recvline(sock, line, sizeof(line)) || sscanf(line, "%d %4095s %d.%d", &code, hisname, &hismajor, &hisminor) < 3 || code != 0 || hismajor != PROT_MAJOR || !check_id(hisname) || !recvline(sock, line, sizeof(line)) || !rstrip(line) || sscanf(line, "%d ", &code) != 1 || code != ACK || strlen(line) < 3) { fprintf(stderr, "Cannot read greeting from peer\n"); closesocket(sock); goto next; diff --git a/src/mingw/device.c b/src/mingw/device.c index 468ba504..1116b5e1 100644 --- a/src/mingw/device.c +++ b/src/mingw/device.c @@ -200,7 +200,7 @@ static bool setup_device(void) { ULONG info[3] = {0}; DWORD len; - if(!DeviceIoControl(device_handle, TAP_IOCTL_GET_VERSION, &info, sizeof(info), &info, sizeof info, &len, NULL)) { + if(!DeviceIoControl(device_handle, TAP_IOCTL_GET_VERSION, &info, sizeof(info), &info, sizeof(info), &len, NULL)) { logger(DEBUG_ALWAYS, LOG_WARNING, "Could not get version information from Windows tap device %s (%s): %s", device, iface, winerror(GetLastError())); } else { logger(DEBUG_ALWAYS, LOG_INFO, "TAP-Windows driver version: %lu.%lu%s", info[0], info[1], info[2] ? " (DEBUG)" : ""); @@ -216,7 +216,7 @@ static bool setup_device(void) { /* Get MAC address from tap device */ - if(!DeviceIoControl(device_handle, TAP_IOCTL_GET_MAC, mymac.x, sizeof(mymac.x), mymac.x, sizeof mymac.x, &len, 0)) { + if(!DeviceIoControl(device_handle, TAP_IOCTL_GET_MAC, mymac.x, sizeof(mymac.x), mymac.x, sizeof(mymac.x), &len, 0)) { logger(DEBUG_ALWAYS, LOG_ERR, "Could not get MAC address from Windows tap device %s (%s): %s", device, iface, winerror(GetLastError())); return false; } @@ -240,7 +240,7 @@ static void enable_device(void) { ULONG status = 1; DWORD len; - DeviceIoControl(device_handle, TAP_IOCTL_SET_MEDIA_STATUS, &status, sizeof(status), &status, sizeof status, &len, NULL); + DeviceIoControl(device_handle, TAP_IOCTL_SET_MEDIA_STATUS, &status, sizeof(status), &status, sizeof(status), &len, NULL); /* We don't use the write event directly, but GetOverlappedResult() does, internally. */ @@ -255,7 +255,7 @@ static void disable_device(void) { ULONG status = 0; DWORD len; - DeviceIoControl(device_handle, TAP_IOCTL_SET_MEDIA_STATUS, &status, sizeof(status), &status, sizeof status, &len, NULL); + DeviceIoControl(device_handle, TAP_IOCTL_SET_MEDIA_STATUS, &status, sizeof(status), &status, sizeof(status), &len, NULL); /* Note that we don't try to cancel ongoing I/O here - we just stop listening. This is because some TAP-Win32 drivers don't seem to handle cancellation very well, diff --git a/src/net_packet.c b/src/net_packet.c index 5709d49a..1aa881ce 100644 --- a/src/net_packet.c +++ b/src/net_packet.c @@ -832,12 +832,12 @@ bool send_sptps_data(node_t *to, node_t *from, int type, const void *data, size_ if(type == SPTPS_HANDSHAKE || tcponly || (!direct && !relay_supported) || (type != PKT_PROBE && (len - SPTPS_DATAGRAM_OVERHEAD) > relay->minmtu)) { if(type != SPTPS_HANDSHAKE && (to->nexthop->connection->options >> 24) >= 7) { - char buf[len + sizeof(to->id) + sizeof from->id]; + char buf[len + sizeof(to->id) + sizeof(from->id)]; char *buf_ptr = buf; memcpy(buf_ptr, &to->id, sizeof(to->id)); - buf_ptr += sizeof to->id; + buf_ptr += sizeof(to->id); memcpy(buf_ptr, &from->id, sizeof(from->id)); - buf_ptr += sizeof from->id; + buf_ptr += sizeof(from->id); memcpy(buf_ptr, data, len); logger(DEBUG_TRAFFIC, LOG_INFO, "Sending packet from %s (%s) to %s (%s) via %s (%s) (TCP)", from->name, from->hostname, to->name, to->hostname, to->nexthop->name, to->nexthop->hostname); return send_sptps_tcppacket(to->nexthop->connection, buf, sizeof(buf)); @@ -860,7 +860,7 @@ bool send_sptps_data(node_t *to, node_t *from, int type, const void *data, size_ size_t overhead = 0; if(relay_supported) { - overhead += sizeof(to->id) + sizeof from->id; + overhead += sizeof(to->id) + sizeof(from->id); } char buf[len + overhead]; @@ -871,14 +871,14 @@ bool send_sptps_data(node_t *to, node_t *from, int type, const void *data, size_ /* Inform the recipient that this packet was sent directly. */ node_id_t nullid = {}; memcpy(buf_ptr, &nullid, sizeof(nullid)); - buf_ptr += sizeof nullid; + buf_ptr += sizeof(nullid); } else { memcpy(buf_ptr, &to->id, sizeof(to->id)); - buf_ptr += sizeof to->id; + buf_ptr += sizeof(to->id); } memcpy(buf_ptr, &from->id, sizeof(from->id)); - buf_ptr += sizeof from->id; + buf_ptr += sizeof(from->id); } diff --git a/src/netutl.c b/src/netutl.c index 73719232..4e58911c 100644 --- a/src/netutl.c +++ b/src/netutl.c @@ -105,7 +105,7 @@ void sockaddr2str(const sockaddr_t *sa, char **addrstr, char **portstr) { return; } - err = getnameinfo(&sa->sa, SALEN(sa->sa), address, sizeof(address), port, sizeof port, NI_NUMERICHOST | NI_NUMERICSERV); + err = getnameinfo(&sa->sa, SALEN(sa->sa), address, sizeof(address), port, sizeof(port), NI_NUMERICHOST | NI_NUMERICSERV); if(err) { logger(DEBUG_ALWAYS, LOG_ERR, "Error while translating addresses: %s", err == EAI_SYSTEM ? strerror(errno) : gai_strerror(err)); @@ -141,7 +141,7 @@ char *sockaddr2hostname(const sockaddr_t *sa) { return str; } - err = getnameinfo(&sa->sa, SALEN(sa->sa), address, sizeof(address), port, sizeof port, + err = getnameinfo(&sa->sa, SALEN(sa->sa), address, sizeof(address), port, sizeof(port), hostnames ? 0 : (NI_NUMERICHOST | NI_NUMERICSERV)); if(err) { diff --git a/src/uml_device.c b/src/uml_device.c index 406c81d0..3e7b8219 100644 --- a/src/uml_device.c +++ b/src/uml_device.c @@ -226,7 +226,7 @@ static bool read_packet(vpn_packet_t *packet) { } case 1: { - if((inlen = read(request_fd, &request, sizeof(request))) != sizeof request) { + if((inlen = read(request_fd, &request, sizeof(request))) != sizeof(request)) { logger(DEBUG_ALWAYS, LOG_ERR, "Error while reading request from %s %s: %s", device_info, device, strerror(errno)); event_exit(); diff --git a/test/pong.c b/test/pong.c index e0d8b095..43fd7180 100644 --- a/test/pong.c +++ b/test/pong.c @@ -72,7 +72,7 @@ static ssize_t do_ipv4(uint8_t *buf, ssize_t len, struct sockaddr_in *in) { return 0; } - memcpy(&icmp, buf + 14 + sizeof(ip), sizeof icmp); + memcpy(&icmp, buf + 14 + sizeof(ip), sizeof(icmp)); if(icmp.icmp_type != ICMP_ECHO) { return 0; @@ -88,7 +88,7 @@ static ssize_t do_ipv4(uint8_t *buf, ssize_t len, struct sockaddr_in *in) { icmp.icmp_type = ICMP_ECHOREPLY; memcpy(buf + 14, &ip, sizeof(ip)); - memcpy(buf + 14 + sizeof(ip), &icmp, sizeof icmp); + memcpy(buf + 14 + sizeof(ip), &icmp, sizeof(icmp)); return len; }