KWSys 2021-10-27 (e19a5668)

Code extracted from:

    https://gitlab.kitware.com/utils/kwsys.git

at commit e19a5668f01bb9d96440ce96e777749d6e92562d (e19a5668f01bb9d96440ce96e777749d6e92562d).

Upstream Shortlog
-----------------

Mathieu Westphal (1):
      e28d7282 DynamicLoader: Add RTLD_GLOBAL as a supported flag on linux

Sean McBride (8):
      704a63d4 Replace sprintf with snprintf
      f9f6d67b Replace non-standard _snprintf with standard snprintf
      f771c009 Fix -Wunused-macros warning by defining under same conditions as usage
      f3d4b12b Fix Wmissing-prototypes warnings by making functions static
      6f4a1826 Fix Wmissing-variable-declarations by declaring variable in a header
      31d25023 Fix all Wold-style-cast warnings
      0f44b620 Fix Wreserved-id-macro warning by removing double underscore
      44718539 Fix for extraneous semi-colon warning
diff --git a/Configure.hxx.in b/Configure.hxx.in
index 29a2dd1..8d47340 100644
--- a/Configure.hxx.in
+++ b/Configure.hxx.in
@@ -16,11 +16,11 @@
   @KWSYS_SYSTEMTOOLS_USE_TRANSLATION_MAP@
 
 #if defined(__SUNPRO_CC) && __SUNPRO_CC > 0x5130 && defined(__has_attribute)
-#  define @KWSYS_NAMESPACE@__has_cpp_attribute(x) __has_attribute(x)
+#  define @KWSYS_NAMESPACE@_has_cpp_attribute(x) __has_attribute(x)
 #elif defined(__has_cpp_attribute)
-#  define @KWSYS_NAMESPACE@__has_cpp_attribute(x) __has_cpp_attribute(x)
+#  define @KWSYS_NAMESPACE@_has_cpp_attribute(x) __has_cpp_attribute(x)
 #else
-#  define @KWSYS_NAMESPACE@__has_cpp_attribute(x) 0
+#  define @KWSYS_NAMESPACE@_has_cpp_attribute(x) 0
 #endif
 
 #if __cplusplus >= 201103L
@@ -31,13 +31,13 @@
 
 #ifndef @KWSYS_NAMESPACE@_FALLTHROUGH
 #  if __cplusplus >= 201703L &&                                               \
-    @KWSYS_NAMESPACE@__has_cpp_attribute(fallthrough)
+    @KWSYS_NAMESPACE@_has_cpp_attribute(fallthrough)
 #    define @KWSYS_NAMESPACE@_FALLTHROUGH [[fallthrough]]
 #  elif __cplusplus >= 201103L &&                                             \
-    @KWSYS_NAMESPACE@__has_cpp_attribute(gnu::fallthrough)
+    @KWSYS_NAMESPACE@_has_cpp_attribute(gnu::fallthrough)
 #    define @KWSYS_NAMESPACE@_FALLTHROUGH [[gnu::fallthrough]]
 #  elif __cplusplus >= 201103L &&                                             \
-    @KWSYS_NAMESPACE@__has_cpp_attribute(clang::fallthrough)
+    @KWSYS_NAMESPACE@_has_cpp_attribute(clang::fallthrough)
 #    define @KWSYS_NAMESPACE@_FALLTHROUGH [[clang::fallthrough]]
 #  endif
 #endif
@@ -45,7 +45,7 @@
 #  define @KWSYS_NAMESPACE@_FALLTHROUGH static_cast<void>(0)
 #endif
 
-#undef @KWSYS_NAMESPACE@__has_cpp_attribute
+#undef @KWSYS_NAMESPACE@_has_cpp_attribute
 
 /* If building a C++ file in kwsys itself, give the source file
    access to the macros without a configured namespace.  */
diff --git a/Directory.cxx b/Directory.cxx
index 2e8aa83..6e31cbf 100644
--- a/Directory.cxx
+++ b/Directory.cxx
@@ -99,18 +99,21 @@
   this->Clear();
   intptr_t srchHandle;
   char* buf;
