]> git.proxmox.com Git - ceph.git/blobdiff - ceph/src/boost/libs/nowide/test/test_env.cpp
update ceph source to reef 18.1.2
[ceph.git] / ceph / src / boost / libs / nowide / test / test_env.cpp
index 8b47b1f7e335df1d867ef74c0a3809f175daec29..f3fdb7497637c4cf48b4ac82113fcde55b7bb696 100644 (file)
@@ -7,37 +7,25 @@
 //
 
 #include <boost/nowide/cstdlib.hpp>
+#include "test.hpp"
 #include <cstring>
 
 #if defined(BOOST_NOWIDE_TEST_INCLUDE_WINDOWS) && defined(BOOST_WINDOWS)
 #include <windows.h>
 #endif
 
-#include "test.hpp"
-
-// "Safe" strcpy version with NULL termination to make MSVC runtime happy
-// which warns when using strncpy
-template<size_t size>
-void strcpy_safe(char (&dest)[size], const char* src)
-{
-    size_t len = std::strlen(src);
-    if(len >= size)
-        len = size - 1u;
-    std::memcpy(dest, src, len);
-    dest[len] = 0;
-}
-
+// coverity [root_function]
 void test_main(int, char**, char**)
 {
     std::string example = "\xd7\xa9-\xd0\xbc-\xce\xbd";
-    char penv[256] = {0};
-    strcpy_safe(penv, ("BOOST_TEST2=" + example + "x").c_str());
+    std::string envVar = "BOOST_TEST2=" + example + "x";
 
     TEST(boost::nowide::setenv("BOOST_TEST1", example.c_str(), 1) == 0);
     TEST(boost::nowide::getenv("BOOST_TEST1"));
     TEST(boost::nowide::getenv("BOOST_TEST1") == example);
     TEST(boost::nowide::setenv("BOOST_TEST1", "xx", 0) == 0);
     TEST(boost::nowide::getenv("BOOST_TEST1") == example);
+    char* penv = const_cast<char*>(envVar.c_str());
     TEST(boost::nowide::putenv(penv) == 0);
     TEST(boost::nowide::getenv("BOOST_TEST2"));
     TEST(boost::nowide::getenv("BOOST_TEST_INVALID") == 0);
@@ -45,11 +33,10 @@ void test_main(int, char**, char**)
 #ifdef BOOST_WINDOWS
     // Passing a variable without an equals sign (before \0) is an error
     // But GLIBC has an extension that unsets the env var instead
-    char penv2[256] = {0};
-    const char* sPenv2 = "BOOST_TEST1SOMEGARBAGE=";
-    strcpy_safe(penv2, sPenv2);
+    std::string envVar2 = "BOOST_TEST1SOMEGARBAGE=";
     // End the string before the equals sign -> Expect fail
-    penv2[strlen("BOOST_TEST1")] = '\0';
+    envVar2[strlen("BOOST_TEST1")] = '\0';
+    char* penv2 = const_cast<char*>(envVar2.c_str());
     TEST(boost::nowide::putenv(penv2) == -1);
     TEST(boost::nowide::getenv("BOOST_TEST1"));
     TEST(boost::nowide::getenv("BOOST_TEST1") == example);