]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Library/PeiPerformanceLib/PeiPerformanceLib.c
MdeModulePkg: Refine code to use Strn**S safe functions instead of Str**S ones in...
[mirror_edk2.git] / MdeModulePkg / Library / PeiPerformanceLib / PeiPerformanceLib.c
index 7a2d3da0ec771f2a63804a22ad35b86daffa8edb..0b5a717caa01890f8e64aea12675f24894fefa21 100644 (file)
@@ -6,7 +6,7 @@
   performance data to the GUIDed HOB. Due to the limitation of temporary RAM, the maximum\r
   number of performance logging entry is specified by PcdMaxPeiPerformanceLogEntries.  \r
 \r
-Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2015, 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
@@ -113,6 +113,7 @@ InternalSearchForLogEntry (
   )\r
 {\r
   UINT32                    Index;\r
+  UINT32                    Index2;\r
   UINT32                    NumberOfEntries;\r
   PEI_PERFORMANCE_LOG_ENTRY *LogEntryArray;\r
 \r
@@ -126,13 +127,16 @@ InternalSearchForLogEntry (
   NumberOfEntries = PeiPerformanceLog->NumberOfEntries;\r
   LogEntryArray   = (PEI_PERFORMANCE_LOG_ENTRY *) (PeiPerformanceLog + 1);\r
 \r
+  Index2 = 0;\r
+\r
   for (Index = 0; Index < NumberOfEntries; Index++) {\r
-    if ((LogEntryArray[Index].Handle == (EFI_PHYSICAL_ADDRESS) (UINTN) Handle) &&\r
-         AsciiStrnCmp (LogEntryArray[Index].Token, Token, PEI_PERFORMANCE_STRING_LENGTH) == 0 &&\r
-         AsciiStrnCmp (LogEntryArray[Index].Module, Module, PEI_PERFORMANCE_STRING_LENGTH) == 0 &&\r
-         (PeiPerformanceIdArray[Index] == Identifier) &&\r
-         LogEntryArray[Index].EndTimeStamp == 0\r
-       ) {\r
+    Index2 = NumberOfEntries - 1 - Index;\r
+    if (LogEntryArray[Index2].EndTimeStamp == 0 &&\r
+        (LogEntryArray[Index2].Handle == (EFI_PHYSICAL_ADDRESS) (UINTN) Handle) &&\r
+        AsciiStrnCmp (LogEntryArray[Index2].Token, Token, PEI_PERFORMANCE_STRING_LENGTH) == 0 &&\r
+        AsciiStrnCmp (LogEntryArray[Index2].Module, Module, PEI_PERFORMANCE_STRING_LENGTH) == 0 &&\r
+        (PeiPerformanceIdArray[Index2] == Identifier)) {\r
+      Index = Index2;\r
       break;\r
     }\r
   }\r
@@ -186,10 +190,10 @@ StartPerformanceMeasurementEx (
   LogEntryArray[Index].Handle = (EFI_PHYSICAL_ADDRESS) (UINTN) Handle;\r
 \r
   if (Token != NULL) {\r
-    AsciiStrnCpy (LogEntryArray[Index].Token, Token, PEI_PERFORMANCE_STRING_LENGTH);\r
+    AsciiStrnCpyS (LogEntryArray[Index].Token, PEI_PERFORMANCE_STRING_SIZE, Token, PEI_PERFORMANCE_STRING_LENGTH);\r
   }\r
   if (Module != NULL) {\r
-    AsciiStrnCpy (LogEntryArray[Index].Module, Module, PEI_PERFORMANCE_STRING_LENGTH);\r
+    AsciiStrnCpyS (LogEntryArray[Index].Module, PEI_PERFORMANCE_STRING_SIZE, Module, PEI_PERFORMANCE_STRING_LENGTH);\r
   }\r
 \r
   LogEntryArray[Index].EndTimeStamp = 0;\r