Fix format errors when cross-compiling for Windows
PATCH 1/1 Fix format errors when cross-compiling for Windows
Not all supported windows formatting libs are C99 compliant and some do not grasp %ll (similar to %zu). Use int64_t and PRIi64 to work around that.
--- src/openvpn/error.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
src/openvpn/error.c +2 -2
@@ -342,8 +342,8 @@ x_msg_va(const unsigned int flags, const char *format, va_list arglist)struct timeval tv;gettimeofday (&tv,NULL ); - fprintf(fp, "%lld.%06lu %x %s%s%s%s", - (long long)tv.tv_sec, + fprintf(fp, "%"PRIi64".%06lu %x %s%s%s%s", + (int64_t)tv.tv_sec, (unsigned long)tv.tv_usec, flags, prefix,
Signature · 1 line
2.7.4
Hi,
Quoted 14 lines · Steffan Karger
Not all supported windows formatting libs are C99 compliant and some do not grasp %ll (similar to %zu). Use
int64_tand PRIi64 to work around that.Signed-off-by Steffan Karger <[email protected]...>--- src/openvpn/error.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)src/openvpn/error.c +0
-0@@ -342,8 +342,8 @@ x_msg_va(const unsigned int flags, const char *format, va_list arglist)struct timeval tv;
src/openvpn/error.c x_msg_va(const unsigned int flags, const char *format, va_list arglist)
Quoted 10 lines
src/openvpn/error.c +2
-3gettimeofday (&tv,NULL ); - fprintf(fp, "%lld.%06lu %x %s%s%s%s", - (long long)tv.tv_sec, + fprintf(fp, "%"PRIi64".%06lu %x %s%s%s%s", + (int64_t)tv.tv_sec, (unsigned long)tv.tv_usec, flags, prefix, --
This is good but there are a number of such instances (otime.c, packet_id.c, forward.c etc. within code path relevant to Windows). Many related to time_t like here, one or two other uses of %lld. And may be more if some DEBUG flags are enabled.
If those are left for future patches, that's ok. Just saying in case its an oversight..
Selva
Hi,
Quoted 32 lines · Selva Nair
Quoted 14 lines · Steffan Karger
Not all supported windows formatting libs are C99 compliant and some do not grasp %ll (similar to %zu). Use
int64_tand PRIi64 to work around that.Signed-off-by Steffan Karger <[email protected]...>--- src/openvpn/error.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)src/openvpn/error.c +0
-0@@ -342,8 +342,8 @@ x_msg_va(const unsigned int flags, const char *format, va_list arglist)struct timeval tv;src/openvpn/error.c x_msg_va(const unsigned int flags, const char *format, va_list arglist)
Quoted 10 lines
src/openvpn/error.c +2
-3gettimeofday (&tv,NULL ); - fprintf(fp, "%lld.%06lu %x %s%s%s%s", - (long long)tv.tv_sec, + fprintf(fp, "%"PRIi64".%06lu %x %s%s%s%s", + (int64_t)tv.tv_sec, (unsigned long)tv.tv_usec, flags, prefix, --This is good but there are a number of such instances (
otime.c,packet_id.c,forward.cetc. within code path relevant to Windows). Many related totime_tlike here, one or two other uses of %lld. And may be more if some DEBUG flags are enabled.
Quoted 2 lines
If those are left for future patches, that's ok. Just saying in case its an oversight..
Good point - I did the lazy thing and just fixed what my compiler was complaining about. (My OpenVPN-NL buildbots build with "-Werror=implicit -Werror=format -Werror=format-security".)
For now, let's leave the rest - that doesn't break my build ;-) - for a future patch. I'll put it on my todo list, but will also happily review patches from someone else if (s)he beats me to it.
-Steffan
Hi,
Quoted 35 lines · Steffan Karger
Hi,
Quoted 32 lines · Selva Nair
Quoted 14 lines · Steffan Karger
Not all supported windows formatting libs are C99 compliant and some do not grasp %ll (similar to %zu). Use
int64_tand PRIi64 to work around that.Signed-off-by Steffan Karger <[email protected]...>--- src/openvpn/error.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)src/openvpn/error.c +0
-0@@ -342,8 +342,8 @@ x_msg_va(const unsigned int flags, const char *format, va_list arglist)struct timeval tv;src/openvpn/error.c x_msg_va(const unsigned int flags, const char *format, va_list arglist)
Quoted 10 lines
src/openvpn/error.c +2
-3gettimeofday (&tv,NULL ); - fprintf(fp, "%lld.%06lu %x %s%s%s%s", - (long long)tv.tv_sec, + fprintf(fp, "%"PRIi64".%06lu %x %s%s%s%s", + (int64_t)tv.tv_sec, (unsigned long)tv.tv_usec, flags, prefix, --This is good but there are a number of such instances (
otime.c,packet_id.c,forward.cetc. within code path relevant to Windows). Many related totime_tlike here, one or two other uses of %lld. And may be more if some DEBUG flags are enabled.
Quoted 6 lines
Quoted 2 lines
If those are left for future patches, that's ok. Just saying in case its an oversight..
Good point - I did the lazy thing and just fixed what my compiler was complaining about. (My OpenVPN-NL buildbots build with "-Werror=implicit -Werror=format -Werror=format-security".)
Makes sense.. But I'm surprised why it doesn't catch all errors.
Quoted 4 lines
For now, let's leave the rest - that doesn't break my build ;-) - for a future patch. I'll put it on my todo list, but will also happily review patches from someone else if (s)he beats me to it.
I am sending in a patch that covers all format errors that I see in current windows cross builds.
Selva
Selva Nair
Acked-byHi,
Quoted 39 lines · Selva Nair
Hi,
Quoted 35 lines · Steffan Karger
Hi,
Quoted 32 lines · Selva Nair
Quoted 14 lines · Steffan Karger
Not all supported windows formatting libs are C99 compliant and some do not grasp %ll (similar to %zu). Use
int64_tand PRIi64 to work around that.Signed-off-by Steffan Karger <[email protected]...>--- src/openvpn/error.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)src/openvpn/error.c +0
-0@@ -342,8 +342,8 @@ x_msg_va(const unsigned int flags, const char *format, va_list arglist)struct timeval tv;src/openvpn/error.c x_msg_va(const unsigned int flags, const char *format, va_list arglist)
Quoted 10 lines
src/openvpn/error.c +2
-3gettimeofday (&tv,NULL ); - fprintf(fp, "%lld.%06lu %x %s%s%s%s", - (long long)tv.tv_sec, + fprintf(fp, "%"PRIi64".%06lu %x %s%s%s%s", + (int64_t)tv.tv_sec, (unsigned long)tv.tv_usec, flags, prefix, --This is good but there are a number of such instances (
otime.c,packet_id.c,forward.cetc. within code path relevant to Windows). Many related totime_tlike here, one or two other uses of %lld. And may be more if some DEBUG flags are enabled.
Quoted 11 lines
Quoted 6 lines
Quoted 2 lines
If those are left for future patches, that's ok. Just saying in case its an oversight..
Good point - I did the lazy thing and just fixed what my compiler was complaining about. (My OpenVPN-NL buildbots build with "-Werror=implicit -Werror=format -Werror=format-security".)
Makes sense.. But I'm surprised why it doesn't catch all errors.
Quoted 2 lines
For now, let's leave the rest - that doesn't break my build ;-)
Anyway, assuming that (i) my longer patch will take more time to get reviewed/tested and (ii) this is priority if a release is imminent, ACK from me.
(Only compile tested)
Selva
Your patch has been applied to the release/2.4 branch.
Note: the code in master looks subtly different here - also using %lld for tv.tv_sec, but using %ld / (long) for tv.tv_usec so the patch does not directly apply. Since Selva is working on fixing all these for good, I've decided to take the easy way and only apply this patch to 2.4 - which it very much looks like it's intended for :-)
commit 9ba36639abcac4367c8227d2dd87b18fb56267c4 (release/2.4)
Author: Steffan Karger Date: Fri Feb 16 14:45:39 2018 +0100
Fix format errors when cross-compiling for Windows
Signed-off-by: Steffan Karger <[email protected]...>
Acked-by: Selva Nair <[email protected]...>
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg16478.html
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering