Revision: 18502
          http://sourceforge.net/p/edk2/code/18502
Author:   hwu1225
Date:     2015-09-18 01:19:00 +0000 (Fri, 18 Sep 2015)
Log Message:
-----------
ShellPkg: Fix GCC build fail and code refine.

1. Fix GCC build fail.
2. It's not correct to cast away constness to allow TrimSpaces() to modify 
'commandline'.
   This patch makes a copy of 'commandLine' and work with that in the remainder 
of the function.

(Sync patch r18500 from main trunk.)

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Qiu Shumin <[email protected]>
Reviewed-by: Ard Biesheuvel <[email protected]>

Revision Links:
--------------
    http://sourceforge.net/p/edk2/code/18500

Modified Paths:
--------------
    branches/UDK2015/ShellPkg/Application/Shell/ShellParametersProtocol.c

Modified: branches/UDK2015/ShellPkg/Application/Shell/ShellParametersProtocol.c
===================================================================
--- branches/UDK2015/ShellPkg/Application/Shell/ShellParametersProtocol.c       
2015-09-18 01:18:34 UTC (rev 18501)
+++ branches/UDK2015/ShellPkg/Application/Shell/ShellParametersProtocol.c       
2015-09-18 01:19:00 UTC (rev 18502)
@@ -195,7 +195,9 @@
   CHAR16      *TempParameter;
   CHAR16      *Walker;
   CHAR16      *NewParam;
+  CHAR16      *NewCommandLine;
   UINTN       Size;
+  EFI_STATUS  Status;
 
   ASSERT(Argc != NULL);
   ASSERT(Argv != NULL);
@@ -206,15 +208,21 @@
     return (EFI_SUCCESS);
   }
 
-  TrimSpaces(&(CHAR16*)CommandLine);
-  Size = StrSize(CommandLine);
+  NewCommandLine = AllocateCopyPool(StrSize(CommandLine), CommandLine);
+  if (NewCommandLine == NULL){
+    return (EFI_OUT_OF_RESOURCES);
+  }
+
+  TrimSpaces(&NewCommandLine);
+  Size = StrSize(NewCommandLine);
   TempParameter = AllocateZeroPool(Size);
   if (TempParameter == NULL) {
+    SHELL_FREE_NON_NULL(NewCommandLine);
     return (EFI_OUT_OF_RESOURCES);
   }
 
   for ( Count = 0
-      , Walker = (CHAR16*)CommandLine
+      , Walker = (CHAR16*)NewCommandLine
       ; Walker != NULL && *Walker != CHAR_NULL
       ; Count++
       ) {
@@ -228,30 +236,34 @@
   //
   (*Argv) = AllocateZeroPool((Count)*sizeof(CHAR16*));
   if (*Argv == NULL) {
-    SHELL_FREE_NON_NULL(TempParameter);
-    return (EFI_OUT_OF_RESOURCES);
+    Status = EFI_OUT_OF_RESOURCES;
+    goto Done;
   }
 
   *Argc = 0;
-  Walker = (CHAR16*)CommandLine;
+  Walker = (CHAR16*)NewCommandLine;
   while(Walker != NULL && *Walker != CHAR_NULL) {
     SetMem16(TempParameter, Size, CHAR_NULL);
     if (EFI_ERROR(GetNextParameter(&Walker, &TempParameter, Size))) {
-      SHELL_FREE_NON_NULL(TempParameter);
-      return (EFI_INVALID_PARAMETER);
+      Status = EFI_INVALID_PARAMETER;
+      goto Done;
     }
 
     NewParam = AllocateCopyPool(StrSize(TempParameter), TempParameter);
     if (NewParam == NULL){
-      SHELL_FREE_NON_NULL(TempParameter);
-      return (EFI_OUT_OF_RESOURCES);
+      Status = EFI_OUT_OF_RESOURCES;
+      goto Done;
     }
     ((CHAR16**)(*Argv))[(*Argc)] = NewParam;
     (*Argc)++;
   }
   ASSERT(Count >= (*Argc));
+  Status = EFI_SUCCESS;
+  
+Done:
   SHELL_FREE_NON_NULL(TempParameter);
-  return (EFI_SUCCESS);
+  SHELL_FREE_NON_NULL(NewCommandLine);
+  return (Status);
 }
 
 /**


------------------------------------------------------------------------------
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to