]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg BaseLib: API PathRemoveLastItem not handle root paths properly
authorHao Wu <hao.a.wu@intel.com>
Thu, 17 Nov 2016 06:07:54 +0000 (14:07 +0800)
committerHao Wu <hao.a.wu@intel.com>
Mon, 21 Nov 2016 01:23:25 +0000 (09:23 +0800)
https://bugzilla.tianocore.org/show_bug.cgi?id=239

When the input path for API PathRemoveLastItem() is a root path like
'fs0:\', the API will return TRUE (indicating a directory or file was
removed from the path) and modifies the path to 'fs0:'. In fact, there's
no directory or file removed in the above case.

This commit adds additional check to resolve this issue and modifies the
API's description to make it more straightforward.

Cc: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Hao Wu <hao.a.wu@intel.com>
Reviewed-by: Ruiyu Ni <ruiyu.ni@intel.com>
MdePkg/Include/Library/BaseLib.h
MdePkg/Library/BaseLib/FilePaths.c

index 6268e6fe46c72b35fd0d63e80bc01accb52e8887..b69c7038e4c084e84620f70c14c717255cf298ce 100644 (file)
@@ -1747,8 +1747,7 @@ BcdToDecimal8 (
 //\r
 \r
 /**\r
-  Removes the last directory or file entry in a path by changing the last\r
-  L'\' to a CHAR_NULL.\r
+  Removes the last directory or file entry in a path.\r
 \r
   @param[in, out] Path    The pointer to the path to modify.\r
 \r
index 183b3234d3302e6daab2a52c3d8c3b5c38825926..29a84ea9025cc010986a8d1522eb00cc3c564709 100644 (file)
@@ -14,9 +14,8 @@
 #include  <Library/BaseLib.h>\r
 \r
 /**\r
-  Removes the last directory or file entry in a path by changing the last\r
-  L'\' to a CHAR_NULL. For a path which is like L"fs0:startup.nsh",\r
-  it's converted to L"fs0:".\r
+  Removes the last directory or file entry in a path. For a path which is\r
+  like L"fs0:startup.nsh", it's converted to L"fs0:".\r
 \r
   @param[in,out] Path     A pointer to the path to modify.\r
 \r
@@ -38,7 +37,9 @@ PathRemoveLastItem(
       ; Walker != NULL && *Walker != CHAR_NULL\r
       ; Walker++\r
      ){\r
-    if ((*Walker == L'\\' || *Walker == L':') && *(Walker + 1) != CHAR_NULL) {\r
+    if (*Walker == L'\\' && *(Walker + 1) != CHAR_NULL) {\r
+      LastSlash = Walker+1;\r
+    } else if (*Walker == L':' && *(Walker + 1) != L'\\' && *(Walker + 1) != CHAR_NULL) {\r
       LastSlash = Walker+1;\r
     }\r
   }\r