$OpenBSD: patch-Source_cmArchiveWrite_cxx,v 1.4 2020/01/11 08:01:09 rsadowski Exp $

Get rid of cmLocaleRAII.

It is of dubious utility:

it's trying to save the LC_CTYPE locale and set it from the environment
variables before processing each single file name, and to restore
the LC_CTYPE locale to the previous value after processing each
file name. There is no way how the environment could possibly change
between files, and setlocale(3) is a potentially expensive operation.

The way how it tries to save the previous locale is broken:

it calls setlocale(LC_CTYPE, NULL), which returns a pointer. CMake
saves that pointer, without strdup(3)ing it, then calls setlocale(3)
again as setlocale(LC_CTYPE, "") to actually set the desired locale,
discarding the return value. It later uses the saved pointer to try
and restore the original locale.
In an implementation using a static buffer, the second call will
overwrite the contents of the pointer returned by the first call,
so the third call will not restore the previous locale, but instead
set the one intended as temporary a second time.
A stricter implementation (one that doesn't just overwrite the
string, but actually frees the memory, so the string returned by
the earlier setlocale() call becomes invalid) will crash, revealing
the invalid use of the interface.

Index: Source/cmArchiveWrite.cxx
--- Source/cmArchiveWrite.cxx.orig
+++ Source/cmArchiveWrite.cxx
@@ -236,9 +236,6 @@ bool cmArchiveWrite::AddFile(const char* file, size_t 
   }
   const char* out = file + skip;
 
-  cmLocaleRAII localeRAII;
-  static_cast<void>(localeRAII);
-
   // Meta-data.
   std::string dest = cmStrCat(prefix ? prefix : "", out);
   if (this->Verbose) {