+  size_t bufLength;
   size_t n = name.size();
   if (name.back() == '/' || name.back() == '\\') {
-    buf = new char[n + 1 + 1];
-    sprintf(buf, "%s*", name.c_str());
+    bufLength = n + 1 + 1;
+    buf = new char[bufLength];
+    snprintf(buf, bufLength, "%s*", name.c_str());
   } else {
     // Make sure the slashes in the wildcard suffix are consistent with the
     // rest of the path
-    buf = new char[n + 2 + 1];
+    bufLength = n + 2 + 1;
+    buf = new char[bufLength];
     if (name.find('\\') != std::string::npos) {
-      sprintf(buf, "%s\\*", name.c_str());
+      snprintf(buf, bufLength, "%s\\*", name.c_str());
     } else {
-      sprintf(buf, "%s/*", name.c_str());
+      snprintf(buf, bufLength, "%s/*", name.c_str());
     }
   }
   struct _wfinddata_t data; // data of current file
@@ -148,13 +151,16 @@
 {
   intptr_t srchHandle;
   char* buf;
+  size_t bufLength;
   size_t n = name.size();
   if (name.back() == '/') {
+    bufLength = n + 1 + 1;
     buf = new char[n + 1 + 1];
-    sprintf(buf, "%s*", name.c_str());
+    snprintf(buf, bufLength, "%s*", name.c_str());
   } else {
+    bufLength = n + 2 + 1;
     buf = new char[n + 2 + 1];
-    sprintf(buf, "%s/*", name.c_str());
+    snprintf(buf, bufLength, "%s/*", name.c_str());
   }
   struct _wfinddata_t data; // data of current file
 
diff --git a/DynamicLoader.cxx b/DynamicLoader.cxx
index 66ee9ea..8afc2e8 100644
--- a/DynamicLoader.cxx
+++ b/DynamicLoader.cxx
@@ -275,20 +275,20 @@
 
   if (length < 1) {
     /* FormatMessage failed.  Use a default message.  */
-    _snprintf(str, DYNLOAD_ERROR_BUFFER_SIZE,
-              "DynamicLoader encountered error 0x%X.  "
-              "FormatMessage failed with error 0x%X",
-              error, GetLastError());
+    snprintf(str, DYNLOAD_ERROR_BUFFER_SIZE,
+             "DynamicLoader encountered error 0x%lX.  "
+             "FormatMessage failed with error 0x%lX",
+             error, GetLastError());
     return str;
   }
 
   if (!WideCharToMultiByte(CP_UTF8, 0, lpMsgBuf, -1, str,
                            DYNLOAD_ERROR_BUFFER_SIZE, nullptr, nullptr)) {
     /* WideCharToMultiByte failed.  Use a default message.  */
-    _snprintf(str, DYNLOAD_ERROR_BUFFER_SIZE,
-              "DynamicLoader encountered error 0x%X.  "
-              "WideCharToMultiByte failed with error 0x%X",
-              error, GetLastError());
+    snprintf(str, DYNLOAD_ERROR_BUFFER_SIZE,
+             "DynamicLoader encountered error 0x%lX.  "
+             "WideCharToMultiByte failed with error 0x%lX",
+             error, GetLastError());
   }
 
   return str;
@@ -436,9 +436,14 @@
 DynamicLoader::LibraryHandle DynamicLoader::OpenLibrary(
   const std::string& libname, int flags)
 {
-  CHECK_OPEN_FLAGS(flags, 0, nullptr);
+  CHECK_OPEN_FLAGS(flags, RTLDGlobal, nullptr);
 
-  return dlopen(libname.c_str(), RTLD_LAZY);
+  int llFlags = RTLD_LAZY;
+  if (flags & RTLDGlobal) {
+    llFlags |= RTLD_GLOBAL;
+  }
+
+  return dlopen(libname.c_str(), llFlags);
 }
 
 int DynamicLoader::CloseLibrary(DynamicLoader::LibraryHandle lib)
diff --git a/DynamicLoader.hxx.in b/DynamicLoader.hxx.in
index 539c742..4edd31c 100644
--- a/DynamicLoader.hxx.in
+++ b/DynamicLoader.hxx.in
@@ -73,7 +73,12 @@
     // This is currently only supported on Windows.
     SearchBesideLibrary = 0x00000001,
 
-    AllOpenFlags = SearchBesideLibrary
+    // Make loaded symbols visible globally
+    //
+    // This is currently only supported on *nix systems.
+    RTLDGlobal = 0x00000002,
+
+    AllOpenFlags = SearchBesideLibrary | RTLDGlobal
   };
 
   /** Load a dynamic library into the current process.
diff --git a/ProcessUNIX.c b/ProcessUNIX.c
index a8a15dd..1963b27 100644
--- a/ProcessUNIX.c
+++ b/ProcessUNIX.c
@@ -2287,7 +2287,8 @@
 #endif
     default:
       cp->ProcessResults[idx].ExitException = kwsysProcess_Exception_Other;
-      sprintf(cp->ProcessResults[idx].ExitExceptionString, "Signal %d", sig);
+      snprintf(cp->ProcessResults[idx].ExitExceptionString,
+               KWSYSPE_PIPE_BUFFER_SIZE + 1, "Signal %d", sig);
       break;
   }
 }
@@ -2540,7 +2541,7 @@
       int pid;
       if (sscanf(d->d_name, "%d", &pid) == 1 && pid != 0) {
         struct stat finfo;
-        sprintf(fname, "/proc/%d/stat", pid);
+        snprintf(fname, sizeof(fname), "/proc/%d/stat", pid);
         if (stat(fname, &finfo) == 0) {
           FILE* f = fopen(fname, "r");
           if (f) {
diff --git a/ProcessWin32.c b/ProcessWin32.c
index 8f01684..e97973e 100644
--- a/ProcessWin32.c
+++ b/ProcessWin32.c
@@ -29,7 +29,7 @@
 #  define KWSYS_WINDOWS_DEPRECATED_GetVersionEx
 #endif
 #include <io.h>     /* _unlink */
