* [Openvpn-devel] [PATCH] route: fix format string passed to argv_printf
@ 2018-06-22 10:21 Antonio Quartulli
2018-06-22 14:45 ` Selva Nair
2018-06-23 2:11 ` [Openvpn-devel] [PATCH v2] add support for %lu in argv_printf and prevent ASSERT Antonio Quartulli
0 siblings, 2 replies; 18+ messages in thread
From: Antonio Quartulli @ 2018-06-22 10:21 UTC (permalink / raw)
To: openvpn-devel; +Cc: Antonio Quartulli <a@
%lu is not supported by our tiny argv_printf implementation and will
trigger an ASSERT() when parsing it. Even though this particular
ASSERT() is not critical as it happens during shutdown, we still have to
fix it.
Since in this case the code is trying to use a DWORD variable as
argument, and we know that DWORD is an unsigned long, which in turn is
32bit long on MS Windows (32 and 64bit version)[1][2], simply use
the already supported %u instead of %lu.
[1]https://msdn.microsoft.com/en-us/library/aa383751(VS.85).aspx
[2]https://en.wikipedia.org/wiki/Integer_(computer_science)#Long_integer
Signed-off-by: Antonio Quartulli <a@...2181...>
---
src/openvpn/route.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/openvpn/route.c b/src/openvpn/route.c
index a45a273a..209daeab 100644
--- a/src/openvpn/route.c
+++ b/src/openvpn/route.c
@@ -1616,7 +1616,7 @@ add_route(struct route_ipv4 *r, const struct tuntap *tt, unsigned int flags,
if (is_on_link(is_local_route, flags, rgi))
{
ai = rgi->adapter_index;
- argv_printf_cat(&argv, "IF %lu", ai);
+ argv_printf_cat(&argv, "IF %u", ai);
}
argv_msg(D_ROUTE, &argv);
--
2.17.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [Openvpn-devel] [PATCH] route: fix format string passed to argv_printf
2018-06-22 10:21 [Openvpn-devel] [PATCH] route: fix format string passed to argv_printf Antonio Quartulli
@ 2018-06-22 14:45 ` Selva Nair
2018-06-22 14:48 ` Antonio Quartulli
2018-06-23 2:11 ` [Openvpn-devel] [PATCH v2] add support for %lu in argv_printf and prevent ASSERT Antonio Quartulli
1 sibling, 1 reply; 18+ messages in thread
From: Selva Nair @ 2018-06-22 14:45 UTC (permalink / raw)
To: Antonio Quartulli <a@; +Cc: openvpn-devel
[-- Attachment #1: Type: text/plain, Size: 2007 bytes --]
Hi,
On Fri, Jun 22, 2018 at 6:21 AM, Antonio Quartulli <a@...2181...> wrote:
> %lu is not supported by our tiny argv_printf implementation and will
> trigger an ASSERT() when parsing it. Even though this particular
> ASSERT() is not critical as it happens during shutdown, we still have to
> fix it.
>
> Since in this case the code is trying to use a DWORD variable as
> argument, and we know that DWORD is an unsigned long, which in turn is
> 32bit long on MS Windows (32 and 64bit version)[1][2], simply use
> the already supported %u instead of %lu.
>
> [1]https://msdn.microsoft.com/en-us/library/aa383751(VS.85).aspx
> [2]https://en.wikipedia.org/wiki/Integer_(computer_science)#Long_integer
>
> Signed-off-by: Antonio Quartulli <a@...2181...>
> ---
> src/openvpn/route.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/openvpn/route.c b/src/openvpn/route.c
> index a45a273a..209daeab 100644
> --- a/src/openvpn/route.c
> +++ b/src/openvpn/route.c
> @@ -1616,7 +1616,7 @@ add_route(struct route_ipv4 *r, const struct tuntap
*tt, unsigned int flags,
> if (is_on_link(is_local_route, flags, rgi))
> {
> ai = rgi->adapter_index;
> - argv_printf_cat(&argv, "IF %lu", ai);
> + argv_printf_cat(&argv, "IF %u", ai);
> }
>
> argv_msg(D_ROUTE, &argv);
Thanks for cleaning up my mistake (commit
06ad53e067d9a8be571a27f44005fa7e8038f69e introduced this). One
purpose of that commit was to get rid of -Wformat warnings as those
are not always benign. But this will re-introduce a warning as "ai" is
unsigned long even though its the same size as unsigned.
Currently we do support building with -Werror=format (see
https://patchwork.openvpn.net/patch/234/#463), so I suggest either
cast to (unsigned) which we know is safe here, or add "%lu" to
argv_printf_arglist().
I would prefer the latter as its easy to overlook the fact that
argv_printf_cat() can't handle %lu which is commonly used
on Windows.
Selva
[-- Attachment #2: Type: text/html, Size: 2686 bytes --]
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Openvpn-devel] [PATCH] route: fix format string passed to argv_printf
2018-06-22 14:45 ` Selva Nair
@ 2018-06-22 14:48 ` Antonio Quartulli
2018-06-22 15:34 ` Gert Doering
2018-06-22 15:37 ` Selva Nair
0 siblings, 2 replies; 18+ messages in thread
From: Antonio Quartulli @ 2018-06-22 14:48 UTC (permalink / raw)
To: Selva Nair <selva.nair@; +Cc: openvpn-devel
[-- Attachment #1.1: Type: text/plain, Size: 1571 bytes --]
Hi,
On 22/06/18 22:45, Selva Nair wrote:
[cut]
>> --- a/src/openvpn/route.c
>> +++ b/src/openvpn/route.c
>> @@ -1616,7 +1616,7 @@ add_route(struct route_ipv4 *r, const struct tuntap
> *tt, unsigned int flags,
>> if (is_on_link(is_local_route, flags, rgi))
>> {
>> ai = rgi->adapter_index;
>> - argv_printf_cat(&argv, "IF %lu", ai);
>> + argv_printf_cat(&argv, "IF %u", ai);
>> }
>>
>> argv_msg(D_ROUTE, &argv);
>
> Thanks for cleaning up my mistake (commit
> 06ad53e067d9a8be571a27f44005fa7e8038f69e introduced this). One
> purpose of that commit was to get rid of -Wformat warnings as those
> are not always benign. But this will re-introduce a warning as "ai" is
> unsigned long even though its the same size as unsigned.
>
> Currently we do support building with -Werror=format (see
> https://patchwork.openvpn.net/patch/234/#463), so I suggest either
> cast to (unsigned) which we know is safe here, or add "%lu" to
> argv_printf_arglist().
>
> I would prefer the latter as its easy to overlook the fact that
> argv_printf_cat() can't handle %lu which is commonly used
> on Windows.
I was just about to test a v2 of this patch with the explicit cast to
"unsigned int". I was leaning towards the explicit cast because we
already print DWORD variables in several spots and we always cast them
to int or unsigned int.
However, if we believe supporting %lu can be more useful, I can do that.
Last opinion? :)
Cheers,
--
Antonio Quartulli
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Openvpn-devel] [PATCH] route: fix format string passed to argv_printf
2018-06-22 14:48 ` Antonio Quartulli
@ 2018-06-22 15:34 ` Gert Doering
2018-06-22 15:37 ` Selva Nair
1 sibling, 0 replies; 18+ messages in thread
From: Gert Doering @ 2018-06-22 15:34 UTC (permalink / raw)
To: Antonio Quartulli <a@; +Cc: Selva Nair <selva.nair@
[-- Attachment #1: Type: text/plain, Size: 838 bytes --]
Hi,
On Fri, Jun 22, 2018 at 10:48:30PM +0800, Antonio Quartulli wrote:
> However, if we believe supporting %lu can be more useful, I can do that.
I tend to add "%lu" to argv.c (which might eventually come back to bite
me, as there are still patches from Heiko pending wrt argv IIRC).
Since we make the same mistake again and again, we shouldn't cast around
it but just make it work :-) - and it's not a lot of extra code, nicely
isolated.
gert
--
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany gert@...1296...
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 630 bytes --]
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Openvpn-devel] [PATCH] route: fix format string passed to argv_printf
2018-06-22 14:48 ` Antonio Quartulli
2018-06-22 15:34 ` Gert Doering
@ 2018-06-22 15:37 ` Selva Nair
2018-06-22 15:39 ` Antonio Quartulli
1 sibling, 1 reply; 18+ messages in thread
From: Selva Nair @ 2018-06-22 15:37 UTC (permalink / raw)
To: Antonio Quartulli <a@; +Cc: openvpn-devel
[-- Attachment #1: Type: text/plain, Size: 2056 bytes --]
Hi,
On Fri, Jun 22, 2018 at 10:48 AM, Antonio Quartulli <a@...2181...> wrote:
> Hi,
>
> On 22/06/18 22:45, Selva Nair wrote:
> [cut]
> >> --- a/src/openvpn/route.c
> >> +++ b/src/openvpn/route.c
> >> @@ -1616,7 +1616,7 @@ add_route(struct route_ipv4 *r, const struct
> tuntap
> > *tt, unsigned int flags,
> >> if (is_on_link(is_local_route, flags, rgi))
> >> {
> >> ai = rgi->adapter_index;
> >> - argv_printf_cat(&argv, "IF %lu", ai);
> >> + argv_printf_cat(&argv, "IF %u", ai);
> >> }
> >>
> >> argv_msg(D_ROUTE, &argv);
> >
> > Thanks for cleaning up my mistake (commit
> > 06ad53e067d9a8be571a27f44005fa7e8038f69e introduced this). One
> > purpose of that commit was to get rid of -Wformat warnings as those
> > are not always benign. But this will re-introduce a warning as "ai" is
> > unsigned long even though its the same size as unsigned.
> >
> > Currently we do support building with -Werror=format (see
> > https://patchwork.openvpn.net/patch/234/#463), so I suggest either
> > cast to (unsigned) which we know is safe here, or add "%lu" to
> > argv_printf_arglist().
> >
> > I would prefer the latter as its easy to overlook the fact that
> > argv_printf_cat() can't handle %lu which is commonly used
> > on Windows.
>
> I was just about to test a v2 of this patch with the explicit cast to
> "unsigned int". I was leaning towards the explicit cast because we
> already print DWORD variables in several spots and we always cast them
> to int or unsigned int.
>
We used to have some printed with even %d and no cast. The last time we
cleaned up the offending ones and removed a few casts nearby.
However, if we believe supporting %lu can be more useful, I can do that.
>
> Last opinion? :)
>
I prefer "%lu" and no cast and have been replacing %u by %lu elsewhere in
the code given a chance.
There are a lots DWORD to (unsigned) in tun.c and elsewhere but there is no
compelling reason to change them. We should get rid of casts to (int) when
possible, though.
Selva
[-- Attachment #2: Type: text/html, Size: 3060 bytes --]
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Openvpn-devel] [PATCH] route: fix format string passed to argv_printf
2018-06-22 15:37 ` Selva Nair
@ 2018-06-22 15:39 ` Antonio Quartulli
0 siblings, 0 replies; 18+ messages in thread
From: Antonio Quartulli @ 2018-06-22 15:39 UTC (permalink / raw)
To: Selva Nair <selva.nair@; +Cc: openvpn-devel
[-- Attachment #1.1: Type: text/plain, Size: 490 bytes --]
Hi
On 22/06/18 23:37, Selva Nair wrote:
>> Last opinion? :)
>>
>
> I prefer "%lu" and no cast and have been replacing %u by %lu elsewhere in
> the code given a chance.
You and Gert both replied at the same time with the same preference of
supporting %lu. And I think all the arguments are valid - that is just
the right thing in this case so we can avoid shortcut/forced casts.
Will send v2 with this change included.
Thanks all!
Cheers,
--
Antonio Quartulli
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 18+ messages in thread
* [Openvpn-devel] [PATCH v2] add support for %lu in argv_printf and prevent ASSERT
2018-06-22 10:21 [Openvpn-devel] [PATCH] route: fix format string passed to argv_printf Antonio Quartulli
2018-06-22 14:45 ` Selva Nair
@ 2018-06-23 2:11 ` Antonio Quartulli
2018-06-23 12:09 ` [Openvpn-devel] [PATCH applied] " Gert Doering
1 sibling, 1 reply; 18+ messages in thread
From: Antonio Quartulli @ 2018-06-23 2:11 UTC (permalink / raw)
To: openvpn-devel; +Cc: Antonio Quartulli <a@
%lu is not supported by our tiny argv_printf implementation, therefore
it will trigger an ASSERT() when parsing it at route.c:1638.
Add support for '%lu' in argv_print() and prevent the ASSERT from being
triggered.
Signed-off-by: Antonio Quartulli <a@...2181...>
---
It seems I managed to trigger this ASSERT when connecting to my v6-only
server with "gateway-redirect !ipv4 ipv6" set. Not sure why this issue
hasn't surfaced earlier though.
Changes from v1:
- keep format string as "%lu" but add support for it in argv_printf()
- tested on Windows 10 on top of the ipv6-only branch
src/openvpn/argv.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/src/openvpn/argv.c b/src/openvpn/argv.c
index dec7e3bf..9100a196 100644
--- a/src/openvpn/argv.c
+++ b/src/openvpn/argv.c
@@ -251,6 +251,13 @@ argv_printf_arglist(struct argv *a, const char *format, va_list arglist)
openvpn_snprintf(numstr, sizeof(numstr), "%u", va_arg(arglist, unsigned int));
argv_append(a, string_alloc(numstr, NULL));
}
+ else if (!strcmp(term, "%lu"))
+ {
+ char numstr[64];
+ openvpn_snprintf(numstr, sizeof(numstr), "%lu",
+ va_arg(arglist, unsigned long));
+ argv_append(a, string_alloc(numstr, NULL));
+ }
else if (!strcmp(term, "%s/%d"))
{
char numstr[64];
--
2.17.1
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [Openvpn-devel] [PATCH applied] Re: add support for %lu in argv_printf and prevent ASSERT
2018-06-23 2:11 ` [Openvpn-devel] [PATCH v2] add support for %lu in argv_printf and prevent ASSERT Antonio Quartulli
@ 2018-06-23 12:09 ` Gert Doering
2018-06-23 12:15 ` [Openvpn-devel] [PATCH] Add %d, %u and %lu tests to test_argv unit tests Gert Doering
0 siblings, 1 reply; 18+ messages in thread
From: Gert Doering @ 2018-06-23 12:09 UTC (permalink / raw)
To: Antonio Quartulli <a@; +Cc: openvpn-devel
Acked-by: Gert Doering <gert@...1296...>
The code is trivially correct, and it does what it says on the lid :-)
- and to verify, I've added a unit test to test_argv.c - attached below,
we might consider adding something like this, or something more elaborate
for all supported argv*() arguments...
Your patch has been applied to the master and release/2.4 branch
("someone will fix something else some day, relying on the existance
of %lu, and then 2.4 will surprisingly explode").
commit e38d3a004195f33c5c04fe7c04db5d66c53241bc (master)
commit 61dcf1513d69ddf1261402744496436923ec14bb (release/2.4)
Author: Antonio Quartulli
Date: Sat Jun 23 10:11:47 2018 +0800
add support for %lu in argv_printf and prevent ASSERT
Signed-off-by: Antonio Quartulli <a@...2181...>
Acked-by: Gert Doering <gert@...1296...>
Message-Id: <20180623021147.22792-1-a@...2181...>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg17115.html
Signed-off-by: Gert Doering <gert@...1296...>
----------
diff --git a/tests/unit_tests/openvpn/test_argv.c b/tests/unit_tests/openvpn/test_argv.c
index 4a3ba559..0e7a4513 100644
--- a/tests/unit_tests/openvpn/test_argv.c
+++ b/tests/unit_tests/openvpn/test_argv.c
@@ -116,8 +116,12 @@ argv_str__multiple_argv__correct_output(void **state)
argv_printf(&a, "%s%sc", PATH1, PATH2);
argv_printf_cat(&a, "%s", PARAM1);
argv_printf_cat(&a, "%s", PARAM2);
+ argv_printf_cat(&a, "%d", -1);
+ argv_printf_cat(&a, "%u", -1);
+ argv_printf_cat(&a, "%lu", (unsigned long) (1L<<33) );
output = argv_str(&a, &gc, PA_BRACKET);
- assert_string_equal(output, "[" PATH1 PATH2 "] [" PARAM1 "] [" PARAM2 "]");
+ assert_string_equal(output, "[" PATH1 PATH2 "] [" PARAM1 "] [" PARAM2 "]"
+ " [-1] [4294967295] [8589934592]");
argv_reset(&a);
gc_free(&gc);
--
kind regards,
Gert Doering
^ permalink raw reply related [flat|nested] 18+ messages in thread
* [Openvpn-devel] [PATCH] Add %d, %u and %lu tests to test_argv unit tests.
2018-06-23 12:09 ` [Openvpn-devel] [PATCH applied] " Gert Doering
@ 2018-06-23 12:15 ` Gert Doering
2018-06-23 17:31 ` Gert Doering
0 siblings, 1 reply; 18+ messages in thread
From: Gert Doering @ 2018-06-23 12:15 UTC (permalink / raw)
To: openvpn-devel
Some basic integer tests to verify signed, unsigned and
long unsigned (2^33) printing.
Signed-off-by: Gert Doering <gert@...1296...>
---
tests/unit_tests/openvpn/test_argv.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/tests/unit_tests/openvpn/test_argv.c b/tests/unit_tests/openvpn/test_argv.c
index 4a3ba559..0e7a4513 100644
--- a/tests/unit_tests/openvpn/test_argv.c
+++ b/tests/unit_tests/openvpn/test_argv.c
@@ -116,8 +116,12 @@ argv_str__multiple_argv__correct_output(void **state)
argv_printf(&a, "%s%sc", PATH1, PATH2);
argv_printf_cat(&a, "%s", PARAM1);
argv_printf_cat(&a, "%s", PARAM2);
+ argv_printf_cat(&a, "%d", -1);
+ argv_printf_cat(&a, "%u", -1);
+ argv_printf_cat(&a, "%lu", (unsigned long) (1L<<33) );
output = argv_str(&a, &gc, PA_BRACKET);
- assert_string_equal(output, "[" PATH1 PATH2 "] [" PARAM1 "] [" PARAM2 "]");
+ assert_string_equal(output, "[" PATH1 PATH2 "] [" PARAM1 "] [" PARAM2 "]"
+ " [-1] [4294967295] [8589934592]");
argv_reset(&a);
gc_free(&gc);
--
2.16.4
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [Openvpn-devel] [PATCH] Add %d, %u and %lu tests to test_argv unit tests.
2018-06-23 12:15 ` [Openvpn-devel] [PATCH] Add %d, %u and %lu tests to test_argv unit tests Gert Doering
@ 2018-06-23 17:31 ` Gert Doering
2018-06-23 18:08 ` Selva Nair
2018-06-23 18:15 ` [Openvpn-devel] [PATCH v2] " Gert Doering
0 siblings, 2 replies; 18+ messages in thread
From: Gert Doering @ 2018-06-23 17:31 UTC (permalink / raw)
To: openvpn-devel
[-- Attachment #1: Type: text/plain, Size: 869 bytes --]
Hi,
On Sat, Jun 23, 2018 at 02:15:03PM +0200, Gert Doering wrote:
> Some basic integer tests to verify signed, unsigned and
> long unsigned (2^33) printing.
Ditch that patch... this only works on 64bit systems.
What I wanted to see is "yes, it really does long math", but on systems
where sizeof(int) = sizeof(long) = 4, this will just not do the right
thing.
Do we care?
Or shall I just have it print "1", so we know "%lu works and prints its
argument nicely"?
gert
--
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany gert@...1296...
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 630 bytes --]
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Openvpn-devel] [PATCH] Add %d, %u and %lu tests to test_argv unit tests.
2018-06-23 17:31 ` Gert Doering
@ 2018-06-23 18:08 ` Selva Nair
2018-06-23 18:12 ` Antonio Quartulli
2018-06-23 18:15 ` [Openvpn-devel] [PATCH v2] " Gert Doering
1 sibling, 1 reply; 18+ messages in thread
From: Selva Nair @ 2018-06-23 18:08 UTC (permalink / raw)
To: openvpn-devel
[-- Attachment #1: Type: text/plain, Size: 740 bytes --]
Hi,
On Sat, Jun 23, 2018 at 1:31 PM, Gert Doering <gert@...1296...> wrote:
> Hi,
>
> On Sat, Jun 23, 2018 at 02:15:03PM +0200, Gert Doering wrote:
> > Some basic integer tests to verify signed, unsigned and
> > long unsigned (2^33) printing.
>
> Ditch that patch... this only works on 64bit systems.
>
Most 64 bit systems (excluding Windows)
>
> What I wanted to see is "yes, it really does long math", but on systems
> where sizeof(int) = sizeof(long) = 4, this will just not do the right
> thing.
>
> Do we care?
>
> Or shall I just have it print "1", so we know "%lu works and prints its
> argument nicely"?
>
That should be enough, but we could get fancy and use -1L and compare
the result against sprintf(str, "%lu", -1L)
Selva
[-- Attachment #2: Type: text/html, Size: 1372 bytes --]
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Openvpn-devel] [PATCH] Add %d, %u and %lu tests to test_argv unit tests.
2018-06-23 18:08 ` Selva Nair
@ 2018-06-23 18:12 ` Antonio Quartulli
2018-06-23 18:16 ` Gert Doering
0 siblings, 1 reply; 18+ messages in thread
From: Antonio Quartulli @ 2018-06-23 18:12 UTC (permalink / raw)
To: Selva Nair <selva.nair@
[-- Attachment #1.1: Type: text/plain, Size: 557 bytes --]
Hi,
On 24/06/18 02:08, Selva Nair wrote:
>> Or shall I just have it print "1", so we know "%lu works and prints its
>> argument nicely"?
>>
>
> That should be enough, but we could get fancy and use -1L and compare
> the result against sprintf(str, "%lu", -1L)
>
I just recommended something similar on IRC.
I think it would make sense to "validate" argv_printf* against sprintf.
Not just for %lu but also for the other formats. This way we know our
code is doing what sprintf would also do.
Cheers,
--
Antonio Quartulli
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 18+ messages in thread
* [Openvpn-devel] [PATCH v2] Add %d, %u and %lu tests to test_argv unit tests.
2018-06-23 17:31 ` Gert Doering
2018-06-23 18:08 ` Selva Nair
@ 2018-06-23 18:15 ` Gert Doering
2018-06-23 19:11 ` Selva Nair
1 sibling, 1 reply; 18+ messages in thread
From: Gert Doering @ 2018-06-23 18:15 UTC (permalink / raw)
To: openvpn-devel
Some basic integer tests to verify signed, unsigned and
long unsigned (2^33) printing.
Signed-off-by: Gert Doering <gert@...1296...>
--
v2: test %lu with "1" as windows and linux/i386 do not have 64 bit long
---
tests/unit_tests/openvpn/test_argv.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/tests/unit_tests/openvpn/test_argv.c b/tests/unit_tests/openvpn/test_argv.c
index 4a3ba559..202a8ff5 100644
--- a/tests/unit_tests/openvpn/test_argv.c
+++ b/tests/unit_tests/openvpn/test_argv.c
@@ -116,8 +116,12 @@ argv_str__multiple_argv__correct_output(void **state)
argv_printf(&a, "%s%sc", PATH1, PATH2);
argv_printf_cat(&a, "%s", PARAM1);
argv_printf_cat(&a, "%s", PARAM2);
+ argv_printf_cat(&a, "%d", -1);
+ argv_printf_cat(&a, "%u", -1);
+ argv_printf_cat(&a, "%lu", 1 );
output = argv_str(&a, &gc, PA_BRACKET);
- assert_string_equal(output, "[" PATH1 PATH2 "] [" PARAM1 "] [" PARAM2 "]");
+ assert_string_equal(output, "[" PATH1 PATH2 "] [" PARAM1 "] [" PARAM2 "]"
+ " [-1] [4294967295] [1]");
argv_reset(&a);
gc_free(&gc);
--
2.16.4
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [Openvpn-devel] [PATCH] Add %d, %u and %lu tests to test_argv unit tests.
2018-06-23 18:12 ` Antonio Quartulli
@ 2018-06-23 18:16 ` Gert Doering
0 siblings, 0 replies; 18+ messages in thread
From: Gert Doering @ 2018-06-23 18:16 UTC (permalink / raw)
To: Antonio Quartulli <a@; +Cc: Selva Nair <selva.nair@
[-- Attachment #1: Type: text/plain, Size: 1048 bytes --]
Hi,
On Sun, Jun 24, 2018 at 02:12:29AM +0800, Antonio Quartulli wrote:
> > That should be enough, but we could get fancy and use -1L and compare
> > the result against sprintf(str, "%lu", -1L)
>
> I just recommended something similar on IRC.
> I think it would make sense to "validate" argv_printf* against sprintf.
> Not just for %lu but also for the other formats. This way we know our
> code is doing what sprintf would also do.
I'll go for the "just 1" thing so we have something.
If one of you feels bored, I'm happy to test something more fancy :-) -
but I do not feel particularily like "coming up with fancy tests for
argv.c" today.
gert
--
"If was one thing all people took for granted, was conviction that if you
feed honest figures into a computer, honest figures come out. Never doubted
it myself till I met a computer with a sense of humor."
Robert A. Heinlein, The Moon is a Harsh Mistress
Gert Doering - Munich, Germany gert@...1296...
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 630 bytes --]
^ permalink raw reply [flat|nested] 18+ messages in thread
* Re: [Openvpn-devel] [PATCH v2] Add %d, %u and %lu tests to test_argv unit tests.
2018-06-23 18:15 ` [Openvpn-devel] [PATCH v2] " Gert Doering
@ 2018-06-23 19:11 ` Selva Nair
2018-06-23 19:15 ` [Openvpn-devel] [PATCH v3] " Gert Doering
0 siblings, 1 reply; 18+ messages in thread
From: Selva Nair @ 2018-06-23 19:11 UTC (permalink / raw)
To: Gert Doering <gert@; +Cc: openvpn-devel
[-- Attachment #1: Type: text/plain, Size: 1671 bytes --]
Hi,
This is good enough, but (there is always a but :)
On Sat, Jun 23, 2018 at 2:15 PM, Gert Doering <gert@...1296...> wrote:
> Some basic integer tests to verify signed, unsigned and
> long unsigned (2^33) printing.
>
That 2^33 still lurking in the commit message could go..
>
> Signed-off-by: Gert Doering <gert@...1296...>
> --
> v2: test %lu with "1" as windows and linux/i386 do not have 64 bit long
> ---
> tests/unit_tests/openvpn/test_argv.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/tests/unit_tests/openvpn/test_argv.c
> b/tests/unit_tests/openvpn/test_argv.c
> index 4a3ba559..202a8ff5 100644
> --- a/tests/unit_tests/openvpn/test_argv.c
> +++ b/tests/unit_tests/openvpn/test_argv.c
> @@ -116,8 +116,12 @@ argv_str__multiple_argv__correct_output(void **state)
> argv_printf(&a, "%s%sc", PATH1, PATH2);
> argv_printf_cat(&a, "%s", PARAM1);
> argv_printf_cat(&a, "%s", PARAM2);
> + argv_printf_cat(&a, "%d", -1);
> + argv_printf_cat(&a, "%u", -1);
> + argv_printf_cat(&a, "%lu", 1 );
>
This triggers a -Wformat warning:
format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 3
has type ‘in’ [-Wformat=]
Suggest 1L instead of 1.
> output = argv_str(&a, &gc, PA_BRACKET);
> - assert_string_equal(output, "[" PATH1 PATH2 "] [" PARAM1 "] [" PARAM2
> "]");
> + assert_string_equal(output, "[" PATH1 PATH2 "] [" PARAM1 "] [" PARAM2
> "]"
> + " [-1] [4294967295] [1]");
> argv_reset(&a);
> gc_free(&gc);
>
ACK otherwise.
Good luck with the game.
Selva
[-- Attachment #2: Type: text/html, Size: 3156 bytes --]
^ permalink raw reply [flat|nested] 18+ messages in thread
* [Openvpn-devel] [PATCH v3] Add %d, %u and %lu tests to test_argv unit tests.
2018-06-23 19:11 ` Selva Nair
@ 2018-06-23 19:15 ` Gert Doering
2018-06-23 19:21 ` Selva Nair
2018-06-23 19:33 ` [Openvpn-devel] [PATCH applied] " Gert Doering
0 siblings, 2 replies; 18+ messages in thread
From: Gert Doering @ 2018-06-23 19:15 UTC (permalink / raw)
To: openvpn-devel
Some basic integer tests to verify signed, unsigned and
long unsigned (1L) printing.
Signed-off-by: Gert Doering <gert@...1296...>
--
v2: test %lu with "1" as windows and linux/i386 do not have 64 bit long
v3: fix 2^33 in commit message, use "1L" for proper data type (Selva)
---
tests/unit_tests/openvpn/test_argv.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/tests/unit_tests/openvpn/test_argv.c b/tests/unit_tests/openvpn/test_argv.c
index 4a3ba559..0fdd3f0a 100644
--- a/tests/unit_tests/openvpn/test_argv.c
+++ b/tests/unit_tests/openvpn/test_argv.c
@@ -116,8 +116,12 @@ argv_str__multiple_argv__correct_output(void **state)
argv_printf(&a, "%s%sc", PATH1, PATH2);
argv_printf_cat(&a, "%s", PARAM1);
argv_printf_cat(&a, "%s", PARAM2);
+ argv_printf_cat(&a, "%d", -1);
+ argv_printf_cat(&a, "%u", -1);
+ argv_printf_cat(&a, "%lu", 1L );
output = argv_str(&a, &gc, PA_BRACKET);
- assert_string_equal(output, "[" PATH1 PATH2 "] [" PARAM1 "] [" PARAM2 "]");
+ assert_string_equal(output, "[" PATH1 PATH2 "] [" PARAM1 "] [" PARAM2 "]"
+ " [-1] [4294967295] [1]");
argv_reset(&a);
gc_free(&gc);
--
2.16.4
^ permalink raw reply related [flat|nested] 18+ messages in thread
* Re: [Openvpn-devel] [PATCH v3] Add %d, %u and %lu tests to test_argv unit tests.
2018-06-23 19:15 ` [Openvpn-devel] [PATCH v3] " Gert Doering
@ 2018-06-23 19:21 ` Selva Nair
2018-06-23 19:33 ` [Openvpn-devel] [PATCH applied] " Gert Doering
1 sibling, 0 replies; 18+ messages in thread
From: Selva Nair @ 2018-06-23 19:21 UTC (permalink / raw)
To: Gert Doering <gert@; +Cc: openvpn-devel
[-- Attachment #1: Type: text/plain, Size: 1398 bytes --]
Hi,
On Sat, Jun 23, 2018 at 3:15 PM, Gert Doering <gert@...1296...> wrote:
> Some basic integer tests to verify signed, unsigned and
> long unsigned (1L) printing.
>
> Signed-off-by: Gert Doering <gert@...1296...>
> --
> v2: test %lu with "1" as windows and linux/i386 do not have 64 bit long
> v3: fix 2^33 in commit message, use "1L" for proper data type (Selva)
> ---
> tests/unit_tests/openvpn/test_argv.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/tests/unit_tests/openvpn/test_argv.c
> b/tests/unit_tests/openvpn/test_argv.c
> index 4a3ba559..0fdd3f0a 100644
> --- a/tests/unit_tests/openvpn/test_argv.c
> +++ b/tests/unit_tests/openvpn/test_argv.c
> @@ -116,8 +116,12 @@ argv_str__multiple_argv__correct_output(void **state)
> argv_printf(&a, "%s%sc", PATH1, PATH2);
> argv_printf_cat(&a, "%s", PARAM1);
> argv_printf_cat(&a, "%s", PARAM2);
> + argv_printf_cat(&a, "%d", -1);
> + argv_printf_cat(&a, "%u", -1);
> + argv_printf_cat(&a, "%lu", 1L );
> output = argv_str(&a, &gc, PA_BRACKET);
> - assert_string_equal(output, "[" PATH1 PATH2 "] [" PARAM1 "] [" PARAM2
> "]");
> + assert_string_equal(output, "[" PATH1 PATH2 "] [" PARAM1 "] [" PARAM2
> "]"
> + " [-1] [4294967295] [1]");
>
> argv_reset(&a);
> gc_free(&gc);
>
Looks good now. An unconditional ACK this time.
Selva
[-- Attachment #2: Type: text/html, Size: 2291 bytes --]
^ permalink raw reply [flat|nested] 18+ messages in thread
* [Openvpn-devel] [PATCH applied] Re: Add %d, %u and %lu tests to test_argv unit tests.
2018-06-23 19:15 ` [Openvpn-devel] [PATCH v3] " Gert Doering
2018-06-23 19:21 ` Selva Nair
@ 2018-06-23 19:33 ` Gert Doering
1 sibling, 0 replies; 18+ messages in thread
From: Gert Doering @ 2018-06-23 19:33 UTC (permalink / raw)
To: Gert Doering <gert@; +Cc: openvpn-devel
Patch has been applied to the master and release/2.4 branch.
commit 4376805d8fd2a5d4a3a7c5e4f60948a3ef76ff3b (master)
commit 6b27704dafcb60e995601178bbcfac751207e93e (release/2.4)
Author: Gert Doering
Date: Sat Jun 23 21:15:38 2018 +0200
Add %d, %u and %lu tests to test_argv unit tests.
Signed-off-by: Gert Doering <gert@...1296...>
Acked-by: Selva Nair <selva.nair@...277...>
Message-Id: <20180623191538.29317-1-gert@...1296...>
URL: https://www.mail-archive.com/search?l=mid&q=20180623191538.29317-1-gert@...1296...
Signed-off-by: Gert Doering <gert@...1296...>
--
kind regards,
Gert Doering
^ permalink raw reply [flat|nested] 18+ messages in thread
end of thread, other threads:[~2018-06-23 19:33 UTC | newest]
Thread overview: 18+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-06-22 10:21 [Openvpn-devel] [PATCH] route: fix format string passed to argv_printf Antonio Quartulli
2018-06-22 14:45 ` Selva Nair
2018-06-22 14:48 ` Antonio Quartulli
2018-06-22 15:34 ` Gert Doering
2018-06-22 15:37 ` Selva Nair
2018-06-22 15:39 ` Antonio Quartulli
2018-06-23 2:11 ` [Openvpn-devel] [PATCH v2] add support for %lu in argv_printf and prevent ASSERT Antonio Quartulli
2018-06-23 12:09 ` [Openvpn-devel] [PATCH applied] " Gert Doering
2018-06-23 12:15 ` [Openvpn-devel] [PATCH] Add %d, %u and %lu tests to test_argv unit tests Gert Doering
2018-06-23 17:31 ` Gert Doering
2018-06-23 18:08 ` Selva Nair
2018-06-23 18:12 ` Antonio Quartulli
2018-06-23 18:16 ` Gert Doering
2018-06-23 18:15 ` [Openvpn-devel] [PATCH v2] " Gert Doering
2018-06-23 19:11 ` Selva Nair
2018-06-23 19:15 ` [Openvpn-devel] [PATCH v3] " Gert Doering
2018-06-23 19:21 ` Selva Nair
2018-06-23 19:33 ` [Openvpn-devel] [PATCH applied] " Gert Doering
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.