diff --git a/CMakeLists.txt b/CMakeLists.txt index 380b3ea..dcf3f56 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,7 +68,7 @@ target_link_libraries(khiopsdriver_file_gcs PRIVATE google-cloud-cpp::storage spdlog::spdlog) target_compile_options( khiopsdriver_file_gcs - PRIVATE $<$:-Wall;/wd4101;/wd4710;/wd4711> + PRIVATE $<$:-Wall;/wd4710;/wd4711;/wd4868> PRIVATE $<$:-Wall;-Wextra;-pedantic>) option(BUILD_TESTS "Build test programs" OFF) diff --git a/src/gcsplugin.cpp b/src/gcsplugin.cpp index 857f88d..f7a1cb1 100644 --- a/src/gcsplugin.cpp +++ b/src/gcsplugin.cpp @@ -269,7 +269,13 @@ std::string ToLower(const std::string &str) { std::string GetEnvironmentVariableOrDefault(const std::string &variable_name, const std::string &default_value) { +#ifdef _WIN32 + size_t len; + char value[2048]; + getenv_s(&len, value, 2048, "TEMP"); +#else char *value = getenv(variable_name.c_str()); +#endif if (value && std::strlen(value) > 0) { return value; diff --git a/test/drivertest.cpp b/test/drivertest.cpp index 044d13c..5e492e7 100644 --- a/test/drivertest.cpp +++ b/test/drivertest.cpp @@ -125,8 +125,11 @@ int launch_test(const char *inputFilename, int nBufferSize) { << boost::uuids::random_generator()() << "/output.txt"; std::stringstream localOutput; #ifdef _WIN32 - localOutput << std::getenv("TEMP") << "\\out-" - << boost::uuids::random_generator()() << ".txt"; + size_t len; + char tempValue[2048]; + getenv_s(&len, tempValue, 2048, "TEMP"); + localOutput << tempValue << "\\out-" << boost::uuids::random_generator()() + << ".txt"; #else localOutput << "/tmp/out-" << boost::uuids::random_generator()() << ".txt"; #endif @@ -333,9 +336,9 @@ int copyFileWithFseek(const char *file_name_input, const char *file_name_output, // Reads the file by steps of nBufferSize and writes to the output file at // each step char *buffer = new char[nBufferSize + 1](); - long long int sizeRead = nBufferSize; - long long int sizeWrite; - int cummulativeRead = 0; + long long sizeRead = nBufferSize; + long long sizeWrite; + long long cummulativeRead = 0; driver_fseek(fileinput, 0, SEEK_SET); while (sizeRead == nBufferSize && copy_status == kSuccess) { driver_fseek(fileinput, cummulativeRead, SEEK_SET); diff --git a/test/path_helper.cpp b/test/path_helper.cpp index 33d9eab..436a070 100644 --- a/test/path_helper.cpp +++ b/test/path_helper.cpp @@ -87,7 +87,7 @@ std::string getExecutableDir() { std::string dirname(std::string path) { char *pathBuffer = new char[path.length() + 1]; - strcpy(pathBuffer, path.c_str()); + strncpy(pathBuffer, path.c_str(), path.length() + 1); std::string pathDir = std::string(::dirname(pathBuffer)); delete[] pathBuffer; return pathDir;