ShellPkg: "For Run" fix for spaces between numerals
authorJaben Carsey <Jaben.carsey@intel.com>
Fri, 15 Nov 2013 20:28:58 +0000 (20:28 +0000)
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 15 Nov 2013 20:28:58 +0000 (20:28 +0000)
Since this is expected to use a string with spaces between some of the numbers, the function must halt on spaces and not skip them.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jaben Carsey <Jaben.carsey@intel.com>
Reviewed-by: Erik Bjorge <erik.c.bjorge@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14854 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Library/UefiShellLevel1CommandsLib/For.c

index b01c69d..f0c4a23 100644 (file)
@@ -253,6 +253,29 @@ InternalRemoveAliasFromList(
   return (FALSE);\r
 }\r
 \r
+/**\r
+  Function to determine whether a string is decimal or hex representation of a number\r
+  and return the number converted from the string.\r
+\r
+  @param[in] String   String representation of a number\r
+\r
+  @return             the number\r
+  @retval (UINTN)(-1) An error ocurred.\r
+**/\r
+UINTN\r
+EFIAPI\r
+ReturnUintn(\r
+  IN CONST CHAR16 *String\r
+  )\r
+{\r
+  UINT64        RetVal;\r
+\r
+  if (!EFI_ERROR(ShellConvertStringToUint64(String, &RetVal, FALSE, FALSE))) {\r
+    return ((UINTN)RetVal);\r
+  }\r
+  return ((UINTN)(-1));\r
+}\r
+\r
 /**\r
   Function for 'for' command.\r
 \r
@@ -486,9 +509,9 @@ ShellCommandRunFor (
               ShellStatus = SHELL_INVALID_PARAMETER;\r
             } else {\r
               if (ArgSetWalker[0] == L'-') {\r
-                Info->Current = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1);\r
+                Info->Current = 0 - (INTN)ReturnUintn(ArgSetWalker+1);\r
               } else {\r
-                Info->Current = (INTN)ShellStrToUintn(ArgSetWalker);\r
+                Info->Current = (INTN)ReturnUintn(ArgSetWalker);\r
               }\r
               ArgSetWalker  = StrStr(ArgSetWalker, L" ");\r
               while (ArgSetWalker != NULL && ArgSetWalker[0] == L' ') {\r
@@ -508,9 +531,9 @@ ShellCommandRunFor (
                 ShellStatus = SHELL_INVALID_PARAMETER;\r
               } else {\r
                 if (ArgSetWalker[0] == L'-') {\r
-                  Info->End = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1);\r
+                  Info->End = 0 - (INTN)ReturnUintn(ArgSetWalker+1);\r
                 } else {\r
-                  Info->End = (INTN)ShellStrToUintn(ArgSetWalker);\r
+                  Info->End = (INTN)ReturnUintn(ArgSetWalker);\r
                 }\r
                 if (Info->Current < Info->End) {\r
                   Info->Step            = 1;\r
@@ -540,9 +563,9 @@ ShellCommandRunFor (
                       ASSERT(Info->Step == 1 || Info->Step == -1);\r
                     } else {\r
                       if (ArgSetWalker[0] == L'-') {\r
-                        Info->Step = 0 - (INTN)ShellStrToUintn(ArgSetWalker+1);\r
+                        Info->Step = 0 - (INTN)ReturnUintn(ArgSetWalker+1);\r
                       } else {\r
-                        Info->Step = (INTN)ShellStrToUintn(ArgSetWalker);\r
+                        Info->Step = (INTN)ReturnUintn(ArgSetWalker);\r
                       }\r
 \r
                       if (StrStr(ArgSetWalker, L" ") != NULL) {\r