]> git.proxmox.com Git - mirror_edk2.git/blobdiff - ShellPkg/Library/UefiShellLib/UefiShellLib.c
ShellPkg: Code refine. Add error handling code to check pointer and remove redundant...
[mirror_edk2.git] / ShellPkg / Library / UefiShellLib / UefiShellLib.c
index dc36db03495ad20de55a9b69bb0da3cdb42e37ca..b7ca41b9846b65bb5c91267b5d91a2a7dbb30f5f 100644 (file)
@@ -1502,6 +1502,8 @@ ShellOpenFileMetaArg (
   ASSERT(Arg      != NULL);\r
   ASSERT(ListHead != NULL);\r
 \r
+  CleanFilePathStr = NULL;\r
+\r
   Status = InternalShellStripQuotes (Arg, &CleanFilePathStr);\r
   if (EFI_ERROR (Status)) {\r
     return Status;\r
@@ -1901,6 +1903,7 @@ InternalIsOnCheckList (
 \r
   @param[in] Name               pointer to Name of parameter found\r
   @param[in] AlwaysAllowNumbers TRUE to allow numbers, FALSE to not.\r
+  @param[in] TimeNumbers        TRUE to allow numbers with ":", FALSE otherwise.\r
 \r
   @retval TRUE                  the Parameter is a flag.\r
   @retval FALSE                 the Parameter not a flag.\r
@@ -1909,7 +1912,8 @@ BOOLEAN
 EFIAPI\r
 InternalIsFlag (\r
   IN CONST CHAR16               *Name,\r
-  IN BOOLEAN                    AlwaysAllowNumbers\r
+  IN CONST BOOLEAN              AlwaysAllowNumbers,\r
+  IN CONST BOOLEAN              TimeNumbers\r
   )\r
 {\r
   //\r
@@ -1920,7 +1924,7 @@ InternalIsFlag (
   //\r
   // If we accept numbers then dont return TRUE. (they will be values)\r
   //\r
-  if (((Name[0] == L'-' || Name[0] == L'+') && InternalShellIsHexOrDecimalNumber(Name+1, FALSE, FALSE)) && AlwaysAllowNumbers) {\r
+  if (((Name[0] == L'-' || Name[0] == L'+') && InternalShellIsHexOrDecimalNumber(Name+1, FALSE, FALSE, TimeNumbers)) && AlwaysAllowNumbers) {\r
     return (FALSE);\r
   }\r
 \r
@@ -2054,6 +2058,7 @@ InternalCommandLineParse (
         // possibly trigger the next loop(s) to populate the value of this item\r
         //\r
         case TypeValue:\r
+        case TypeTimeValue:\r
           GetItemValue = 1;\r
           ValueSize = 0;\r
           break;\r
@@ -2073,8 +2078,7 @@ InternalCommandLineParse (
           ASSERT(GetItemValue == 0);\r
           break;\r
       }\r
-    } else if (GetItemValue != 0 && !InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers)) {\r
-      ASSERT(CurrentItemPackage != NULL);\r
+    } else if (GetItemValue != 0 && CurrentItemPackage != NULL && !InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers, (CONST BOOLEAN)(CurrentItemPackage->Type == TypeTimeValue))) {\r
       //\r
       // get the item VALUE for a previous flag\r
       //\r
@@ -2112,7 +2116,7 @@ InternalCommandLineParse (
       if (GetItemValue == 0) {\r
         InsertHeadList(*CheckPackage, &CurrentItemPackage->Link);\r
       }\r
-    } else if (!InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers) ){ //|| ProblemParam == NULL) {\r
+    } else if (!InternalIsFlag(Argv[LoopCounter], AlwaysAllowNumbers, FALSE)){\r
       //\r
       // add this one as a non-flag\r
       //\r
@@ -3132,7 +3136,7 @@ ShellStrToUintn(
 \r
   Hex = FALSE;\r
 \r
-  if (!InternalShellIsHexOrDecimalNumber(String, Hex, TRUE)) {\r
+  if (!InternalShellIsHexOrDecimalNumber(String, Hex, TRUE, FALSE)) {\r
     Hex = TRUE;\r
   }\r
 \r
@@ -3549,6 +3553,7 @@ ShellPromptForResponseHii (
   @param[in] String       The string to evaluate.\r
   @param[in] ForceHex     TRUE - always assume hex.\r
   @param[in] StopAtSpace  TRUE to halt upon finding a space, FALSE to keep going.\r
+  @param[in] TimeNumbers        TRUE to allow numbers with ":", FALSE otherwise.\r
 \r
   @retval TRUE        It is all numeric (dec/hex) characters.\r
   @retval FALSE       There is a non-numeric character.\r
@@ -3558,7 +3563,8 @@ EFIAPI
 InternalShellIsHexOrDecimalNumber (\r
   IN CONST CHAR16   *String,\r
   IN CONST BOOLEAN  ForceHex,\r
-  IN CONST BOOLEAN  StopAtSpace\r
+  IN CONST BOOLEAN  StopAtSpace,\r
+  IN CONST BOOLEAN  TimeNumbers\r
   )\r
 {\r
   BOOLEAN Hex;\r
@@ -3602,6 +3608,9 @@ InternalShellIsHexOrDecimalNumber (
   // loop through the remaining characters and use the lib function\r
   //\r
   for ( ; String != NULL && *String != CHAR_NULL && !(StopAtSpace && *String == L' ') ; String++){\r
+    if (TimeNumbers && (String[0] == L':')) {\r
+      continue;\r
+    }\r
     if (Hex) {\r
       if (!ShellIsHexaDecimalDigitCharacter(*String)) {\r
         return (FALSE);\r
@@ -3925,10 +3934,10 @@ ShellConvertStringToUint64(
 \r
   Hex = ForceHex;\r
 \r
-  if (!InternalShellIsHexOrDecimalNumber(String, Hex, StopAtSpace)) {\r
+  if (!InternalShellIsHexOrDecimalNumber(String, Hex, StopAtSpace, FALSE)) {\r
     if (!Hex) {\r
       Hex = TRUE;\r
-      if (!InternalShellIsHexOrDecimalNumber(String, Hex, StopAtSpace)) {\r
+      if (!InternalShellIsHexOrDecimalNumber(String, Hex, StopAtSpace, FALSE)) {\r
         return (EFI_INVALID_PARAMETER);\r
       }\r
     } else {\r
@@ -3944,7 +3953,7 @@ ShellConvertStringToUint64(
   //\r
   // make sure we have something left that is numeric.\r
   //\r
-  if (Walker == NULL || *Walker == CHAR_NULL || !InternalShellIsHexOrDecimalNumber(Walker, Hex, StopAtSpace)) {\r
+  if (Walker == NULL || *Walker == CHAR_NULL || !InternalShellIsHexOrDecimalNumber(Walker, Hex, StopAtSpace, FALSE)) {\r
     return (EFI_INVALID_PARAMETER);\r
   }\r
 \r