Simplify source_dir_path substring extraction

Instead of checking if 'source_dir_path' is longer than 'build_dir'
before using the latter's length as an index into the first string,
switch to calling the subsrt() method of the former. This correctly
handles the case of both strings having the same length while being
clearer about its intended function.

Bug: 293
Fixes: fd6cae41bd7d ("Avoid out-of-bounds string indexing")
Change-Id: I46d29efb579b70eec47e32004347ebfccc56430e
Reviewed-on: https://gn-review.googlesource.com/c/gn/+/14120
Commit-Queue: Sylvain Defresne <sdefresne@chromium.org>
Reviewed-by: Sylvain Defresne <sdefresne@chromium.org>
diff --git a/src/gn/filesystem_utils.cc b/src/gn/filesystem_utils.cc
index 0f984a7..d0a1ee0 100644
--- a/src/gn/filesystem_utils.cc
+++ b/src/gn/filesystem_utils.cc
@@ -1036,10 +1036,8 @@
       // or `toolchain2/obj/BUILD_DIR/toolchain1/gen` which look surprising,
       // but guarantee unicity.
       result.value().append("BUILD_DIR/");
-      if (source_dir_path.size() > build_dir.size()) {
-        result.value().append(&source_dir_path[build_dir.size()],
-                              source_dir_path.size() - build_dir.size());
-      }
+      result.value().append(source_dir_path.substr(build_dir.size()));
+
     } else {
       // The source dir is source-absolute, so we trim off the two leading
       // slashes to append to the toolchain object directory.