From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C630681F45 for ; Wed, 16 Nov 2016 22:32:22 -0800 (PST) Received: from fmsmga004.fm.intel.com ([10.253.24.48]) by orsmga104.jf.intel.com with ESMTP; 16 Nov 2016 22:32:27 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.31,504,1473145200"; d="scan'208";a="192420600" Received: from shwdeopenpsi014.ccr.corp.intel.com ([10.239.9.34]) by fmsmga004.fm.intel.com with ESMTP; 16 Nov 2016 22:32:26 -0800 From: Hao Wu To: edk2-devel@lists.01.org Cc: Hao Wu , Ruiyu Ni , Liming Gao Date: Thu, 17 Nov 2016 14:32:23 +0800 Message-Id: <1479364343-21736-2-git-send-email-hao.a.wu@intel.com> X-Mailer: git-send-email 1.9.5.msysgit.0 In-Reply-To: <1479364343-21736-1-git-send-email-hao.a.wu@intel.com> References: <1479364343-21736-1-git-send-email-hao.a.wu@intel.com> Subject: [PATCH v2] MdePkg BaseLib: API PathRemoveLastItem not handle root paths properly X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Nov 2016 06:32:22 -0000 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 Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Hao Wu --- MdePkg/Include/Library/BaseLib.h | 3 +-- MdePkg/Library/BaseLib/FilePaths.c | 9 +++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/MdePkg/Include/Library/BaseLib.h b/MdePkg/Include/Library/BaseLib.h index 6268e6f..b69c703 100644 --- a/MdePkg/Include/Library/BaseLib.h +++ b/MdePkg/Include/Library/BaseLib.h @@ -1747,8 +1747,7 @@ BcdToDecimal8 ( // /** - Removes the last directory or file entry in a path by changing the last - L'\' to a CHAR_NULL. + Removes the last directory or file entry in a path. @param[in, out] Path The pointer to the path to modify. diff --git a/MdePkg/Library/BaseLib/FilePaths.c b/MdePkg/Library/BaseLib/FilePaths.c index 183b323..29a84ea 100644 --- a/MdePkg/Library/BaseLib/FilePaths.c +++ b/MdePkg/Library/BaseLib/FilePaths.c @@ -14,9 +14,8 @@ #include /** - Removes the last directory or file entry in a path by changing the last - L'\' to a CHAR_NULL. For a path which is like L"fs0:startup.nsh", - it's converted to L"fs0:". + Removes the last directory or file entry in a path. For a path which is + like L"fs0:startup.nsh", it's converted to L"fs0:". @param[in,out] Path A pointer to the path to modify. @@ -38,7 +37,9 @@ PathRemoveLastItem( ; Walker != NULL && *Walker != CHAR_NULL ; Walker++ ){ - if ((*Walker == L'\\' || *Walker == L':') && *(Walker + 1) != CHAR_NULL) { + if (*Walker == L'\\' && *(Walker + 1) != CHAR_NULL) { + LastSlash = Walker+1; + } else if (*Walker == L':' && *(Walker + 1) != L'\\' && *(Walker + 1) != CHAR_NULL) { LastSlash = Walker+1; } } -- 1.9.5.msysgit.0