-#include <stdio.h>  /* sprintf */
+#include <stdio.h>  /* snprintf */
 #include <string.h> /* strlen, strdup */
 
 #ifndef _MAX_FNAME
@@ -1867,18 +1867,18 @@
         KWSYSPE_PIPE_BUFFER_SIZE, 0);
       if (length < 1) {
         /* FormatMessage failed.  Use a default message.  */
-        _snprintf(cp->ErrorMessage, KWSYSPE_PIPE_BUFFER_SIZE,
-                  "Process execution failed with error 0x%X.  "
-                  "FormatMessage failed with error 0x%X",
-                  error, GetLastError());
+        snprintf(cp->ErrorMessage, KWSYSPE_PIPE_BUFFER_SIZE,
+                 "Process execution failed with error 0x%lX.  "
+                 "FormatMessage failed with error 0x%lX",
+                 error, GetLastError());
       }
       if (!WideCharToMultiByte(CP_UTF8, 0, err_msg, -1, cp->ErrorMessage,
                                KWSYSPE_PIPE_BUFFER_SIZE, NULL, NULL)) {
         /* WideCharToMultiByte failed.  Use a default message.  */
-        _snprintf(cp->ErrorMessage, KWSYSPE_PIPE_BUFFER_SIZE,
-                  "Process execution failed with error 0x%X.  "
-                  "WideCharToMultiByte failed with error 0x%X",
-                  error, GetLastError());
+        snprintf(cp->ErrorMessage, KWSYSPE_PIPE_BUFFER_SIZE,
+                 "Process execution failed with error 0x%lX.  "
+                 "WideCharToMultiByte failed with error 0x%lX",
+                 error, GetLastError());
       }
     }
 
