lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 2be5478 27/28: Preserve NUL characters in fs:


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 2be5478 27/28: Preserve NUL characters in fs::path::string()
Date: Wed, 12 May 2021 18:14:47 -0400 (EDT)

branch: master
commit 2be5478c88b07c3eb5d41c26660595dc3965e7a5
Author: Vadim Zeitlin <vadim@tt-solutions.com>
Commit: Gregory W. Chicares <gchicares@sbcglobal.net>

    Preserve NUL characters in fs::path::string()
    
    Even though NULs are forbidden in the file paths, std::filesystem::path
    doesn't discard them and returns them as part of std::[u8]strings that
    it returns, so do likewise rather than truncating the string at the
    first NUL appearing in it.
    
    Note that this doesn't affect test_path_validation() since the changes
    of the previous commit, but would have broken it for C++20 compilers
    with char8_t support without them (previously the test was broken only
    for the compilers without char8_t support).
---
 path.hpp | 6 +-----
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/path.hpp b/path.hpp
index 71f334d..38177f2 100644
--- a/path.hpp
+++ b/path.hpp
@@ -355,11 +355,7 @@ class path
         // of char pointers that can be used to iterate over any buffer and
         // that u8string contents can always be stored in string (unlike vice
         // versa).
-        //
-        // Also note that the input string can't contain embedded NULs here, as
-        // they're not allowed in file paths, hence there is no need to use
-        // size.
-        return reinterpret_cast<char const*>(s8.c_str());
+        return std::string{reinterpret_cast<char const*>(s8.c_str()), 
s8.size()};
         }
 #endif // defined __cpp_char8_t
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]