[Lldb-commits] [lldb] f72ae5c - [lldb] Fix windows path guessing for root paths

Jaroslav Sevcik via lldb-commits lldb-commits at lists.llvm.org
Tue Dec 7 02:23:30 PST 2021


Author: Jaroslav Sevcik
Date: 2021-12-07T11:16:04+01:00
New Revision: f72ae5cba1d625301aa8a668a3d54ec3ac5b7806

URL: https://github.com/llvm/llvm-project/commit/f72ae5cba1d625301aa8a668a3d54ec3ac5b7806
DIFF: https://github.com/llvm/llvm-project/commit/f72ae5cba1d625301aa8a668a3d54ec3ac5b7806.diff

LOG: [lldb] Fix windows path guessing for root paths

Fix recognizing "<letter>:\" as a windows path.

Differential Revision: https://reviews.llvm.org/D115104

Added: 
    

Modified: 
    lldb/source/Utility/FileSpec.cpp
    lldb/unittests/Utility/FileSpecTest.cpp

Removed: 
    


################################################################################
diff  --git a/lldb/source/Utility/FileSpec.cpp b/lldb/source/Utility/FileSpec.cpp
index 601edb86c1b0c..24f8c2b1c23fc 100644
--- a/lldb/source/Utility/FileSpec.cpp
+++ b/lldb/source/Utility/FileSpec.cpp
@@ -310,7 +310,7 @@ llvm::Optional<FileSpec::Style> FileSpec::GuessPathStyle(llvm::StringRef absolut
     return Style::posix;
   if (absolute_path.startswith(R"(\\)"))
     return Style::windows;
-  if (absolute_path.size() > 3 && llvm::isAlpha(absolute_path[0]) &&
+  if (absolute_path.size() >= 3 && llvm::isAlpha(absolute_path[0]) &&
       absolute_path.substr(1, 2) == R"(:\)")
     return Style::windows;
   return llvm::None;

diff  --git a/lldb/unittests/Utility/FileSpecTest.cpp b/lldb/unittests/Utility/FileSpecTest.cpp
index 3dd355284ce0f..64b72bec483e5 100644
--- a/lldb/unittests/Utility/FileSpecTest.cpp
+++ b/lldb/unittests/Utility/FileSpecTest.cpp
@@ -198,8 +198,10 @@ TEST(FileSpecTest, GuessPathStyle) {
             FileSpec::GuessPathStyle(R"(C:\foo.txt)"));
   EXPECT_EQ(FileSpec::Style::windows,
             FileSpec::GuessPathStyle(R"(\\net\foo.txt)"));
+  EXPECT_EQ(FileSpec::Style::windows, FileSpec::GuessPathStyle(R"(Z:\)"));
   EXPECT_EQ(llvm::None, FileSpec::GuessPathStyle("foo.txt"));
   EXPECT_EQ(llvm::None, FileSpec::GuessPathStyle("foo/bar.txt"));
+  EXPECT_EQ(llvm::None, FileSpec::GuessPathStyle("Z:"));
 }
 
 TEST(FileSpecTest, GetPath) {


        


More information about the lldb-commits mailing list