@@ -2144,8 +2144,8 @@
     case STATUS_NO_MEMORY:
     default:
       cp->ProcessResults[idx].ExitException = kwsysProcess_Exception_Other;
-      _snprintf(cp->ProcessResults[idx].ExitExceptionString,
-                KWSYSPE_PIPE_BUFFER_SIZE, "Exit code 0x%x\n", code);
+      snprintf(cp->ProcessResults[idx].ExitExceptionString,
+               KWSYSPE_PIPE_BUFFER_SIZE, "Exit code 0x%x\n", code);
       break;
   }
 }
diff --git a/SharedForward.h.in b/SharedForward.h.in
index 091334b..d6ae75c 100644
--- a/SharedForward.h.in
+++ b/SharedForward.h.in
@@ -457,9 +457,9 @@
                    message, KWSYS_SHARED_FORWARD_MAXPATH, 0);
   if (length < 1 || length > KWSYS_SHARED_FORWARD_MAXPATH) {
     /* FormatMessage failed.  Use a default message.  */
-    _snprintf(message, KWSYS_SHARED_FORWARD_MAXPATH,
-              "Error 0x%X (FormatMessage failed with error 0x%X)", original,
-              GetLastError());
+    snprintf(message, KWSYS_SHARED_FORWARD_MAXPATH,
+             "Error 0x%lX (FormatMessage failed with error 0x%lX)", original,
+             GetLastError());
   }
 #  else
   /* Implementation for UNIX.  */
diff --git a/Status.cxx b/Status.cxx
index 503d1e1..edda7a0 100644
--- a/Status.cxx
+++ b/Status.cxx
@@ -53,7 +53,7 @@
       LocalFree(message);
     } break;
 #endif
-  };
+  }
   return err;
 }
 
diff --git a/SystemInformation.cxx b/SystemInformation.cxx
index f2bf85f..ecb9bf3 100644
--- a/SystemInformation.cxx
+++ b/SystemInformation.cxx
@@ -1267,7 +1267,9 @@
 private:
   void* GetRealAddress() const
   {
-    return (void*)((char*)this->Address - (char*)this->BinaryBaseAddress);
+    return reinterpret_cast<void*>(
+      static_cast<char*>(this->Address) -
+      static_cast<char*>(this->BinaryBaseAddress));
   }
 
   std::string GetFileName(const std::string& path) const;
@@ -2789,19 +2791,20 @@
   //    ;        ecx: middle 32 bits are the processor signature bits
   //    ;        edx: bottom 32 bits are the processor signature bits
   char sn[128];
-  sprintf(sn, "%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x",
-          ((SerialNumber[1] & 0xff000000) >> 24),
-          ((SerialNumber[1] & 0x00ff0000) >> 16),
-          ((SerialNumber[1] & 0x0000ff00) >> 8),
-          ((SerialNumber[1] & 0x000000ff) >> 0),
-          ((SerialNumber[2] & 0xff000000) >> 24),
-          ((SerialNumber[2] & 0x00ff0000) >> 16),
-          ((SerialNumber[2] & 0x0000ff00) >> 8),
-          ((SerialNumber[2] & 0x000000ff) >> 0),
-          ((SerialNumber[3] & 0xff000000) >> 24),
-          ((SerialNumber[3] & 0x00ff0000) >> 16),
-          ((SerialNumber[3] & 0x0000ff00) >> 8),
-          ((SerialNumber[3] & 0x000000ff) >> 0));
+  snprintf(sn, sizeof(sn),
+           "%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x-%.2x%.2x",
+           ((SerialNumber[1] & 0xff000000) >> 24),
+           ((SerialNumber[1] & 0x00ff0000) >> 16),
+           ((SerialNumber[1] & 0x0000ff00) >> 8),
+           ((SerialNumber[1] & 0x000000ff) >> 0),
+           ((SerialNumber[2] & 0xff000000) >> 24),
+           ((SerialNumber[2] & 0x00ff0000) >> 16),
+           ((SerialNumber[2] & 0x0000ff00) >> 8),
+           ((SerialNumber[2] & 0x000000ff) >> 0),
+           ((SerialNumber[3] & 0xff000000) >> 24),
+           ((SerialNumber[3] & 0x00ff0000) >> 16),
+           ((SerialNumber[3] & 0x0000ff00) >> 8),
+           ((SerialNumber[3] & 0x000000ff) >> 0));
   this->ChipID.SerialNumber = sn;
   return true;
 
