From: Joel Rosdahl Date: Tue, 4 Aug 2020 14:32:14 +0000 (+0200) Subject: Retrieve non-const pointer to std::string data without casting X-Git-Tag: v4.0~222 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=296559cbc4efe4f7251bc36ddc7471c8e79fca6c;p=thirdparty%2Fccache.git Retrieve non-const pointer to std::string data without casting --- diff --git a/src/TemporaryFile.cpp b/src/TemporaryFile.cpp index 803ad9e8b..88814fa99 100644 --- a/src/TemporaryFile.cpp +++ b/src/TemporaryFile.cpp @@ -84,6 +84,6 @@ TemporaryFile::initialize(string_view path_prefix) { path = std::string(path_prefix); path += ".XXXXXX"; - fd = Fd(mkstemp(const_cast(path.data()))); // cast needed before C++17 + fd = Fd(mkstemp(&path[0])); return bool(fd); } diff --git a/src/Util.cpp b/src/Util.cpp index eafab5eab..03c38508b 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -1031,8 +1031,7 @@ read_file(const std::string& path, size_t size_hint) result.resize(2 * result.size()); } const size_t max_read = result.size() - pos; - char* data = const_cast(result.data()); // cast needed before C++17 - ret = read(*fd, data + pos, max_read); + ret = read(*fd, &result[pos], max_read); if (ret == 0 || (ret == -1 && errno != EINTR)) { break; } diff --git a/src/ccache.cpp b/src/ccache.cpp index 7dad6bade..f501d8c0e 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -413,9 +413,9 @@ process_preprocessed_file(Context& ctx, } // Bytes between p and q are pending to be hashed. - const char* p = data.data(); - char* q = const_cast(data.data()); // cast needed before C++17 - const char* end = data.c_str() + data.length(); + const char* p = &data[0]; + char* q = &data[0]; + const char* end = p + data.length(); // There must be at least 7 characters (# 1 "x") left to potentially find an // include file path.