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. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Qiu Shumin <shumin.qiu@intel.com> Reviewed-by: Ard Biesheuvel <ard.biesheuvel@linaro.org> git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@18500 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
@ -195,7 +195,9 @@ ParseCommandLineToArgs(
|
|||||||
CHAR16 *TempParameter;
|
CHAR16 *TempParameter;
|
||||||
CHAR16 *Walker;
|
CHAR16 *Walker;
|
||||||
CHAR16 *NewParam;
|
CHAR16 *NewParam;
|
||||||
|
CHAR16 *NewCommandLine;
|
||||||
UINTN Size;
|
UINTN Size;
|
||||||
|
EFI_STATUS Status;
|
||||||
|
|
||||||
ASSERT(Argc != NULL);
|
ASSERT(Argc != NULL);
|
||||||
ASSERT(Argv != NULL);
|
ASSERT(Argv != NULL);
|
||||||
@ -206,15 +208,21 @@ ParseCommandLineToArgs(
|
|||||||
return (EFI_SUCCESS);
|
return (EFI_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
TrimSpaces(&(CHAR16*)CommandLine);
|
NewCommandLine = AllocateCopyPool(StrSize(CommandLine), CommandLine);
|
||||||
Size = StrSize(CommandLine);
|
if (NewCommandLine == NULL){
|
||||||
|
return (EFI_OUT_OF_RESOURCES);
|
||||||
|
}
|
||||||
|
|
||||||
|
TrimSpaces(&NewCommandLine);
|
||||||
|
Size = StrSize(NewCommandLine);
|
||||||
TempParameter = AllocateZeroPool(Size);
|
TempParameter = AllocateZeroPool(Size);
|
||||||
if (TempParameter == NULL) {
|
if (TempParameter == NULL) {
|
||||||
|
SHELL_FREE_NON_NULL(NewCommandLine);
|
||||||
return (EFI_OUT_OF_RESOURCES);
|
return (EFI_OUT_OF_RESOURCES);
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( Count = 0
|
for ( Count = 0
|
||||||
, Walker = (CHAR16*)CommandLine
|
, Walker = (CHAR16*)NewCommandLine
|
||||||
; Walker != NULL && *Walker != CHAR_NULL
|
; Walker != NULL && *Walker != CHAR_NULL
|
||||||
; Count++
|
; Count++
|
||||||
) {
|
) {
|
||||||
@ -228,30 +236,34 @@ ParseCommandLineToArgs(
|
|||||||
//
|
//
|
||||||
(*Argv) = AllocateZeroPool((Count)*sizeof(CHAR16*));
|
(*Argv) = AllocateZeroPool((Count)*sizeof(CHAR16*));
|
||||||
if (*Argv == NULL) {
|
if (*Argv == NULL) {
|
||||||
SHELL_FREE_NON_NULL(TempParameter);
|
Status = EFI_OUT_OF_RESOURCES;
|
||||||
return (EFI_OUT_OF_RESOURCES);
|
goto Done;
|
||||||
}
|
}
|
||||||
|
|
||||||
*Argc = 0;
|
*Argc = 0;
|
||||||
Walker = (CHAR16*)CommandLine;
|
Walker = (CHAR16*)NewCommandLine;
|
||||||
while(Walker != NULL && *Walker != CHAR_NULL) {
|
while(Walker != NULL && *Walker != CHAR_NULL) {
|
||||||
SetMem16(TempParameter, Size, CHAR_NULL);
|
SetMem16(TempParameter, Size, CHAR_NULL);
|
||||||
if (EFI_ERROR(GetNextParameter(&Walker, &TempParameter, Size))) {
|
if (EFI_ERROR(GetNextParameter(&Walker, &TempParameter, Size))) {
|
||||||
SHELL_FREE_NON_NULL(TempParameter);
|
Status = EFI_INVALID_PARAMETER;
|
||||||
return (EFI_INVALID_PARAMETER);
|
goto Done;
|
||||||
}
|
}
|
||||||
|
|
||||||
NewParam = AllocateCopyPool(StrSize(TempParameter), TempParameter);
|
NewParam = AllocateCopyPool(StrSize(TempParameter), TempParameter);
|
||||||
if (NewParam == NULL){
|
if (NewParam == NULL){
|
||||||
SHELL_FREE_NON_NULL(TempParameter);
|
Status = EFI_OUT_OF_RESOURCES;
|
||||||
return (EFI_OUT_OF_RESOURCES);
|
goto Done;
|
||||||
}
|
}
|
||||||
((CHAR16**)(*Argv))[(*Argc)] = NewParam;
|
((CHAR16**)(*Argv))[(*Argc)] = NewParam;
|
||||||
(*Argc)++;
|
(*Argc)++;
|
||||||
}
|
}
|
||||||
ASSERT(Count >= (*Argc));
|
ASSERT(Count >= (*Argc));
|
||||||
|
Status = EFI_SUCCESS;
|
||||||
|
|
||||||
|
Done:
|
||||||
SHELL_FREE_NON_NULL(TempParameter);
|
SHELL_FREE_NON_NULL(TempParameter);
|
||||||
return (EFI_SUCCESS);
|
SHELL_FREE_NON_NULL(NewCommandLine);
|
||||||
|
return (Status);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user