Attention is currently required from: plaisthos.

Hello plaisthos,

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

    http://gerrit.openvpn.net/c/openvpn/+/1189?usp=email

to review the following change.


Change subject: Change msglevel flags to int
......................................................................

Change msglevel flags to int

The API said they are unsigned, but most callers
actually used int. So this produced a LOT of
warnings when enabling -Wsign-conversion.

Since changing the API is actually a smaller change
than changing all the callers, we do that.

Change-Id: I4b0078d099e975d223825194ad104945b1247554
Signed-off-by: Frank Lichtenheld <[email protected]>
---
M src/openvpn/crypto_mbedtls.c
M src/openvpn/crypto_mbedtls.h
M src/openvpn/crypto_openssl.c
M src/openvpn/crypto_openssl.h
M src/openvpn/error.c
M src/openvpn/error.h
M src/openvpn/manage.c
M src/openvpn/manage.h
M src/openvpn/options.c
M src/openvpn/options.h
M src/openvpn/pkcs11.c
M src/openvpn/platform.c
M src/openvpn/plugin.c
M src/openvpn/proto.c
M src/openvpn/status.h
M src/openvpnmsica/dllmain.c
M src/tapctl/error.c
M src/tapctl/error.h
M src/tapctl/main.c
M tests/unit_tests/openvpn/mock_msg.c
M tests/unit_tests/openvpn/test_cryptoapi.c
M tests/unit_tests/openvpn/test_pkcs11.c
22 files changed, 71 insertions(+), 72 deletions(-)



  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/89/1189/1

diff --git a/src/openvpn/crypto_mbedtls.c b/src/openvpn/crypto_mbedtls.c
index 0c15812..3c2b66f 100644
--- a/src/openvpn/crypto_mbedtls.c
+++ b/src/openvpn/crypto_mbedtls.c
@@ -105,7 +105,7 @@
 }

 bool
-mbed_log_err(unsigned int flags, int errval, const char *prefix)
+mbed_log_err(int flags, int errval, const char *prefix)
 {
     if (0 != errval)
     {
@@ -123,7 +123,7 @@
 }

 bool
-mbed_log_func_line(unsigned int flags, int errval, const char *func, int line)
+mbed_log_func_line(int flags, int errval, const char *func, int line)
 {
     char prefix[256];

diff --git a/src/openvpn/crypto_mbedtls.h b/src/openvpn/crypto_mbedtls.h
index 80f1d16..c9d4fe6 100644
--- a/src/openvpn/crypto_mbedtls.h
+++ b/src/openvpn/crypto_mbedtls.h
@@ -106,7 +106,7 @@
  *
  * @returns true if no errors are detected, false otherwise.
  */
-bool mbed_log_err(unsigned int flags, int errval, const char *prefix);
+bool mbed_log_err(int flags, int errval, const char *prefix);

 /**
  * Log the supplied mbed TLS error, prefixed by function name and line number.
@@ -118,11 +118,11 @@
  *
  * @returns true if no errors are detected, false otherwise.
  */
-bool mbed_log_func_line(unsigned int flags, int errval, const char *func, int 
line);
+bool mbed_log_func_line(int flags, int errval, const char *func, int line);

 /** Wraps mbed_log_func_line() to prevent function calls for non-errors */
 static inline bool
-mbed_log_func_line_lite(unsigned int flags, int errval, const char *func, int 
line)
+mbed_log_func_line_lite(int flags, int errval, const char *func, int line)
 {
     if (errval)
     {
diff --git a/src/openvpn/crypto_openssl.c b/src/openvpn/crypto_openssl.c
index 19ca88c..bacc89f 100644
--- a/src/openvpn/crypto_openssl.c
+++ b/src/openvpn/crypto_openssl.c
@@ -227,7 +227,7 @@
 }

 void
-crypto_print_openssl_errors(const unsigned int flags)
+crypto_print_openssl_errors(const int flags)
 {
     unsigned long err = 0;
     int line, errflags;
diff --git a/src/openvpn/crypto_openssl.h b/src/openvpn/crypto_openssl.h
index 6218b39..21dae4f 100644
--- a/src/openvpn/crypto_openssl.h
+++ b/src/openvpn/crypto_openssl.h
@@ -103,7 +103,7 @@
  *
  * @param flags         Flags to indicate error type and priority.
  */
-void crypto_print_openssl_errors(const unsigned int flags);
+void crypto_print_openssl_errors(const int flags);

 /**
  * Retrieve any OpenSSL errors, then print the supplied error message.
diff --git a/src/openvpn/error.c b/src/openvpn/error.c
index 1b98235..8043afe 100644
--- a/src/openvpn/error.c
+++ b/src/openvpn/error.c
@@ -48,7 +48,7 @@
 #endif

 /* Globals */
-unsigned int x_debug_level; /* GLOBAL */
+int x_debug_level; /* GLOBAL */

 /* Mute state */
 static int mute_cutoff;   /* GLOBAL */
@@ -101,7 +101,7 @@
 }

 bool
-set_debug_level(const int level, const unsigned int flags)
+set_debug_level(const int level, const int flags)
 {
     const int ceiling = 15;

@@ -190,7 +190,7 @@
  * Return a file to print messages to before syslog is opened.
  */
 FILE *
-msg_fp(const unsigned int flags)
+msg_fp(const int flags)
 {
     FILE *fp = msgfp;
     if (!fp)
@@ -214,7 +214,7 @@
 int x_msg_line_num; /* GLOBAL */

 void
-x_msg(const unsigned int flags, const char *format, ...)
+x_msg(const int flags, const char *format, ...)
 {
     va_list arglist;
     va_start(arglist, format);
@@ -235,7 +235,7 @@
 }

 void
-x_msg_va(const unsigned int flags, const char *format, va_list arglist)
+x_msg_va(const int flags, const char *format, va_list arglist)
 {
     struct gc_arena gc;
 #if SYSLOG_CAPABILITY
@@ -385,7 +385,7 @@
  * Apply muting filter.
  */
 bool
-dont_mute(unsigned int flags)
+dont_mute(int flags)
 {
     bool ret = true;
     if (mute_cutoff > 0 && !(flags & M_NOMUTE))
@@ -599,9 +599,9 @@
  * of I/O operations.
  */

-unsigned int x_cs_info_level;    /* GLOBAL */
-unsigned int x_cs_verbose_level; /* GLOBAL */
-unsigned int x_cs_err_delay_ms;  /* GLOBAL */
+int x_cs_info_level;            /* GLOBAL */
+int x_cs_verbose_level;         /* GLOBAL */
+unsigned int x_cs_err_delay_ms; /* GLOBAL */

 void
 reset_check_status(void)
@@ -611,7 +611,7 @@
 }

 void
-set_check_status(unsigned int info_level, unsigned int verbose_level)
+set_check_status(int info_level, int verbose_level)
 {
     x_cs_info_level = info_level;
     x_cs_verbose_level = verbose_level;
@@ -750,7 +750,7 @@
  * Translate msg flags into a string
  */
 const char *
-msg_flags_string(const unsigned int flags, struct gc_arena *gc)
+msg_flags_string(const int flags, struct gc_arena *gc)
 {
     struct buffer out = alloc_buf_gc(16, gc);
     if (flags == M_INFO)
diff --git a/src/openvpn/error.h b/src/openvpn/error.h
index 8388f82..babb42f 100644
--- a/src/openvpn/error.h
+++ b/src/openvpn/error.h
@@ -78,7 +78,7 @@
  * These globals should not be accessed directly,
  * but rather through macros or inline functions defined below.
  */
-extern unsigned int x_debug_level;
+extern int x_debug_level;
 extern int x_msg_line_num;

 /* msg() flags */
@@ -135,7 +135,7 @@
  */

 /** Check muting filter */
-bool dont_mute(unsigned int flags);
+bool dont_mute(int flags);

 /* Macro to ensure (and teach static analysis tools) we exit on fatal errors */
 #define EXIT_FATAL(flags)      \
@@ -170,7 +170,7 @@
 #define dmsg(flags, ...)
 #endif

-void x_msg(const unsigned int flags, const char *format, ...)
+void x_msg(const int flags, const char *format, ...)
 #ifdef __GNUC__
 #if __USE_MINGW_ANSI_STDIO
     __attribute__((format(gnu_printf, 2, 3)))
@@ -180,7 +180,7 @@
 #endif
     ; /* should be called via msg above */

-void x_msg_va(const unsigned int flags, const char *format, va_list arglist);
+void x_msg_va(const int flags, const char *format, va_list arglist);

 /*
  * Function prototypes
@@ -197,7 +197,7 @@


 #define SDL_CONSTRAIN (1 << 0)
-bool set_debug_level(const int level, const unsigned int flags);
+bool set_debug_level(const int level, const int flags);

 bool set_mute_cutoff(const int cutoff);

@@ -205,12 +205,12 @@

 int get_mute_cutoff(void);

-const char *msg_flags_string(const unsigned int flags, struct gc_arena *gc);
+const char *msg_flags_string(const int flags, struct gc_arena *gc);

 /*
  * File to print messages to before syslog is opened.
  */
-FILE *msg_fp(const unsigned int flags);
+FILE *msg_fp(const int flags);

 /* Fatal logic errors */
 #ifndef ENABLE_SMALL
@@ -254,14 +254,14 @@
 /* Inline functions */

 static inline bool
-check_debug_level(unsigned int level)
+check_debug_level(int level)
 {
     return (level & M_DEBUG_LEVEL) <= x_debug_level;
 }

 /** Return true if flags represent an enabled, not muted log level */
 static inline bool
-msg_test(unsigned int flags)
+msg_test(int flags)
 {
     return check_debug_level(flags) && dont_mute(flags);
 }
@@ -297,13 +297,13 @@
 struct link_socket;
 struct tuntap;

-extern unsigned int x_cs_info_level;
-extern unsigned int x_cs_verbose_level;
+extern int x_cs_info_level;
+extern int x_cs_verbose_level;
 extern unsigned int x_cs_err_delay_ms;

 void reset_check_status(void);

-void set_check_status(unsigned int info_level, unsigned int verbose_level);
+void set_check_status(int info_level, int verbose_level);

 void x_check_status(int status, const char *description, struct link_socket 
*sock,
                     struct tuntap *tt);
@@ -400,8 +400,8 @@
 }

 /** Convert fatal errors to nonfatal, don't touch other errors */
-static inline unsigned int
-nonfatal(const unsigned int err)
+static inline int
+nonfatal(const int err)
 {
     return err & M_FATAL ? (err ^ M_FATAL) | M_NONFATAL : err;
 }
@@ -409,21 +409,20 @@
 static inline int
 openvpn_errno_maybe_crt(bool *crt_error)
 {
-    int err = 0;
     *crt_error = false;
 #ifdef _WIN32
-    err = GetLastError();
+    int err = (int)GetLastError();
     if (err == ERROR_SUCCESS)
     {
         /* error is likely C runtime */
         *crt_error = true;
         err = errno;
     }
+    return err;
 #else /* ifdef _WIN32 */
     *crt_error = true;
-    err = errno;
+    return errno;
 #endif
-    return err;
 }

 #include "errlevel.h"
diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c
index 4f37bd2..87981d2 100644
--- a/src/openvpn/manage.c
+++ b/src/openvpn/manage.c
@@ -352,7 +352,7 @@
 }

 static void
-virtual_output_callback_func(void *arg, const unsigned int flags, const char 
*str)
+virtual_output_callback_func(void *arg, const int flags, const char *str)
 {
     struct management *man = (struct management *)arg;
     static int recursive_level = 0; /* GLOBAL */
diff --git a/src/openvpn/manage.h b/src/openvpn/manage.h
index 7c189ba..7196210 100644
--- a/src/openvpn/manage.h
+++ b/src/openvpn/manage.h
@@ -98,7 +98,7 @@

 union log_entry_union
 {
-    unsigned int msg_flags;
+    int msg_flags;
     int state;
     int intval;
 };
diff --git a/src/openvpn/options.c b/src/openvpn/options.c
index e47d54c..22b36a3 100644
--- a/src/openvpn/options.c
+++ b/src/openvpn/options.c
@@ -4869,7 +4869,7 @@

 #ifdef _WIN32
 void
-show_windows_version(const unsigned int flags)
+show_windows_version(const int flags)
 {
     struct gc_arena gc = gc_new();
     msg(flags, "Windows version: %s", win32_version_string(&gc));
@@ -4878,7 +4878,7 @@
 #endif

 void
-show_dco_version(const unsigned int flags)
+show_dco_version(const int flags)
 {
 #ifdef ENABLE_DCO
     struct gc_arena gc = gc_new();
@@ -4888,7 +4888,7 @@
 }

 void
-show_library_versions(const unsigned int flags)
+show_library_versions(const int flags)
 {
 #ifdef ENABLE_LZO
 #define LZO_LIB_VER_STR ", LZO ", lzo_version_string()
diff --git a/src/openvpn/options.h b/src/openvpn/options.h
index bb2c052..b8efdf8 100644
--- a/src/openvpn/options.h
+++ b/src/openvpn/options.h
@@ -830,14 +830,14 @@

 void usage_small(void);

-void show_library_versions(const unsigned int flags);
+void show_library_versions(const int flags);

 #ifdef _WIN32
-void show_windows_version(const unsigned int flags);
+void show_windows_version(const int flags);

 #endif

-void show_dco_version(const unsigned int flags);
+void show_dco_version(const int flags);

 void init_options(struct options *o, const bool init_gc);

diff --git a/src/openvpn/pkcs11.c b/src/openvpn/pkcs11.c
index d9c16d9..ba81c54 100644
--- a/src/openvpn/pkcs11.c
+++ b/src/openvpn/pkcs11.c
@@ -77,10 +77,10 @@
 #endif
 };

-static unsigned
-_pkcs11_msg_pkcs112openvpn(const unsigned flags)
+static int
+_pkcs11_msg_pkcs112openvpn(const unsigned int flags)
 {
-    unsigned openvpn_flags;
+    int openvpn_flags;

     switch (flags)
     {
@@ -117,7 +117,7 @@
 }

 static unsigned
-_pkcs11_msg_openvpn2pkcs11(const unsigned flags)
+_pkcs11_msg_openvpn2pkcs11(const int flags)
 {
     unsigned pkcs11_flags;

diff --git a/src/openvpn/platform.c b/src/openvpn/platform.c
index 880d14e..78c56d3 100644
--- a/src/openvpn/platform.c
+++ b/src/openvpn/platform.c
@@ -223,7 +223,7 @@
                         const struct platform_state_group *group_state, struct 
context *c)
 {
     int keep_caps = need_keep_caps(c);
-    unsigned int err_flags = (keep_caps > 0) ? M_FATAL : M_NONFATAL;
+    int err_flags = (keep_caps > 0) ? M_FATAL : M_NONFATAL;
 #ifdef HAVE_LIBCAPNG
     int new_gid = -1, new_uid = -1;
     int res;
diff --git a/src/openvpn/plugin.c b/src/openvpn/plugin.c
index ea76a08..b14ce5c 100644
--- a/src/openvpn/plugin.c
+++ b/src/openvpn/plugin.c
@@ -371,7 +371,7 @@
 static void
 plugin_vlog(openvpn_plugin_log_flags_t flags, const char *name, const char 
*format, va_list arglist)
 {
-    unsigned int msg_flags = 0;
+    int msg_flags = 0;

     if (!format)
     {
diff --git a/src/openvpn/proto.c b/src/openvpn/proto.c
index 34b3378..b0373df 100644
--- a/src/openvpn/proto.c
+++ b/src/openvpn/proto.c
@@ -183,7 +183,7 @@
             int hlen;
             int totlen;
             const char *msgstr = "PACKET SIZE INFO";
-            unsigned int msglevel = D_PACKET_TRUNC_DEBUG;
+            int msglevel = D_PACKET_TRUNC_DEBUG;

             if (BLEN(&buf) < (int)sizeof(struct openvpn_iphdr))
             {
diff --git a/src/openvpn/status.h b/src/openvpn/status.h
index 0c7a869..c318683 100644
--- a/src/openvpn/status.h
+++ b/src/openvpn/status.h
@@ -32,11 +32,11 @@
 {
     void *arg;
     unsigned int flags_default;
-    void (*func)(void *arg, const unsigned int flags, const char *str);
+    void (*func)(void *arg, const int flags, const char *str);
 };

 static inline void
-virtual_output_print(const struct virtual_output *vo, const unsigned int 
flags, const char *str)
+virtual_output_print(const struct virtual_output *vo, const int flags, const 
char *str)
 {
     (*vo->func)(vo->arg, flags, str);
 }
diff --git a/src/openvpnmsica/dllmain.c b/src/openvpnmsica/dllmain.c
index e7d4a4b..8b1b7e9 100644
--- a/src/openvpnmsica/dllmain.c
+++ b/src/openvpnmsica/dllmain.c
@@ -91,7 +91,7 @@


 bool
-dont_mute(unsigned int flags)
+dont_mute(int flags)
 {
     UNREFERENCED_PARAMETER(flags);

@@ -100,7 +100,7 @@


 void
-x_msg_va(const unsigned int flags, const char *format, va_list arglist)
+x_msg_va(const int flags, const char *format, va_list arglist)
 {
     /* Secure last error before it is overridden. */
     DWORD dwResult = (flags & M_ERRNO) != 0 ? GetLastError() : ERROR_SUCCESS;
diff --git a/src/tapctl/error.c b/src/tapctl/error.c
index 9f5094e..27a475a 100644
--- a/src/tapctl/error.c
+++ b/src/tapctl/error.c
@@ -22,11 +22,11 @@


 /* Globals */
-unsigned int x_debug_level; /* GLOBAL */
+int x_debug_level; /* GLOBAL */


 void
-x_msg(const unsigned int flags, const char *format, ...)
+x_msg(const int flags, const char *format, ...)
 {
     va_list arglist;
     va_start(arglist, format);
diff --git a/src/tapctl/error.h b/src/tapctl/error.h
index fb24a61..ee9909a 100644
--- a/src/tapctl/error.h
+++ b/src/tapctl/error.h
@@ -29,7 +29,7 @@
  * These globals should not be accessed directly,
  * but rather through macros or inline functions defined below.
  */
-extern unsigned int x_debug_level;
+extern int x_debug_level;
 extern int x_msg_line_num;

 /* msg() flags */
@@ -58,7 +58,7 @@


 /** Check muting filter */
-bool dont_mute(unsigned int flags);
+bool dont_mute(int flags);

 /* Macro to ensure (and teach static analysis tools) we exit on fatal errors */
 #ifdef _MSC_VER
@@ -97,21 +97,21 @@
 #define dmsg(flags, ...)
 #endif

-void x_msg(const unsigned int flags, const char *format, ...); /* should be 
called via msg above */
+void x_msg(const int flags, const char *format, ...); /* should be called via 
msg above */

-void x_msg_va(const unsigned int flags, const char *format, va_list arglist);
+void x_msg_va(const int flags, const char *format, va_list arglist);
 
 /* Inline functions */

 static inline bool
-check_debug_level(unsigned int level)
+check_debug_level(int level)
 {
     return (level & M_DEBUG_LEVEL) <= x_debug_level;
 }

 /** Return true if flags represent and enabled, not muted log level */
 static inline bool
-msg_test(unsigned int flags)
+msg_test(int flags)
 {
     return check_debug_level(flags) && dont_mute(flags);
 }
diff --git a/src/tapctl/main.c b/src/tapctl/main.c
index 031e262..52cc8e22 100644
--- a/src/tapctl/main.c
+++ b/src/tapctl/main.c
@@ -479,7 +479,7 @@


 bool
-dont_mute(unsigned int flags)
+dont_mute(int flags)
 {
     UNREFERENCED_PARAMETER(flags);

@@ -488,7 +488,7 @@
 

 void
-x_msg_va(const unsigned int flags, const char *format, va_list arglist)
+x_msg_va(const int flags, const char *format, va_list arglist)
 {
     /* Output message string. Note: Message strings don't contain line 
terminators. */
     vfprintf(stderr, format, arglist);
diff --git a/tests/unit_tests/openvpn/mock_msg.c 
b/tests/unit_tests/openvpn/mock_msg.c
index 603520b..a2d9c72 100644
--- a/tests/unit_tests/openvpn/mock_msg.c
+++ b/tests/unit_tests/openvpn/mock_msg.c
@@ -38,8 +38,8 @@
 #include "error.h"
 #include "mock_msg.h"

-unsigned int x_debug_level = 0; /* Default to (almost) no debugging output */
-unsigned int print_x_debug_level = 0;
+int x_debug_level = 0; /* Default to (almost) no debugging output */
+int print_x_debug_level = 0;

 bool fatal_error_triggered = false;

@@ -71,7 +71,7 @@
 }

 void
-x_msg_va(const unsigned int flags, const char *format, va_list arglist)
+x_msg_va(const int flags, const char *format, va_list arglist)
 {
     if (flags & M_FATAL)
     {
@@ -89,7 +89,7 @@
 }

 void
-x_msg(const unsigned int flags, const char *format, ...)
+x_msg(const int flags, const char *format, ...)
 {
     va_list arglist;
     va_start(arglist, format);
@@ -128,7 +128,7 @@
 }

 bool
-dont_mute(unsigned int flags)
+dont_mute(int flags)
 {
     return true;
 }
diff --git a/tests/unit_tests/openvpn/test_cryptoapi.c 
b/tests/unit_tests/openvpn/test_cryptoapi.c
index 6e83465..cff9547 100644
--- a/tests/unit_tests/openvpn/test_cryptoapi.c
+++ b/tests/unit_tests/openvpn/test_cryptoapi.c
@@ -59,7 +59,7 @@

 /* replacement for crypto_print_openssl_errors() */
 void
-crypto_print_openssl_errors(const unsigned int flags)
+crypto_print_openssl_errors(const int flags)
 {
     unsigned long e;
     while ((e = ERR_get_error()))
diff --git a/tests/unit_tests/openvpn/test_pkcs11.c 
b/tests/unit_tests/openvpn/test_pkcs11.c
index 9ba6cfc..961d78b 100644
--- a/tests/unit_tests/openvpn/test_pkcs11.c
+++ b/tests/unit_tests/openvpn/test_pkcs11.c
@@ -47,7 +47,7 @@

 /* replacement for crypto_print_openssl_errors() */
 void
-crypto_print_openssl_errors(const unsigned int flags)
+crypto_print_openssl_errors(const int flags)
 {
     unsigned long e;
     while ((e = ERR_get_error()))

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

Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I4b0078d099e975d223825194ad104945b1247554
Gerrit-Change-Number: 1189
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]>
Gerrit-Reviewer: plaisthos <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Reply via email to