From: Guus Sliepen Date: Mon, 6 Apr 2026 14:26:15 +0000 (+0200) Subject: Fix more warnings from Clang X-Git-Url: https://www.tinc-vpn.org/git/?a=commitdiff_plain;h=0cdb51ae5cfefd66d76b2b6f38ed9fed5d6d00ac;p=tinc Fix more warnings from Clang --- diff --git a/src/bsd/device.c b/src/bsd/device.c index ca06f4a2..618f3d89 100644 --- a/src/bsd/device.c +++ b/src/bsd/device.c @@ -448,7 +448,9 @@ static bool read_packet(vpn_packet_t *packet) { case DEVICE_TYPE_UTUN: case DEVICE_TYPE_TUNIFHEAD: { - if((inlen = read(device_fd, DATA(packet) + 10, MTU - 10)) <= 0) { + inlen = read(device_fd, DATA(packet) + 10, MTU - 10); + + if(inlen <= 0) { logger(DEBUG_ALWAYS, LOG_ERR, "Error while reading from %s %s: %s", device_info, device, strerror(errno)); return false; @@ -482,7 +484,9 @@ static bool read_packet(vpn_packet_t *packet) { case DEVICE_TYPE_VMNET: #endif case DEVICE_TYPE_TAP: - if((inlen = read(device_fd, DATA(packet), MTU)) <= 0) { + inlen = read(device_fd, DATA(packet), MTU); + + if(inlen <= 0) { logger(DEBUG_ALWAYS, LOG_ERR, "Error while reading from %s %s: %s", device_info, device, strerror(errno)); return false; diff --git a/src/gcrypt/cipher.c b/src/gcrypt/cipher.c index ee3856ad..3f23f841 100644 --- a/src/gcrypt/cipher.c +++ b/src/gcrypt/cipher.c @@ -99,7 +99,9 @@ static bool cipher_open(cipher_t *cipher, cipher_algo_t algo, cipher_mode_t mode return false; } - if((err = gcry_cipher_open(&cipher->handle, algo, mode, 0))) { + err = gcry_cipher_open(&cipher->handle, algo, mode, 0); + + if(err) { logger(DEBUG_ALWAYS, LOG_DEBUG, "Unable to initialise cipher %d mode %d: %s", algo, mode, gcry_strerror(err)); return false; } @@ -237,13 +239,17 @@ bool cipher_encrypt(cipher_t *cipher, const void *indata, size_t inlen, void *ou gcry_cipher_setiv(cipher->handle, cipher->key + cipher->keylen, cipher->blklen); } - if((err = gcry_cipher_encrypt(cipher->handle, outdata, *outlen, indata, inlen))) { + err = gcry_cipher_encrypt(cipher->handle, outdata, *outlen, indata, inlen); + + if(err) { logger(DEBUG_ALWAYS, LOG_ERR, "Error while encrypting: %s", gcry_strerror(err)); return false; } if(cipher->padding) { - if((err = gcry_cipher_encrypt(cipher->handle, (char *)outdata + inlen, cipher->blklen, pad, cipher->blklen))) { + err = gcry_cipher_encrypt(cipher->handle, (char *)outdata + inlen, cipher->blklen, pad, cipher->blklen); + + if(err) { logger(DEBUG_ALWAYS, LOG_ERR, "Error while encrypting: %s", gcry_strerror(err)); return false; } @@ -262,7 +268,9 @@ bool cipher_decrypt(cipher_t *cipher, const void *indata, size_t inlen, void *ou gcry_cipher_setiv(cipher->handle, cipher->key + cipher->keylen, cipher->blklen); } - if((err = gcry_cipher_decrypt(cipher->handle, outdata, *outlen, indata, inlen))) { + err = gcry_cipher_decrypt(cipher->handle, outdata, *outlen, indata, inlen); + + if(err) { logger(DEBUG_ALWAYS, LOG_ERR, "Error while decrypting: %s", gcry_strerror(err)); return false; } diff --git a/src/linux/uml_device.c b/src/linux/uml_device.c index 2004850f..891cdd6c 100644 --- a/src/linux/uml_device.c +++ b/src/linux/uml_device.c @@ -69,7 +69,9 @@ static bool setup_device(void) { get_config_string(lookup_config(&config_tree, "Interface"), &iface); - if((write_fd = socket(PF_UNIX, SOCK_DGRAM, 0)) < 0) { + write_fd = socket(PF_UNIX, SOCK_DGRAM, 0); + + if(write_fd < 0) { logger(DEBUG_ALWAYS, LOG_ERR, "Could not open write %s: %s", device_info, strerror(errno)); event_exit(); return false; @@ -87,7 +89,9 @@ static bool setup_device(void) { return false; } - if((data_fd = socket(PF_UNIX, SOCK_DGRAM, 0)) < 0) { + data_fd = socket(PF_UNIX, SOCK_DGRAM, 0); + + if(data_fd < 0) { logger(DEBUG_ALWAYS, LOG_ERR, "Could not open data %s: %s", device_info, strerror(errno)); event_exit(); return false; @@ -117,7 +121,9 @@ static bool setup_device(void) { return false; } - if((listen_fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0) { + listen_fd = socket(PF_UNIX, SOCK_STREAM, 0); + + if(listen_fd < 0) { logger(DEBUG_ALWAYS, LOG_ERR, "Could not open %s: %s", device_info, strerror(errno)); return false; diff --git a/src/script.c b/src/script.c index 2f2c30bf..2491d430 100644 --- a/src/script.c +++ b/src/script.c @@ -184,7 +184,9 @@ bool execute_script(const char *name, environment_t *env) { strncpy(ext, p, pathlen + 1); } - if((found = !access(fullname, F_OK))) { + found = !access(fullname, F_OK); + + if(found) { break; } diff --git a/src/tincctl.c b/src/tincctl.c index ab5a2b24..50e8a415 100644 --- a/src/tincctl.c +++ b/src/tincctl.c @@ -917,8 +917,9 @@ static int cmd_start(int argc, char *argv[]) { char *slash = strrchr(program_name, '/'); #ifdef HAVE_WINDOWS + c = strrchr(program_name, '\\'); - if((c = strrchr(program_name, '\\')) > slash) { + if(c > slash) { slash = c; } diff --git a/src/utils.c b/src/utils.c index 8c8c6526..174053fd 100644 --- a/src/utils.c +++ b/src/utils.c @@ -205,7 +205,9 @@ const char *winerror(int err) { strncpy(buf, "(unable to format errormessage)", sizeof(buf)); }; - if((ptr = strchr(buf, '\r'))) { + ptr = strchr(buf, '\r'); + + if(ptr) { *ptr = '\0'; } diff --git a/test/integration/splice.c b/test/integration/splice.c index e72d0c71..fcdca7d2 100644 --- a/test/integration/splice.c +++ b/test/integration/splice.c @@ -30,7 +30,9 @@ static const char *winerror(int err) { strncpy(buf, "(unable to format errormessage)", sizeof(buf)); }; - if((ptr = strchr(buf, '\r'))) { + ptr = strchr(buf, '\r'); + + if(ptr) { *ptr = '\0'; } diff --git a/test/unit/test_fs.c b/test/unit/test_fs.c index b335174a..b06c9688 100644 --- a/test/unit/test_fs.c +++ b/test/unit/test_fs.c @@ -122,6 +122,10 @@ static void test_makedir(unsigned int dir, bool exists) { DIR *d = opendir(container); assert_non_null(d); + if (!d) { + abort(); + } + struct dirent *ent; while((ent = readdir(d))) {