diff options
author | Jisi Liu <liujisi@google.com> | 2017-12-12 17:16:51 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-12 17:16:51 -0800 |
commit | 0f9bfa8244fcb68f503c7c373651d4eb1180026f (patch) | |
tree | f0c63184ba790a34a3e7dd2ff09be9e2ff2bbc37 /src | |
parent | 27e877fdaa5f051031d8d7e6500244855b0c608f (diff) | |
parent | f5b086273aa2f5832f72e6b2aa755c0930dfaffa (diff) | |
download | protobuf-0f9bfa8244fcb68f503c7c373651d4eb1180026f.tar.gz protobuf-0f9bfa8244fcb68f503c7c373651d4eb1180026f.tar.bz2 protobuf-0f9bfa8244fcb68f503c7c373651d4eb1180026f.zip |
Merge pull request #4016 from jquesnelle/string-access-ub
fix undefined behavior in C++03
Diffstat (limited to 'src')
-rw-r--r-- | src/google/protobuf/stubs/io_win32.cc | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/src/google/protobuf/stubs/io_win32.cc b/src/google/protobuf/stubs/io_win32.cc index fa2cb8b1..2b8a8a22 100644 --- a/src/google/protobuf/stubs/io_win32.cc +++ b/src/google/protobuf/stubs/io_win32.cc @@ -155,12 +155,13 @@ string normalize(string path) { static const string dot("."); static const string dotdot(".."); + const char *p = path.c_str(); std::vector<string> segments; int segment_start = -1; // Find the path segments in `path` (separated by "/"). for (int i = 0;; ++i) { - if (!is_separator(path[i]) && path[i] != '\0') { + if (!is_separator(p[i]) && p[i] != '\0') { // The current character does not end a segment, so start one unless it's // already started. if (segment_start < 0) { @@ -169,7 +170,7 @@ string normalize(string path) { } else if (segment_start >= 0 && i > segment_start) { // The current character is "/" or "\0", so this ends a segment. // Add that to `segments` if there's anything to add; handle "." and "..". - string segment(path, segment_start, i - segment_start); + string segment(p, segment_start, i - segment_start); segment_start = -1; if (segment == dotdot) { if (!segments.empty() && @@ -180,7 +181,7 @@ string normalize(string path) { segments.push_back(segment); } } - if (path[i] == '\0') { + if (p[i] == '\0') { break; } } @@ -203,7 +204,7 @@ string normalize(string path) { result << segments[i]; } // Preserve trailing separator if the input contained it. - if (!path.empty() && is_separator(path[path.size() - 1])) { + if (!path.empty() && is_separator(p[path.size() - 1])) { result << '\\'; } return result.str(); |