]> git.proxmox.com Git - mirror_edk2.git/commitdiff
ShellPkg: Remove use of ASSERT to test parameters
authorJaben Carsey <Jaben.carsey@intel.com>
Wed, 18 Jun 2014 16:37:16 +0000 (16:37 +0000)
committerjcarsey <jcarsey@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 18 Jun 2014 16:37:16 +0000 (16:37 +0000)
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@15566 6f19259b-4bc3-4df7-8a09-765794883524

ShellPkg/Library/UefiFileHandleLib/UefiFileHandleLib.c

index 2085f6c5218432d0c1eaef7d123c73196d1ae77a..5af75c5adb3996861b54aaf3b28ab6095d113400 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Provides interface to EFI_FILE_HANDLE functionality.\r
 \r
-  Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved. <BR>\r
+  Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved. <BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -119,11 +119,9 @@ FileHandleSetInfo (
   )\r
 {\r
 \r
-  //\r
-  // ASSERT if the FileHandle or FileInfo is NULL\r
-  //\r
-  ASSERT (FileHandle != NULL);\r
-  ASSERT (FileInfo   != NULL);\r
+  if (FileHandle == NULL || FileInfo == NULL) {\r
+    return (EFI_INVALID_PARAMETER);\r
+  }\r
 \r
   //\r
   // Set the info\r
@@ -171,10 +169,9 @@ FileHandleRead(
   OUT VOID                      *Buffer\r
   )\r
 {\r
-  //\r
-  // ASSERT if FileHandle is NULL\r
-  //\r
-  ASSERT (FileHandle != NULL);\r
+  if (FileHandle == NULL) {\r
+    return (EFI_INVALID_PARAMETER);\r
+  }\r
 \r
   //\r
   // Perform the read based on EFI_FILE_PROTOCOL\r
@@ -215,10 +212,10 @@ FileHandleWrite(
   IN VOID                       *Buffer\r
   )\r
 {\r
-  //\r
-  // ASSERT if FileHandle is NULL\r
-  //\r
-  ASSERT (FileHandle != NULL);\r
+  if (FileHandle == NULL) {\r
+    return (EFI_INVALID_PARAMETER);\r
+  }\r
+\r
   //\r
   // Perform the write based on EFI_FILE_PROTOCOL\r
   //\r
@@ -243,10 +240,11 @@ FileHandleClose (
   )\r
 {\r
   EFI_STATUS Status;\r
-  //\r
-  // ASSERT if FileHandle is NULL\r
-  //\r
-  ASSERT (FileHandle != NULL);\r
+\r
+  if (FileHandle == NULL) {\r
+    return (EFI_INVALID_PARAMETER);\r
+  }\r
+\r
   //\r
   // Perform the Close based on EFI_FILE_PROTOCOL\r
   //\r
@@ -275,10 +273,11 @@ FileHandleDelete (
   )\r
 {\r
   EFI_STATUS Status;\r
-  //\r
-  // ASSERT if FileHandle is NULL\r
-  //\r
-  ASSERT (FileHandle != NULL);\r
+\r
+  if (FileHandle == NULL) {\r
+    return (EFI_INVALID_PARAMETER);\r
+  }\r
+\r
   //\r
   // Perform the Delete based on EFI_FILE_PROTOCOL\r
   //\r
@@ -312,10 +311,10 @@ FileHandleSetPosition (
   IN UINT64             Position\r
   )\r
 {\r
-  //\r
-  // ASSERT if FileHandle is NULL\r
-  //\r
-  ASSERT (FileHandle != NULL);\r
+  if (FileHandle == NULL) {\r
+    return (EFI_INVALID_PARAMETER);\r
+  }\r
+\r
   //\r
   // Perform the SetPosition based on EFI_FILE_PROTOCOL\r
   //\r
@@ -344,13 +343,10 @@ FileHandleGetPosition (
   OUT UINT64                    *Position\r
   )\r
 {\r
-  if (Position == NULL) {\r
+  if (Position == NULL || FileHandle == NULL) {\r
     return (EFI_INVALID_PARAMETER);\r
   }\r
-  //\r
-  // ASSERT if FileHandle is NULL\r
-  //\r
-  ASSERT (FileHandle != NULL);\r
+\r
   //\r
   // Perform the GetPosition based on EFI_FILE_PROTOCOL\r
   //\r
@@ -376,10 +372,10 @@ FileHandleFlush (
   IN EFI_FILE_HANDLE            FileHandle\r
   )\r
 {\r
-  //\r
-  // ASSERT if FileHandle is NULL\r
-  //\r
-  ASSERT (FileHandle != NULL);\r
+  if (FileHandle == NULL) {\r
+    return (EFI_INVALID_PARAMETER);\r
+  }\r
+\r
   //\r
   // Perform the Flush based on EFI_FILE_PROTOCOL\r
   //\r
@@ -389,7 +385,7 @@ FileHandleFlush (
 /**\r
   function to determine if a given handle is a directory handle\r
 \r
-  if DirHandle is NULL then ASSERT()\r
+  if DirHandle is NULL then return error\r
 \r
   open the file information on the DirHandle and verify that the Attribute\r
   includes EFI_FILE_DIRECTORY bit set.\r
@@ -408,10 +404,9 @@ FileHandleIsDirectory (
 {\r
   EFI_FILE_INFO *DirInfo;\r
 \r
-  //\r
-  // ASSERT if DirHandle is NULL\r
-  //\r
-  ASSERT(DirHandle != NULL);\r
+  if (DirHandle == NULL) {\r
+    return (EFI_INVALID_PARAMETER);\r
+  }\r
 \r
   //\r
   // get the file information for DirHandle\r
@@ -549,12 +544,9 @@ FileHandleFindNextFile(
   EFI_STATUS    Status;\r
   UINTN         BufferSize;\r
 \r
-  //\r
-  // ASSERTs for DirHandle or Buffer or NoFile poitners being NULL\r
-  //\r
-  ASSERT (DirHandle != NULL);\r
-  ASSERT (Buffer    != NULL);\r
-  ASSERT (NoFile    != NULL);\r
+  if (DirHandle == NULL || Buffer == NULL || NoFile == NULL) {\r
+    return (EFI_INVALID_PARAMETER);\r
+  }\r
 \r
   //\r
   // This BufferSize MUST stay equal to the originally allocated one in GetFirstFile\r
@@ -584,8 +576,8 @@ FileHandleFindNextFile(
 /**\r
   Retrieve the size of a file.\r
 \r
-  if FileHandle is NULL then ASSERT()\r
-  if Size is NULL then ASSERT()\r
+  if FileHandle is NULL then return error\r
+  if Size is NULL then return error\r
 \r
   This function extracts the file size info from the FileHandle's EFI_FILE_INFO\r
   data.\r
@@ -605,11 +597,9 @@ FileHandleGetSize (
 {\r
   EFI_FILE_INFO                 *FileInfo;\r
 \r
-  //\r
-  // ASSERT for FileHandle or Size being NULL\r
-  //\r
-  ASSERT (FileHandle != NULL);\r
-  ASSERT (Size != NULL);\r
+  if (FileHandle == NULL || Size == NULL) {\r
+    return (EFI_INVALID_PARAMETER);\r
+  }\r
 \r
   //\r
   // get the FileInfo structure\r
@@ -635,7 +625,7 @@ FileHandleGetSize (
 /**\r
   Set the size of a file.\r
 \r
-  If FileHandle is NULL then ASSERT().\r
+  If FileHandle is NULL then return error.\r
 \r
   This function changes the file size info from the FileHandle's EFI_FILE_INFO\r
   data.\r
@@ -656,10 +646,9 @@ FileHandleSetSize (
   EFI_FILE_INFO                 *FileInfo;\r
   EFI_STATUS                    Status;\r
 \r
-  //\r
-  // ASSERT for FileHandle or Size being NULL\r
-  //\r
-  ASSERT (FileHandle != NULL);\r
+  if (FileHandle == NULL) {\r
+    return (EFI_INVALID_PARAMETER);\r
+  }\r
 \r
   //\r
   // get the FileInfo structure\r
@@ -701,7 +690,7 @@ FileHandleSetSize (
   If Source is NULL, there is nothing to append, just return the current buffer in\r
   Destination.\r
 \r
-  if Destination is NULL, then ASSERT()\r
+  if Destination is NULL, then return error\r
   if Destination's current length (including NULL terminator) is already more then\r
   CurrentSize, then ASSERT()\r
 \r
@@ -728,10 +717,9 @@ StrnCatGrowLeft (
   UINTN NewSize;\r
   UINTN CopySize;\r
 \r
-  //\r
-  // ASSERTs\r
-  //\r
-  ASSERT(Destination != NULL);\r
+  if (Destination == NULL) {\r
+    return (NULL);\r
+  }\r
 \r
   //\r
   // If there's nothing to do then just return Destination\r
@@ -964,12 +952,11 @@ FileHandleReadLine(
 \r
   if (Handle == NULL\r
     ||Size   == NULL\r
+    ||(Buffer==NULL&&*Size!=0)\r
    ){\r
     return (EFI_INVALID_PARAMETER);\r
   }\r
-  if (Buffer == NULL) {\r
-    ASSERT(*Size == 0);\r
-  } else {\r
+  if (Buffer != NULL) {\r
     *Buffer = CHAR_NULL;\r
   }\r
   FileHandleGetPosition(Handle, &OriginalFilePosition);\r
@@ -1032,7 +1019,7 @@ FileHandleReadLine(
 /**\r
   function to write a line of unicode text to a file.\r
 \r
-  if Handle is NULL, ASSERT.\r
+  if Handle is NULL, return error.\r
   if Buffer is NULL, do nothing.  (return SUCCESS)\r
 \r
   @param[in]     Handle         FileHandle to write to\r
@@ -1053,12 +1040,14 @@ FileHandleWriteLine(
   EFI_STATUS Status;\r
   UINTN      Size;\r
 \r
-  ASSERT(Handle != NULL);\r
-\r
   if (Buffer == NULL) {\r
     return (EFI_SUCCESS);\r
   }\r
 \r
+  if (Handle == NULL) {\r
+    return (EFI_INVALID_PARAMETER);\r
+  }\r
+\r
   Size = StrSize(Buffer) - sizeof(Buffer[0]);\r
   Status = FileHandleWrite(Handle, &Size, Buffer);\r
   if (EFI_ERROR(Status)) {\r
@@ -1096,7 +1085,9 @@ FileHandlePrintLine(
   // Get a buffer to print into\r
   //\r
   Buffer = AllocateZeroPool (PcdGet16 (PcdShellPrintBufferSize));\r
-  ASSERT (Buffer != NULL);\r
+  if (Buffer == NULL) {\r
+    return (EFI_OUT_OF_RESOURCES);\r
+  }\r
 \r
   //\r
   // Print into our buffer\r
@@ -1122,7 +1113,7 @@ FileHandlePrintLine(
 \r
   This will NOT work on directories.\r
 \r
-  If Handle is NULL, then ASSERT.\r
+  If Handle is NULL, then return False.\r
 \r
   @param[in] Handle     the file handle\r
 \r
@@ -1139,20 +1130,19 @@ FileHandleEof(
   UINT64        Pos;\r
   BOOLEAN       RetVal;\r
 \r
-  //\r
-  // ASSERT if Handle is NULL\r
-  //\r
-  ASSERT(Handle != NULL);\r
+  if (Handle == NULL) {\r
+    return (FALSE);\r
+  }\r
 \r
   FileHandleGetPosition(Handle, &Pos);\r
   Info = FileHandleGetInfo (Handle);\r
-  ASSERT(Info != NULL);\r
-  FileHandleSetPosition(Handle, Pos);\r
 \r
   if (Info == NULL) {\r
     return (FALSE);\r
   }\r
 \r
+  FileHandleSetPosition(Handle, Pos);\r
+\r
   if (Pos == Info->FileSize) {\r
     RetVal = TRUE;\r
   } else {\r