diff DEPENDENCIES/generic/include/boost/log/detail/snprintf.hpp @ 101:c530137014c0

Update Boost headers (1.58.0)
author Chris Cannam
date Mon, 07 Sep 2015 11:12:49 +0100
parents 2665513ce2d3
children
line wrap: on
line diff
--- a/DEPENDENCIES/generic/include/boost/log/detail/snprintf.hpp	Fri Sep 04 12:01:02 2015 +0100
+++ b/DEPENDENCIES/generic/include/boost/log/detail/snprintf.hpp	Mon Sep 07 11:12:49 2015 +0100
@@ -1,5 +1,5 @@
 /*
- *          Copyright Andrey Semashev 2007 - 2013.
+ *          Copyright Andrey Semashev 2007 - 2015.
  * Distributed under the Boost Software License, Version 1.0.
  *    (See accompanying file LICENSE_1_0.txt or copy at
  *          http://www.boost.org/LICENSE_1_0.txt)
@@ -48,47 +48,36 @@
 
 #else // !defined(_MSC_VER)
 
-#   if _MSC_VER >= 1400
-
-// MSVC 2005 and later provide the safe-CRT implementation of the conforming snprintf
+// MSVC snprintfs are not conforming but they are good enough for our cases
 inline int vsnprintf(char* buf, std::size_t size, const char* format, std::va_list args)
 {
-    return ::vsprintf_s(buf, size, format, args);
-}
-
-#       ifdef BOOST_LOG_USE_WCHAR_T
-inline int vswprintf(wchar_t* buf, std::size_t size, const wchar_t* format, std::va_list args)
-{
-    return ::vswprintf_s(buf, size, format, args);
-}
-#       endif // BOOST_LOG_USE_WCHAR_T
-
-#   else // _MSC_VER >= 1400
-
-// MSVC prior to 2005 had a non-conforming extension _vsnprintf, that sometimes did not put a terminating '\0'
-inline int vsnprintf(char* buf, std::size_t size, const char* format, std::va_list args)
-{
-    register int n = _vsnprintf(buf, size - 1, format, args);
-    buf[size - 1] = '\0';
+    int n = _vsnprintf(buf, size, format, args);
+    if (static_cast< unsigned int >(n) >= size)
+    {
+        n = static_cast< int >(size);
+        buf[size - 1] = '\0';
+    }
     return n;
 }
 
-#       ifdef BOOST_LOG_USE_WCHAR_T
+#   ifdef BOOST_LOG_USE_WCHAR_T
 inline int vswprintf(wchar_t* buf, std::size_t size, const wchar_t* format, std::va_list args)
 {
-    register int n = _vsnwprintf(buf, size - 1, format, args);
-    buf[size - 1] = L'\0';
+    int n = _vsnwprintf(buf, size, format, args);
+    if (static_cast< unsigned int >(n) >= size)
+    {
+        n = static_cast< int >(size);
+        buf[size - 1] = L'\0';
+    }
     return n;
 }
-#       endif // BOOST_LOG_USE_WCHAR_T
-
-#   endif // _MSC_VER >= 1400
+#   endif // BOOST_LOG_USE_WCHAR_T
 
 inline int snprintf(char* buf, std::size_t size, const char* format, ...)
 {
     std::va_list args;
     va_start(args, format);
-    register int n = vsnprintf(buf, size, format, args);
+    int n = vsnprintf(buf, size, format, args);
     va_end(args);
     return n;
 }
@@ -98,7 +87,7 @@
 {
     std::va_list args;
     va_start(args, format);
-    register int n = vswprintf(buf, size, format, args);
+    int n = vswprintf(buf, size, format, args);
     va_end(args);
     return n;
 }