From: Frank Lichtenheld <[email protected]> Due to the int return of vsnprintf this is always going to be somewhat ugly.
Change-Id: Id5152a5aacdd50f2fa9c5b3dfab92be8887541db Signed-off-by: Frank Lichtenheld <[email protected]> Acked-by: Razvan Cojocaru <[email protected]> Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2340 --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/2340 This mail reflects revision 1 of this Change. Acked-by according to Gerrit (reflected above): Razvan Cojocaru <[email protected]> diff --git a/src/openvpn/argv.c b/src/openvpn/argv.c index c716e5b0..cf841a5 100644 --- a/src/openvpn/argv.c +++ b/src/openvpn/argv.c @@ -323,11 +323,6 @@ return f; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wsign-conversion" -#endif - /** * Create a struct argv based on a format string * @@ -378,9 +373,9 @@ */ va_list tmplist; va_copy(tmplist, arglist); - int len = vsnprintf(NULL, 0, f, tmplist); + int test_len = vsnprintf(NULL, 0, f, tmplist); va_end(tmplist); - if (len < 0) + if (test_len < 0) { goto out; } @@ -389,10 +384,10 @@ * Do the actual vsnprintf() operation, which expands the format * string with the provided arguments. */ - int size = len + 1; + size_t size = (size_t)test_len + 1; char *buf = gc_malloc(size, false, &argres->gc); - len = vsnprintf(buf, size, f, arglist); - if (len < 0 || len >= size) + int len = vsnprintf(buf, size, f, arglist); + if (len < 0 || len > test_len) { goto out; } @@ -423,10 +418,6 @@ return res; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - /** * printf() variant which populates a struct argv. It processes the * format string with the provided arguments. For each space separator found _______________________________________________ Openvpn-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/openvpn-devel
