diff options
author | Scott Graham <scottmg@chromium.org> | 2014-11-11 03:38:08 (GMT) |
---|---|---|
committer | Scott Graham <scottmg@chromium.org> | 2014-11-11 03:38:08 (GMT) |
commit | 0c2982d13ea290a451efa8e8ddbaa9af1e7229a1 (patch) | |
tree | d69e9ba2d4eef691fc5d0beff13e92988c04bc2d /src | |
parent | 99a72092646537992d57196e5286cc556b1437e5 (diff) | |
download | Ninja-0c2982d13ea290a451efa8e8ddbaa9af1e7229a1.zip Ninja-0c2982d13ea290a451efa8e8ddbaa9af1e7229a1.tar.gz Ninja-0c2982d13ea290a451efa8e8ddbaa9af1e7229a1.tar.bz2 |
fix not respecting length
Diffstat (limited to 'src')
-rw-r--r-- | src/util.cc | 32 |
1 files changed, 18 insertions, 14 deletions
diff --git a/src/util.cc b/src/util.cc index f89c7ad..e667992 100644 --- a/src/util.cc +++ b/src/util.cc @@ -98,7 +98,7 @@ bool CanonicalizePath(string* path, unsigned int* slash_bits, string* err) { } #ifdef _WIN32 -unsigned int ShiftOverBit(int offset, unsigned int bits) { +static unsigned int ShiftOverBit(int offset, unsigned int bits) { // e.g. for |offset| == 2: // | ... 9 8 7 6 5 4 3 2 1 0 | // \_________________/ \_/ @@ -124,25 +124,29 @@ bool CanonicalizePath(char* path, size_t* len, unsigned int* slash_bits, char* components[kMaxPathComponents]; int component_count = 0; + char* start = path; + char* dst = start; + const char* src = start; + const char* end = start + *len; + #ifdef _WIN32 // kMaxPathComponents protects this from overflowing. unsigned int bits = 0; - int bits_offset = 0; - for (char* c = path; (c = strpbrk(c, "/\\")) != NULL;) { - if (static_cast<size_t>(c - path) >= *len) - break; - bits |= (*c == '\\') << bits_offset; - *c++ = '/'; - bits_offset++; + unsigned int bits_mask = 1; + // Convert \ to /, setting a bit in |bits| for each \ encountered. + for (char* c = path; c < end; ++c) { + switch (*c) { + case '\\': + bits |= bits_mask; + *c = '/'; + // Intentional fallthrough. + case '/': + bits_mask <<= 1; + } } - bits_offset = 0; + int bits_offset = 0; #endif - char* start = path; - char* dst = start; - const char* src = start; - const char* end = start + *len; - if (*src == '/') { #ifdef _WIN32 bits_offset++; |