@@ -3749,24 +3752,24 @@
   ResourceLimitType rlim;
   ierr = GetResourceLimit(RLIMIT_DATA, &rlim);
   if ((ierr == 0) && (rlim.rlim_cur != RLIM_INFINITY)) {
-    memAvail = min((long long)rlim.rlim_cur / 1024, memAvail);
+    memAvail = min(static_cast<long long>(rlim.rlim_cur) / 1024, memAvail);
   }
 
   ierr = GetResourceLimit(RLIMIT_AS, &rlim);
   if ((ierr == 0) && (rlim.rlim_cur != RLIM_INFINITY)) {
-    memAvail = min((long long)rlim.rlim_cur / 1024, memAvail);
+    memAvail = min(static_cast<long long>(rlim.rlim_cur) / 1024, memAvail);
   }
 #elif defined(__APPLE__)
   struct rlimit rlim;
   int ierr;
   ierr = getrlimit(RLIMIT_DATA, &rlim);
   if ((ierr == 0) && (rlim.rlim_cur != RLIM_INFINITY)) {
-    memAvail = min((long long)rlim.rlim_cur / 1024, memAvail);
+    memAvail = min(static_cast<long long>(rlim.rlim_cur) / 1024, memAvail);
   }
 
   ierr = getrlimit(RLIMIT_RSS, &rlim);
   if ((ierr == 0) && (rlim.rlim_cur != RLIM_INFINITY)) {
-    memAvail = min((long long)rlim.rlim_cur / 1024, memAvail);
+    memAvail = min(static_cast<long long>(rlim.rlim_cur) / 1024, memAvail);
   }
 #endif
 
@@ -4068,7 +4071,7 @@
 
     // install ours
     struct sigaction sa;
-    sa.sa_sigaction = (SigAction)StacktraceSignalHandler;
+    sa.sa_sigaction = static_cast<SigAction>(StacktraceSignalHandler);
     sa.sa_flags = SA_SIGINFO | SA_RESETHAND;
 #  ifdef SA_RESTART
     sa.sa_flags |= SA_RESTART;
@@ -4564,7 +4567,8 @@
   this->AvailablePhysicalMemory = 0;
   vm_statistics_data_t vmstat;
   mach_msg_type_number_t count = HOST_VM_INFO_COUNT;
-  if (host_statistics(mach_host_self(), HOST_VM_INFO, (host_info_t)&vmstat,
+  if (host_statistics(mach_host_self(), HOST_VM_INFO,
+                      reinterpret_cast<host_info_t>(&vmstat),
                       &count) == KERN_SUCCESS) {
     err = kw_sysctlbyname_int64("hw.pagesize", &tempInt64);
     if (err == 0) {
@@ -5395,8 +5399,8 @@
           }
         }
 
-        sprintf(operatingSystem, "%ls (Build %ld)", osvi.szCSDVersion,
-                osvi.dwBuildNumber & 0xFFFF);
+        snprintf(operatingSystem, sizeof(operatingSystem), "%ls (Build %ld)",
+                 osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF);
         this->OSVersion = operatingSystem;
       } else
 #  endif // VER_NT_WORKSTATION
@@ -5439,9 +5443,10 @@
       // Display version, service pack (if any), and build number.
       if (osvi.dwMajorVersion <= 4) {
         // NB: NT 4.0 and earlier.
-        sprintf(operatingSystem, "version %ld.%ld %ls (Build %ld)",
-                osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.szCSDVersion,
-                osvi.dwBuildNumber & 0xFFFF);
+        snprintf(operatingSystem, sizeof(operatingSystem),
+                 "version %ld.%ld %ls (Build %ld)", osvi.dwMajorVersion,
+                 osvi.dwMinorVersion, osvi.szCSDVersion,
+                 osvi.dwBuildNumber & 0xFFFF);
         this->OSVersion = operatingSystem;
       } else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1) {
         // Windows XP and .NET server.
@@ -5467,8 +5472,8 @@
         }
       } else {
         // Windows 2000 and everything else.
-        sprintf(operatingSystem, "%ls (Build %ld)", osvi.szCSDVersion,
-                osvi.dwBuildNumber & 0xFFFF);
+        snprintf(operatingSystem, sizeof(operatingSystem), "%ls (Build %ld)",
+                 osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF);
         this->OSVersion = operatingSystem;
       }
       break;
