Attention is currently required from: Arne Schwabe.

Hello Arne Schwabe,

I'd like you to do a code review.
Please visit

    https://gerrit.openvpn.net/c/openvpn/+/2197?usp=email

to review the following change.


Change subject: Various trivial -Wsign-conversion fixes (part 2)
......................................................................

Various trivial -Wsign-conversion fixes (part 2)

Change-Id: I33f70825c058c24ecabd8e80e5ac84bff07c9253
Signed-off-by: Frank Lichtenheld <[email protected]>
---
M src/openvpn/env_set.c
M src/openvpn/manage.c
M src/openvpn/ps.c
M src/openvpn/ssl_mbedtls.c
M tests/unit_tests/openvpn/test_buffer.c
M tests/unit_tests/openvpn/test_cryptoapi.c
6 files changed, 15 insertions(+), 60 deletions(-)



  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/97/2197/1

diff --git a/src/openvpn/env_set.c b/src/openvpn/env_set.c
index d59115a..55190b8 100644
--- a/src/openvpn/env_set.c
+++ b/src/openvpn/env_set.c
@@ -432,11 +432,6 @@
     return (script_security() >= SSEC_PW_ENV || !is_password_env_var(str));
 }

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-conversion"
-#endif
-
 /* Make arrays of strings */

 const char **
@@ -444,7 +439,7 @@
 {
     char **ret = NULL;
     struct env_item *e = NULL;
-    int i = 0, n = 0;
+    size_t i = 0, n = 0;

     /* figure length of es */
     if (es)
@@ -475,7 +470,3 @@
     ret[i] = NULL;
     return (const char **)ret;
 }
-
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c
index ca0a7dd..ae30930 100644
--- a/src/openvpn/manage.c
+++ b/src/openvpn/manage.c
@@ -779,14 +779,9 @@
     }
 }

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-conversion"
-#endif
-
 static void
 man_query_user_pass(struct management *man, const char *type, const char 
*string, const bool needed,
-                    const char *prompt, char *dest, int len)
+                    const char *prompt, char *dest, size_t len)
 {
     if (needed)
     {
@@ -809,10 +804,6 @@
     }
 }

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 static void
 man_query_username(struct management *man, const char *type, const char 
*string)
 {
@@ -2700,11 +2691,6 @@
     CLEAR(*mp);
 }

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-conversion"
-#endif
-
 static void
 man_settings_init(struct man_settings *ms, const char *addr, const char *port,
                   const char *pass_file, const char *client_user, const char 
*client_group,
@@ -3315,15 +3301,11 @@
         {
             return false;
         }
-        *persistent = n;
+        *persistent = (unsigned int)n;
     }
     return true;
 }

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 #ifdef _WIN32

 void
@@ -3708,7 +3690,7 @@
         struct buffer alert_msg = alloc_buf_gc(256, &gc);
         const char *alert_type = NULL;
         const char *prefix = NULL;
-        unsigned int up_query_mode = 0;
+        int up_query_mode = 0;
         const char *sc = NULL;
         ret = true;
         /* This is so M_CLIENT messages will be correctly passed through msg() 
*/
@@ -4052,8 +4034,8 @@
         const bool standalone_disabled_save = man->persist.standalone_disabled;
         struct gc_arena gc = gc_new();

-        man->persist.standalone_disabled =
-            false; /* This is so M_CLIENT messages will be correctly passed 
through msg() */
+        /* This is so M_CLIENT messages will be correctly passed through msg() 
*/
+        man->persist.standalone_disabled = false;
         man->persist.special_state_msg = NULL;
         man->settings.mansig |= MANSIG_IGNORE_USR1_HUP;

diff --git a/src/openvpn/ps.c b/src/openvpn/ps.c
index 86b4fc9..4aff2f3 100644
--- a/src/openvpn/ps.c
+++ b/src/openvpn/ps.c
@@ -159,7 +159,7 @@
     }
 }

