From 1b313e2514694dfab8ecc51549e21a68ea5b95d8 Mon Sep 17 00:00:00 2001
From: William F Godoy <williamfgc@yahoo.com>
Date: Mon, 24 Jul 2017 08:27:51 -0400
Subject: [PATCH] Additional changes

Restoring std:: for cstdio functions
Removing warnings explicitly with pragmas
---
 source/adios2/helper/adiosSystem.cpp          |  7 ++----
 source/adios2/mpidummy.cpp                    | 21 ++++++++---------
 .../adios2/toolkit/capsule/heap/STLVector.cpp |  8 +++----
 .../toolkit/transport/file/FilePointer.cpp    | 23 ++++++++-----------
 4 files changed, 26 insertions(+), 33 deletions(-)

diff --git a/source/adios2/helper/adiosSystem.cpp b/source/adios2/helper/adiosSystem.cpp
index 9dcbd42f3..233f2d096 100644
--- a/source/adios2/helper/adiosSystem.cpp
+++ b/source/adios2/helper/adiosSystem.cpp
@@ -20,11 +20,8 @@
 #include "adios2/helper/adiosString.h"
 
 // remove ctime warning on Windows
-#ifdef _MSC_VER
-#define _CRT_SECURE_NO_WARNINGS
-#define _CRT_SECURE_NO_DEPRECATE
-#define _SCL_SECURE_NO_WARNINGS
-#define _SCL_SECURE_NO_DEPRECATE
+#ifdef _WIN32
+#pragma warning(disable : 4996)
 #endif
 
 namespace adios2
diff --git a/source/adios2/mpidummy.cpp b/source/adios2/mpidummy.cpp
index 763d9a6f3..b47c68a34 100644
--- a/source/adios2/mpidummy.cpp
+++ b/source/adios2/mpidummy.cpp
@@ -33,11 +33,10 @@
 #include <chrono>
 #include <string>
 
-#ifdef _MSC_VER
-#define _CRT_SECURE_NO_WARNINGS
-#define _CRT_SECURE_NO_DEPRECATE
-#define _SCL_SECURE_NO_WARNINGS
-#define _SCL_SECURE_NO_DEPRECATE
+// remove warnings on Windows
+#ifdef _WIN32
+#pragma warning(disable : 4996) // fopen
+#pragma warning(disable : 4477) // strcpy, sprintf
 #endif
 
 namespace adios2
@@ -302,7 +301,7 @@ int MPI_File_open(MPI_Comm /*comm*/, const char *filename, int amode,
     }
     mode += "b";
 
