Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This patch fixes a few annoying bugs in the implementation of
CanonicalizePath():
It canonicalized "/" and "/foo/.." incorrectly to "",
while the correct value should be "/". And this was
enforced by unit-tests :-(
This was the root cause for issue ninja thinks the root directory doesn't exist #2008.
In certain cases, it would copy the first byte after the
path buffer into the destination (assuming in the comment
that this is a terminating zero), though there is no guarantee
that this is the case, or that this address is accessible.
This is important because the function is being called in
build.cc:xxx and :xxx with arguments coming from StringPiece
values, which do not guarantee anything about the bytes/memory
that follow the content they point to. It just happens to work
due to the way the parser are currently implemented, but could
break easily in the future if they are modified (e.g.
to read directly from read-only memory-mapped files).
Performance comparisons with
canonical_perfcompare
shows thisimplementation to be slightly faster as well, though benchmarking
ninja with a large Fuchsia build plan doesn't show any difference
overall.
Minimal times reported by canon_perftest (best of 5 runs each):
Note that the loop had to be unrolled for
gcc -O3
due to somesurprising compiler optimization failure :-(