-static int
+static size_t
 cmsg_size(void)
 {
     return CMSG_SPACE(sizeof(socket_descriptor_t));
@@ -357,8 +357,8 @@
         }
         if (fd != -1)
         {
-            ssize_t write_len = strlen(f);
-            if (write(fd, f, write_len) != write_len)
+            const size_t write_len = strlen(f);
+            if (write(fd, f, write_len) != (ssize_t)write_len)
             {
                 msg(M_WARN, "PORT SHARE: writing to journal file (%s) failed", 
jfn);
             }
diff --git a/src/openvpn/ssl_mbedtls.c b/src/openvpn/ssl_mbedtls.c
index 43bb0ff..aa843c1 100644
--- a/src/openvpn/ssl_mbedtls.c
+++ b/src/openvpn/ssl_mbedtls.c
@@ -1017,7 +1017,7 @@

     if (1 == retval)
     {
-        memset(BPTR(buf), 0, BLEN(buf)); /* erase data just written */
+        memset(BPTR(buf), 0, BLENZ(buf)); /* erase data just written */
         buf->len = 0;
     }

@@ -1039,7 +1039,7 @@

     ASSERT(data);

-    retval = mbedtls_ssl_write(ks->ctx, data, len);
+    retval = mbedtls_ssl_write(ks->ctx, data, (size_t)len);

     if (retval < 0)
     {
@@ -1143,7 +1143,7 @@
     /* successful write */
     dmsg(D_HANDSHAKE_VERBOSE, "write tls_write_ciphertext %d bytes", retval);

-    memset(BPTR(buf), 0, BLEN(buf)); /* erase data just written */
+    memset(BPTR(buf), 0, BLENZ(buf)); /* erase data just written */
     buf->len = 0;

     return 1;
diff --git a/tests/unit_tests/openvpn/test_buffer.c 
b/tests/unit_tests/openvpn/test_buffer.c
index b480985..14f5d1d 100644
--- a/tests/unit_tests/openvpn/test_buffer.c
+++ b/tests/unit_tests/openvpn/test_buffer.c
@@ -106,20 +106,15 @@
     gc_free(&gc);
 }

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-conversion"
-#endif
-
 static void
 test_buffer_format_hex_ex(void **state)
 {
-    const int input_size = 10;
+    const size_t input_size = 10;
     const uint8_t input[] = { 0x01, 0x00, 0xff, 0x10, 0xff, 0x00, 0xf0, 0x0f, 
0x09, 0x0a };
     char *output;
     struct gc_arena gc = gc_new();

-    int maxoutput = 0;
+    size_t maxoutput = 0;
     unsigned int blocksize = 5;
     const char *separator = " ";
     output = format_hex_ex(input, input_size, maxoutput, blocksize, separator, 
&gc);
@@ -144,10 +139,6 @@
     gc_free(&gc);
 }

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 struct test_buffer_list_aggregate_ctx
 {
     struct buffer_list *empty;
diff --git a/tests/unit_tests/openvpn/test_cryptoapi.c 
b/tests/unit_tests/openvpn/test_cryptoapi.c
index 55aafbb..2517a55 100644
--- a/tests/unit_tests/openvpn/test_cryptoapi.c
+++ b/tests/unit_tests/openvpn/test_cryptoapi.c
@@ -137,11 +137,6 @@
     return c->cert ? c : NULL;
 }

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign-conversion"
-#endif
-
 /* import sample certificates into windows cert store */
 static void
 import_certs(void **state)
@@ -201,7 +196,7 @@
             fail_msg("Failed to DER encode PKCS12: <%s>", c->friendly_name);
             return;
         }
-        blob.cbData = len;
+        blob.cbData = (DWORD)len;

         DWORD flags = PKCS12_ALLOW_OVERWRITE_KEY | PKCS12_ALWAYS_CNG_KSP;
         HCERTSTORE tmp_store = PFXImportCertStore(&blob, wpass, flags);
@@ -228,10 +223,6 @@
     certs_loaded = true;
 }

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 static int
 cleanup(void **state)
 {

--
To view, visit https://gerrit.openvpn.net/c/openvpn/+/2197?usp=email
To unsubscribe, or for help writing mail filters, visit 
https://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I33f70825c058c24ecabd8e80e5ac84bff07c9253
Gerrit-Change-Number: 2197
Gerrit-PatchSet: 1
Gerrit-Owner: Frank Lichtenheld <[email protected]>
Gerrit-Reviewer: Arne Schwabe <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: Arne Schwabe <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Reply via email to