diff --git a/SystemTools.cxx b/SystemTools.cxx
index bd900fe..ac45b14 100644
--- a/SystemTools.cxx
+++ b/SystemTools.cxx
@@ -4552,10 +4552,10 @@
         }
 
         res += " ";
-        sprintf(buffer, "%ld", osvi.dwMajorVersion);
+        snprintf(buffer, sizeof(buffer), "%ld", osvi.dwMajorVersion);
         res += buffer;
         res += ".";
-        sprintf(buffer, "%ld", osvi.dwMinorVersion);
+        snprintf(buffer, sizeof(buffer), "%ld", osvi.dwMinorVersion);
         res += buffer;
       }
 
@@ -4575,7 +4575,7 @@
 
         if (lRet == ERROR_SUCCESS) {
           res += " Service Pack 6a (Build ";
-          sprintf(buffer, "%ld", osvi.dwBuildNumber & 0xFFFF);
+          snprintf(buffer, sizeof(buffer), "%ld", osvi.dwBuildNumber & 0xFFFF);
           res += buffer;
           res += ")";
         } else // Windows NT 4.0 prior to SP6a
@@ -4583,7 +4583,7 @@
           res += " ";
           res += osvi.szCSDVersion;
           res += " (Build ";
-          sprintf(buffer, "%ld", osvi.dwBuildNumber & 0xFFFF);
+          snprintf(buffer, sizeof(buffer), "%ld", osvi.dwBuildNumber & 0xFFFF);
           res += buffer;
           res += ")";
         }
@@ -4594,7 +4594,7 @@
         res += " ";
         res += osvi.szCSDVersion;
         res += " (Build ";
-        sprintf(buffer, "%ld", osvi.dwBuildNumber & 0xFFFF);
+        snprintf(buffer, sizeof(buffer), "%ld", osvi.dwBuildNumber & 0xFFFF);
         res += buffer;
         res += ")";
       }
diff --git a/testDirectory.cxx b/testDirectory.cxx
index a847462..79bdc98 100644
--- a/testDirectory.cxx
+++ b/testDirectory.cxx
@@ -19,7 +19,7 @@
 
 #include <testSystemTools.h>
 
-int _doLongPathTest()
+static int _doLongPathTest()
 {
   using namespace kwsys;
   static const int LONG_PATH_THRESHOLD = 512;
@@ -77,7 +77,7 @@
   return res;
 }
 
-int _nonExistentDirectoryTest()
+static int _nonExistentDirectoryTest()
 {
   using namespace kwsys;
   int res = 0;
@@ -105,7 +105,7 @@
   return res;
 }
 