-    *fh = fopen(filename, mode.c_str());
+    *fh = std::fopen(filename, mode.c_str());
     if (!*fh)
     {
         std::snprintf(mpierrmsg, MPI_MAX_ERROR_STRING, "File not found: %s",
@@ -316,10 +315,10 @@ int MPI_File_close(MPI_File *fh) { return fclose(*fh); }
 
 int MPI_File_get_size(MPI_File fh, MPI_Offset *size)
 {
-    long curpos = ftell(fh);
+    long curpos = std::ftell(fh);
     fseek(fh, 0, SEEK_END); // go to end, returned is the size in bytes
-    long endpos = ftell(fh);
-    fseek(fh, curpos, SEEK_SET); // go back where we were
+    long endpos = std::ftell(fh);
+    std::fseek(fh, curpos, SEEK_SET); // go back where we were
     *size = static_cast<MPI_Offset>(endpos);
     // printf("MPI_File_get_size: fh=%d, size=%lld\n", fh, *size);
     return MPI_SUCCESS;
@@ -331,7 +330,7 @@ int MPI_File_read(MPI_File fh, void *buf, int count, MPI_Datatype datatype,
     // FIXME: int count can read only 2GB (*datatype size) array at max
     size_t bytes_to_read = static_cast<size_t>(count) * datatype;
     size_t bytes_read;
-    bytes_read = fread(buf, 1, bytes_to_read, fh);
+    bytes_read = std::fread(buf, 1, bytes_to_read, fh);
     if (bytes_read != bytes_to_read)
     {
         std::snprintf(mpierrmsg, MPI_MAX_ERROR_STRING,
@@ -348,7 +347,7 @@ int MPI_File_read(MPI_File fh, void *buf, int count, MPI_Datatype datatype,
 
 int MPI_File_seek(MPI_File fh, MPI_Offset offset, int whence)
 {
-    return fseek(fh, offset, whence) == MPI_SUCCESS;
+    return std::fseek(fh, offset, whence) == MPI_SUCCESS;
 }
 
 int MPI_Get_count(const MPI_Status *status, MPI_Datatype, int *count)
diff --git a/source/adios2/toolkit/capsule/heap/STLVector.cpp b/source/adios2/toolkit/capsule/heap/STLVector.cpp
index 9ff852d3f..5221f00fa 100644
--- a/source/adios2/toolkit/capsule/heap/STLVector.cpp
+++ b/source/adios2/toolkit/capsule/heap/STLVector.cpp
@@ -41,10 +41,10 @@ void STLVector::ResizeData(const size_t size)
         {
             m_Data.resize(size);
         }
-        catch (std::bad_alloc &e)
+        catch (...)
         {
             std::throw_with_nested(
-                std::runtime_error("ERROR: bad_alloc detected when resizing "
+                std::runtime_error("ERROR: possible overflow when resizing "
                                    "data buffer with size " +
                                    std::to_string(size) + "\n"));
         }
@@ -63,10 +63,10 @@ void STLVector::ResizeMetadata(const size_t size)
         {
             m_Metadata.resize(size);
         }
-        catch (std::bad_alloc &e)
+        catch (...)
         {
             std::throw_with_nested(
-                std::runtime_error("ERROR: bad_alloc detected when resizing "
+                std::runtime_error("ERROR: possible overflow when resizing "
                                    "metadata buffer with size " +
                                    std::to_string(size) + "\n"));
         }
diff --git a/source/adios2/toolkit/transport/file/FilePointer.cpp b/source/adios2/toolkit/transport/file/FilePointer.cpp
index 468b726e1..e11c4f9fb 100644
--- a/source/adios2/toolkit/transport/file/FilePointer.cpp
+++ b/source/adios2/toolkit/transport/file/FilePointer.cpp
@@ -15,11 +15,8 @@
 /// \endcond
 
 // removes fopen warning on Windows
-#ifdef _MSC_VER
-#define _CRT_SECURE_NO_WARNINGS
-#define _CRT_SECURE_NO_DEPRECATE
-#define _SCL_SECURE_NO_WARNINGS
-#define _SCL_SECURE_NO_DEPRECATE
+#ifdef _WIN32
+#pragma warning(disable : 4996) // fopen
 #endif
 
 namespace adios2
@@ -36,7 +33,7 @@ FilePointer::~FilePointer()
 {
     if (m_IsOpen)
     {
-        fclose(m_File);
+        std::fclose(m_File);
     }
 }
 
@@ -56,16 +53,16 @@ void FilePointer::Open(const std::string &name, const OpenMode openMode)
 
     if (m_OpenMode == OpenMode::Write)
     {
-        m_File = fopen(name.c_str(), "wb");
+        m_File = std::fopen(name.c_str(), "wb");
     }
     else if (m_OpenMode == OpenMode::Append)
     {
         // need to change when implemented
-        m_File = fopen(name.c_str(), "ab");
+        m_File = std::fopen(name.c_str(), "ab");
     }
     else if (m_OpenMode == OpenMode::Read)
     {
-        m_File = fopen(name.c_str(), "rb");
+        m_File = std::fopen(name.c_str(), "rb");
     }
 
     if (ferror(m_File))
@@ -80,7 +77,7 @@ void FilePointer::Open(const std::string &name, const OpenMode openMode)
 
 void FilePointer::SetBuffer(char *buffer, size_t size)
 {
-    const int status = setvbuf(m_File, buffer, _IOFBF, size);
+    const int status = std::setvbuf(m_File, buffer, _IOFBF, size);
 
     if (!status)
     {
@@ -98,7 +95,7 @@ void FilePointer::Write(const char *buffer, size_t size)
         {
             m_Profiler.Timers.at("write").Resume();
         }
-        auto writtenSize = fwrite(buffer, sizeof(char), size, m_File);
+        auto writtenSize = std::fwrite(buffer, sizeof(char), size, m_File);
 
         if (m_Profiler.IsActive)
         {
@@ -141,7 +138,7 @@ void FilePointer::Write(const char *buffer, size_t size)
 
 void FilePointer::Flush()
 {
-    const int status = fflush(m_File);
+    const int status = std::fflush(m_File);
 
     if (status == EOF)
     {
@@ -157,7 +154,7 @@ void FilePointer::Close()
         m_Profiler.Timers.at("close").Resume();
     }
 
-    const int status = fclose(m_File);
+    const int status = std::fclose(m_File);
 
     if (m_Profiler.IsActive)
     {
-- 
GitLab