summaryrefslogtreecommitdiffstats
path: root/Source/Checks/cm_cxx_features.cmake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2022-10-20 21:59:03 (GMT)
committerBrad King <brad.king@kitware.com>2022-10-20 22:31:50 (GMT)
commitee9805ccd17670e945e41e62f160bfdd9ad8a386 (patch)
tree402a9d03107dee1098eb96d58357bbaeff63aec9 /Source/Checks/cm_cxx_features.cmake
parent96172ba2d18b98b2a5b651dee5326d7298c5891c (diff)
downloadCMake-ee9805ccd17670e945e41e62f160bfdd9ad8a386.zip
CMake-ee9805ccd17670e945e41e62f160bfdd9ad8a386.tar.gz
CMake-ee9805ccd17670e945e41e62f160bfdd9ad8a386.tar.bz2
cm/filesystem: Fix crash with pre-C++11 std::string GNU ABI in C++17
The `remove_filename` and `replace_extension` methods compute an offset between the whole path in a `std::string` and a part of a path in a `std::string_view`. This is done by subtracting their `.data()` pointers. However, C++17 adds a non-const `.data()` through which modification of the string is allowed. This means the copy-on-write implementation used by the pre-C++11 std::string GNU ABI must reallocate if the string has been copied. Our subtraction then computes an offset between two different allocations, which is undefined behavior. The workaround in commit b3ca4f9ad1 (cm/filesystem: Work around crash when compiled for CYGWIN/MSYS runtime, 2021-04-22, v3.21.0-rc1~271^2~2) avoided the problem by calling the non-const `.data()` to reallocate before constructing the `string_view`. Instead, explicitly call the const `.data()` method on the string, which does not reallocate. Fixes: #22090, #23328
Diffstat (limited to 'Source/Checks/cm_cxx_features.cmake')
-rw-r--r--Source/Checks/cm_cxx_features.cmake4
1 files changed, 1 insertions, 3 deletions
diff --git a/Source/Checks/cm_cxx_features.cmake b/Source/Checks/cm_cxx_features.cmake
index f20572e..7917d41 100644
--- a/Source/Checks/cm_cxx_features.cmake
+++ b/Source/Checks/cm_cxx_features.cmake
@@ -80,9 +80,7 @@ if(CMake_HAVE_CXX_MAKE_UNIQUE)
set(CMake_HAVE_CXX_UNIQUE_PTR 1)
endif()
cm_check_cxx_feature(unique_ptr)
-if (NOT CMAKE_CXX_STANDARD LESS "17"
- AND NOT MSYS # FIXME: RunCMake.cmake_path cases crash with MSYS std::filesystem
- )
+if (NOT CMAKE_CXX_STANDARD LESS "17")
if (NOT CMAKE_CROSSCOMPILING OR CMAKE_CROSSCOMPILING_EMULATOR)
cm_check_cxx_feature(filesystem TRY_RUN)
else()