kicad-developers team mailing list archive
-
kicad-developers team
-
Mailing list archive
-
Message #11373
Re: Various HAVE_ISO_* in CMakeModules/config.h.cmake
On 3 October 2013 23:41, Cirilo Bernardo <cirilo_bernardo@xxxxxxxxx> wrote:
> >________________________________
> > From: Brian Sidebotham <brian.sidebotham@xxxxxxxxx>
> >To: KiCad Developers <kicad-developers@xxxxxxxxxxxxxxxxxxx>
> >Sent: Friday, October 4, 2013 8:19 AM
> >Subject: [Kicad-developers] Various HAVE_ISO_* in
> CMakeModules/config.h.cmake
> >
> >
> >
> >Hi Guys,
> >
> >
> >This plays breaks compilation with mingw-w64, can I remove them? I don't
> think they should affect anyone anymore because they are a MicroSoft Visual
> C cludge as far as I can tell. Mingw-w64's problem is that is defines both
> snprintf and _snprintf symbols.
> >
> >
> > #cmakedefine HAVE_ISO_SNPRINTF
> >
> >
> > #if defined( HAVE_ISO_SNPRINTF )
> > #define snprintf _snprintf
> > #endif
> >
> >
> >I guess MSVC only defined _snprintf and not snprintf?
> >
> >
> >Anyhoo, if we don't want to get rid of them, I'll need to add a check so
> that the define is not used on mingw-w64
> >
> >
> >Best Regards,
> >
> >
> >Brian.
>
>
> A few thoughts on the matter:
>
> (1) MSVC 2010 and earlier only define _snprintf; I can't speak for any
> later versions.
>
> (2) "#define snprintf _snprintf" is what MinGW used to do when I last used
> MinGW 7+ years ago. This is *incorrect* behavior; MicroSoft's _snprintf
> implementation is baaaad; one behavior that's guaranteed to bite you in the
> ass is that if the source string is longer than the destination, the
> destination is filled with the source characters until the end of the
> destination - there is no terminal \0 (yay buffer overflow!) If I recall
> correctly there are other nuisances with the return value of _snprintf.
> The best workaround is to define a snprintf() function which wraps
> _snprintf_s() to provide the specified behavior of snprintf(). MS have
> marked _snprintf as deprecated, so just don't use it. MS have been
> promising since at least 2008 to make it simply disappear.
>
> (3) Given the comments in (2), if MinGW still uses "#define snprintf
> _snprintf" and you want to support MinGW compilation, you will need to
> disable the MinGW definition somehow.
>
> - Cirilo
>
Cheers Cirilo - I noted that their _snprintf was indeed flawed and hardly
safe!
Mingw-w64 doesn't do "#define snprintf _snprintf" exactly, they actually
have two slightly differing definitions.
Best Regards, Brian.
References