Skip to contentSkip to conversation

Changed snprintf to _snprintf in service-win32/openvpnserv.c

PATCH In review Samuli Seppänen 4 participants 5 messages Jan 5, 2011 – Jan 6, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Changed snprintf to _snprintf in service-win32/openvpnserv.c

This fixes a generic Windows/VC++ issue:

<http://thedailyreviewer.com/dotnet/view/strncasecmp-and-snprintf-functions-not-available-in-vc-109235975>

Does this change affect the automake/gcc-based Windows builds?

Signature · 5 lines
Samuli Seppänen
Community Manager
OpenVPN Technologies, Inc

irc freenode net: mattock

From 96880655ebfc1859d18431eeecc9103d29951935 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?Samuli=20Sepp=C3=A4nen?= <[email protected]...>
Date: Wed, 5 Jan 2011 15:14:21 +0200
Subject: [PATCH] Changed snprintf to _snprintf in service-win32/openvpnserv.c

This solves a fatal build error (LNK2019: unresolved external symbol _snprintf referenced...) when using the Python-based build system

---
 service-win32/openvpnserv.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
service-win32/openvpnserv.c +1 -1
index 07374e2..42be609 100755
@@ -86,7 +86,7 @@ static HANDLE exit_event = NULL;
 /* snprintf with guaranteed null termination */
 #define mysnprintf(out, ...) \
         { \
-           snprintf (out, sizeof(out), __VA_ARGS__); \
+           _snprintf (out, sizeof(out), __VA_ARGS__); \
            out [sizeof (out) - 1] = '\0'; \
         }
 
Signature · 1 line
1.6.3.3
#1 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Quoted 6 lines · Samuli Seppänen

This fixes a generic Windows/VC++ issue:

<http://thedailyreviewer.com/dotnet/view/strncasecmp-and-snprintf-functions-not-available-in-vc-109235975>

Does this change affect the automake/gcc-based Windows builds?

I'm leaning towards a NAK on this one, as it might influence non-Visual C builds. OpenVPN have openvpn_snprintf() which is a portable snprintf() function, and this one should be used instead. It's found in buffer.[ch].

kind regards,

David Sommerseth
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAk0kdjgACgkQDC186MBRfrq+/ACfZ0XlQpSSJpEatxvnoQY0MQU7 RA4AoI6ahmFBh1QugQt/EG7WrIQchNQu
=rRM9
-----END PGP SIGNATURE-----

#3 lore raw
In reply to Samuli Seppänen
Quoted 11 lines · Samuli Seppänen

+++ b/service-win32/openvpnserv.c

service-win32/openvpnserv.c +1 -1
@@ -86,7 +86,7 @@ static HANDLE exit_event = NULL;
 /* snprintf with guaranteed null termination */
 #define mysnprintf(out, ...) \
         { \
-           snprintf (out, sizeof(out), __VA_ARGS__); \
+           _snprintf (out, sizeof(out), __VA_ARGS__); \
            out [sizeof (out) - 1] = '\0'; \
         }
 

Does this change affect the automake/gcc-based Windows builds?

My MinGW compiles both snprintf() and _snprintf() fine.

//Peter

#2 lore raw
In reply to David Sommerseth

David Sommerseth ha scritto:

Quoted 15 lines · Samuli Seppänen
Quoted 3 lines

This fixes a generic Windows/VC++ issue:

<http://thedailyreviewer.com/dotnet/view/strncasecmp-and-snprintf-functions-not-available-in-vc-109235975>

Quoted 1 line

Does this change affect the automake/gcc-based Windows builds?

I'm leaning towards a NAK on this one, as it might influence non-Visual C builds. OpenVPN have openvpn_snprintf() which is a portable snprintf() function, and this one should be used instead. It's found in buffer.[ch].

Quoted 3 lines

kind regards,

David Sommerseth

Yep, this is not an optimal solution. Some clarifications based on IRC discussions.... openvpnserv.c uses it's own snprintf wrapper function (=mysnprintf) extensively. My modification changed snprintf into _snprintf inside this wrapper function. I assume mysnprintf is used instead of openvpn_snprintf (in buffer.c) to avoid dependency to openvpn at code level. If we want to use openvpn_snprintf instead of mysnprintf, I think we should change all references to mysnprintf into references to openvpn_snprintf. This would avoid "double-wrapping" snprintf.

For your convenience, here are mysnprintf (with my _snprintf modification) and openvpn_snprintf from buffer.c:

http://pastie.org/1431115

Signature · 7 lines
Samuli Seppänen
Community Manager
OpenVPN Technologies, Inc

irc freenode net: mattock

PS.. I sure learned how to write snprintf when writing this mail :D
#4 lore raw
In reply to Samuli Seppänen

Am 05.01.2011 14:21, schrieb Samuli Seppänen:

Quoted 5 lines

This fixes a generic Windows/VC++ issue:

<http://thedailyreviewer.com/dotnet/view/strncasecmp-and-snprintf-functions-not-available-in-vc-109235975>

Does this change affect the automake/gcc-based Windows builds?

NAK. Do not mess with the namespaces.

The whole mysnprintf macro looks suspicious and should be removed, as it only works on static buffers. If you ever use it on dynamic buffers (char *foo = malloc(4711); style), you're in for nasty surprises with truncated strings -- and surprise means "prone to give maintenance head aches".

If you must do it, use #ifdefs so it's only visible on Windows. The canonical solution is to use AC_REPLACE([somefunction]) in configure.{ac,in} and provide somefunction.c to contain a replacement based on such boilerplate code:

#ifdef HAVE_CONFIG_H
#include "config.h"

#ifndef HAVE_SOMEFUNCTION
returntype somefunction( ...prototype... )
{
/* implementation */
}
#endif
#endif

The implementation can then be something along the lines of arke_snprintf on
<http://social.msdn.microsoft.com/forums/en-US/vcgeneral/thread/2b339bdf-7ab1-4a08-bf7e-e9293801455b/>
but I'm not so sure about the license.

HTH