Commit 992a4931 authored by Sean McBride's avatar Sean McBride

Use real snprintf (not _snprintf) with >= VS2015

Infuriatingly, Visual Studio has not supported C99’s snprintf until VS2015.

Modify a couple of workaround hacks to only apply to pre-VS2015.

This is more than just a cleanup.  snprintf guarantees null
termination, _snprintf does not!  The return values are also different,
though rarely used.
parent 01a0d34d
Pipeline #5257 passed with stage
......@@ -39,13 +39,6 @@
#include <limits>
#include <cmath>
// pull in snprintf on MSVC:
#if defined(_WIN32) && !defined(__CYGWIN__)
# define SNPRINTF _snprintf
#else
# define SNPRINTF snprintf
#endif
//-----------------------------------------------------------------------------
vtkStandardNewMacro(vtkAxis);
......@@ -1497,19 +1490,16 @@ vtkStdString vtkAxis::GenerateSprintfLabel(double value, const std::string & for
// digits on Windows for consistent behavior.
#if defined(_MSC_VER) && _MSC_VER < 1900
unsigned int oldWin32ExponentFormat = _set_output_format(_TWO_DIGIT_EXPONENT);
#endif
int len = SNPRINTF(buffer, buffSize, format.c_str(), value);
if (len < 0) // Overrun on windows
{
len = buffSize;
}
_snprintf(buffer, buffSize-1, format.c_str(), value);
buffer[buffSize-1] = '\0';
#if defined(_MSC_VER) && _MSC_VER < 1900
_set_output_format(oldWin32ExponentFormat);
#else
snprintf(buffer, buffSize, format.c_str(), value);
#endif
vtkStdString result = vtkStdString(buffer, std::min(len, buffSize));
vtkStdString result = vtkStdString(buffer);
return result;
}
......
......@@ -69,7 +69,7 @@
# include <malloc.h>
#endif /* EXODUSII_HAVE_MALLOC_H */
#if defined(_WIN32) && !defined(__CYGWIN__)
#if defined(_MSC_VER) && (_MSC_VER < 1900)
# define SNPRINTF _snprintf
#else
# define SNPRINTF snprintf
......
......@@ -25,7 +25,7 @@
#include <sstream>
#if _MSC_VER
#if defined(_MSC_VER) && (_MSC_VER < 1900)
#define snprintf _snprintf
#endif
......
......@@ -62,12 +62,6 @@
#include <libxml/tree.h> // always after std::blah stuff
#if defined(_WIN32) && !defined(__CYGWIN__)
# define SNPRINTF _snprintf
#else
# define SNPRINTF snprintf
#endif
using namespace xdmf2;
struct _xmlNode;
......
......@@ -45,7 +45,7 @@
#include <stdio.h> // for snprintf
#if defined(_WIN32) && !defined(__CYGWIN__)
#if defined(_MSC_VER) && (_MSC_VER < 1900)
# define SNPRINTF _snprintf
#else
# define SNPRINTF snprintf
......
......@@ -40,7 +40,7 @@ PURPOSE. See the above copyright notice for more information.
#include "vtkTrivialProducer.h"
#include "vtkViewport.h"
#if defined(_WIN32) && !defined(__CYGWIN__)
#if defined(_MSC_VER) && (_MSC_VER < 1900)
# define SNPRINTF _snprintf
#else
# define SNPRINTF snprintf
......
......@@ -49,7 +49,7 @@
#include <fstream>
using std::ofstream;
#if defined(_WIN32) && !defined(__CYGWIN__)
#if defined(_MSC_VER) && (_MSC_VER < 1900)
# define SNPRINTF _snprintf
#else
# define SNPRINTF snprintf
......
......@@ -46,7 +46,7 @@ vtkStandardNewMacro(vtkLabeledDataMapper);
vtkCxxSetObjectMacro(vtkLabeledDataMapper,Transform,vtkTransform);
#if defined(_WIN32) && !defined(__CYGWIN__)
#if defined(_MSC_VER) && (_MSC_VER < 1900)
# define SNPRINTF _snprintf
#else
# define SNPRINTF snprintf
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment