From 81cd2f536ef0097392b51f96405321ce7b01350c Mon Sep 17 00:00:00 2001
From: Eric Dong <eric.dong@intel.com>
Date: Thu, 26 Jun 2014 01:38:46 +0000
Subject: Refine code to make it more safely.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Eric Dong <eric.dong@intel.com>
Reviewed-by: Jaben Carsey <Jaben.carsey@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@15593 6f19259b-4bc3-4df7-8a09-765794883524
---
 ShellPkg/Library/UefiShellLevel1CommandsLib/For.c | 31 +++++++----------------
 1 file changed, 9 insertions(+), 22 deletions(-)

(limited to 'ShellPkg/Library/UefiShellLevel1CommandsLib')

diff --git a/ShellPkg/Library/UefiShellLevel1CommandsLib/For.c b/ShellPkg/Library/UefiShellLevel1CommandsLib/For.c
index 85b85d8dcf..4fdbdd051d 100644
--- a/ShellPkg/Library/UefiShellLevel1CommandsLib/For.c
+++ b/ShellPkg/Library/UefiShellLevel1CommandsLib/For.c
@@ -1,7 +1,7 @@
 /** @file
   Main file for endfor and for shell level 1 functions.
 
-  Copyright (c) 2009 - 2012, Intel Corporation. All rights reserved.<BR>
+  Copyright (c) 2009 - 2014, Intel Corporation. All rights reserved.<BR>
   This program and the accompanying materials
   are licensed and made available under the terms and conditions of the BSD License
   which accompanies this distribution.  The full text of the license may be found at
@@ -333,7 +333,7 @@ ShellCommandRunFor (
   CurrentScriptFile = ShellCommandGetCurrentScriptFile();
   ASSERT(CurrentScriptFile != NULL);
 
-  if (CurrentScriptFile->CurrentCommand->Data == NULL) {
+  if ((CurrentScriptFile->CurrentCommand != NULL) && (CurrentScriptFile->CurrentCommand->Data == NULL)) {
     FirstPass = TRUE;
 
     //
@@ -348,8 +348,7 @@ ShellCommandRunFor (
         gShellLevel1HiiHandle, 
         L"EndFor", 
         L"For", 
-        CurrentScriptFile->CurrentCommand!=NULL
-          ?CurrentScriptFile->CurrentCommand->Line:0);
+        CurrentScriptFile->CurrentCommand->Line);
       return (SHELL_DEVICE_ERROR);
     }
 
@@ -459,9 +458,7 @@ ShellCommandRunFor (
             STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), 
             gShellLevel1HiiHandle, 
             ArgSet, 
-            CurrentScriptFile!=NULL 
-              && CurrentScriptFile->CurrentCommand!=NULL
-              ? CurrentScriptFile->CurrentCommand->Line:0);
+            CurrentScriptFile->CurrentCommand->Line);
           ShellStatus = SHELL_INVALID_PARAMETER;
         } else {
           TempSpot = StrStr(ArgSetWalker, L")");
@@ -483,9 +480,7 @@ ShellCommandRunFor (
               NULL, 
               STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), 
               gShellLevel1HiiHandle, 
-              CurrentScriptFile!=NULL 
-                && CurrentScriptFile->CurrentCommand!=NULL
-                ? CurrentScriptFile->CurrentCommand->Line:0);
+              CurrentScriptFile->CurrentCommand->Line);
             ShellStatus = SHELL_INVALID_PARAMETER;
           } else {
             *TempSpot = CHAR_NULL;
@@ -501,9 +496,7 @@ ShellCommandRunFor (
                 STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), 
                 gShellLevel1HiiHandle, 
                 ArgSet, 
-                CurrentScriptFile!=NULL 
-                  && CurrentScriptFile->CurrentCommand!=NULL
-                  ? CurrentScriptFile->CurrentCommand->Line:0);
+                CurrentScriptFile->CurrentCommand->Line);
               ShellStatus = SHELL_INVALID_PARAMETER;
             } else {
               if (ArgSetWalker[0] == L'-') {
@@ -523,9 +516,7 @@ ShellCommandRunFor (
                   STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), 
                   gShellLevel1HiiHandle, 
                   ArgSet, 
-                  CurrentScriptFile!=NULL 
-                    && CurrentScriptFile->CurrentCommand!=NULL
-                    ? CurrentScriptFile->CurrentCommand->Line:0);
+                  CurrentScriptFile->CurrentCommand->Line);
                 ShellStatus = SHELL_INVALID_PARAMETER;
               } else {
                 if (ArgSetWalker[0] == L'-') {
@@ -552,9 +543,7 @@ ShellCommandRunFor (
                       STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), 
                       gShellLevel1HiiHandle, 
                       ArgSet, 
-                      CurrentScriptFile!=NULL 
-                        && CurrentScriptFile->CurrentCommand!=NULL
-                        ? CurrentScriptFile->CurrentCommand->Line:0);
+                      CurrentScriptFile->CurrentCommand->Line);
                     ShellStatus = SHELL_INVALID_PARAMETER;
                   } else {
                     if (*ArgSetWalker == L')') {
@@ -574,9 +563,7 @@ ShellCommandRunFor (
                           STRING_TOKEN (STR_GEN_PROBLEM_SCRIPT), 
                           gShellLevel1HiiHandle, 
                           ArgSet, 
-                          CurrentScriptFile!=NULL 
-                            && CurrentScriptFile->CurrentCommand!=NULL
-                            ? CurrentScriptFile->CurrentCommand->Line:0);
+                          CurrentScriptFile->CurrentCommand->Line);
                         ShellStatus = SHELL_INVALID_PARAMETER;
                       }
                     }
-- 
cgit v1.2.3