]> tinc-vpn.org Git - tinc/commitdiff
Fix more warnings from Clang
authorGuus Sliepen <guus@tinc-vpn.org>
Mon, 6 Apr 2026 14:26:15 +0000 (16:26 +0200)
committerGuus Sliepen <guus@tinc-vpn.org>
Mon, 6 Apr 2026 14:26:54 +0000 (16:26 +0200)
src/bsd/device.c
src/gcrypt/cipher.c
src/linux/uml_device.c
src/script.c
src/tincctl.c
src/utils.c
test/integration/splice.c
test/unit/test_fs.c

index ca06f4a23f76331b34fc2eb3ba08c0602628a015..618f3d89ccef629966a7a925f2290067fc0d89c3 100644 (file)
@@ -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;
index ee3856add941a941421da0f35fa983407046c360..3f23f84158f74690cfbff3f436119cab7e530986 100644 (file)
@@ -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;
        }
index 2004850f08e2f62ad77ced2af8275025c0e2de20..891cdd6c478e07b2c49825d365d6067fc7242910 100644 (file)
@@ -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;
index 2f2c30bf51a87f22739c8a9a78ff921273943753..2491d430a13e6730a632db2b5961c5f766a22f29 100644 (file)
@@ -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;
                        }
 
index ab5a2b247c3154ce730c99160c4e393c824cbfd9..50e8a415fbf50b54c4412689ffbaa152d9c13fad 100644 (file)
@@ -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;
        }
 
index 8c8c6526fd3038898bde60cb388d7616902e300f..174053fdb93b197043611aa1c971a25fdcf19aa1 100644 (file)
@@ -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';
        }
 
index e72d0c7199b60a88e38ec49e6528106e6e23fb55..fcdca7d2ee98650c842a802c6f0466ce83b95ee2 100644 (file)
@@ -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';
        }
 
index b335174ad8e7adf42158e71ef88e61811f7d44d9..b06c96884655ed8ea856e31990bc6332942af36b 100644 (file)
@@ -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))) {