-int _copyDirectoryTest()
+static int _copyDirectoryTest()
 {
   using namespace kwsys;
   const std::string source(TEST_SYSTEMTOOLS_BINARY_DIR
diff --git a/testDynamicLoader.cxx b/testDynamicLoader.cxx
index 9ba204e..806c01a 100644
--- a/testDynamicLoader.cxx
+++ b/testDynamicLoader.cxx
@@ -11,20 +11,20 @@
 // Needed for __GLIBC__ test macro.
 #ifdef __linux__
 #  include <features.h>
-#endif
 
 // Will define LIBDL_SO macro on systems with glibc.
-#ifdef __GLIBC__
-#  include <gnu/lib-names.h>
+#  ifdef __GLIBC__
+#    include <gnu/lib-names.h>
 // Define to LIBC_SO, if not defined by above header.
-#  ifndef LIBDL_SO
-#    define LIBDL_SO LIBC_SO
+#    ifndef LIBDL_SO
+#      define LIBDL_SO LIBC_SO
+#    endif
 #  endif
-#endif
 
 // Define the LIBDL_SO macro, if not defined above.
-#ifndef LIBDL_SO
-#  define LIBDL_SO "libdl.so"
+#  ifndef LIBDL_SO
+#    define LIBDL_SO "libdl.so"
+#  endif
 #endif
 
 // Work-around CMake dependency scanning limitation.  This must
@@ -40,6 +40,10 @@
 // left on disk.
 #include <testSystemTools.h>
 
+// For TestDynamicLoaderData, which, though not referenced literally,
+// is referenced semantically.
+#include "testDynload.h"
+
 static std::string GetLibName(const char* lname, const char* subdir = nullptr)
 {
   // Construct proper name of lib
diff --git a/testDynload.c b/testDynload.c
index 33a431e..83056c0 100644
--- a/testDynload.c
+++ b/testDynload.c
@@ -6,6 +6,8 @@
 #  define DL_EXPORT
 #endif
 
+#include "testDynload.h"
+
 DL_EXPORT int TestDynamicLoaderData = 0;
 
 DL_EXPORT void TestDynamicLoaderSymbolPointer(void)
diff --git a/testDynload.h b/testDynload.h
new file mode 100644
index 0000000..dc0d7a1
--- /dev/null
+++ b/testDynload.h
@@ -0,0 +1,9 @@
+/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
+   file Copyright.txt or https://cmake.org/licensing#kwsys for details.  */
+#ifdef _WIN32
+#  define DL_EXPORT __declspec(dllexport)
+#else
+#  define DL_EXPORT
+#endif
+
+extern DL_EXPORT int TestDynamicLoaderData;
diff --git a/testEncoding.cxx b/testEncoding.cxx
index ee93e8d..1d605cb 100644
--- a/testEncoding.cxx
+++ b/testEncoding.cxx
@@ -80,7 +80,7 @@
   std::ios::fmtflags const& flags = std::cout.flags();
 
   int ret = 0;
-  char cstr[] = { (char)-1, 0 };
+  char cstr[] = { static_cast<char>(-1), 0 };
   // this conversion could fail
   std::wstring wstr = kwsys::Encoding::ToWide(cstr);
 
@@ -89,7 +89,7 @@
     const wchar_t* wcstr = wstr.c_str();
     std::cout << "ToWide(NULL) returned";
     for (size_t i = 0; i < wstr.size(); i++) {
-      std::cout << " " << std::hex << (int)wcstr[i];
+      std::cout << " " << std::hex << static_cast<int>(wcstr[i]);
     }
     std::cout << std::endl;
     ret++;
@@ -99,7 +99,7 @@
     const wchar_t* wcstr = wstr.c_str();
     std::cout << "ToWide(\"\") returned";
     for (size_t i = 0; i < wstr.size(); i++) {
-      std::cout << " " << std::hex << (int)wcstr[i];
+      std::cout << " " << std::hex << static_cast<int>(wcstr[i]);
     }
     std::cout << std::endl;
     ret++;
@@ -160,7 +160,9 @@
 {
   int status = 0;
 
-  char const* argv[2] = { "./app.exe", (char const*)helloWorldStrings[1] };
+  char const* argv[2] = {
+    "./app.exe", reinterpret_cast<char const*>(helloWorldStrings[1])
+  };
 
   kwsys::Encoding::CommandLineArguments args(2, argv);
   kwsys::Encoding::CommandLineArguments arg2 =