If the last line in the file did not have a newline character,
then the CurrentFilePointer would end up passed the end of
the file.

Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Jordan Justen <[email protected]>
---
 Source/C/Common/MemoryFile.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/Source/C/Common/MemoryFile.c b/Source/C/Common/MemoryFile.c
index a93a505..1fb845d 100644
--- a/Source/C/Common/MemoryFile.c
+++ b/Source/C/Common/MemoryFile.c
@@ -201,7 +201,7 @@ Returns:
     CharsToCopy = EndOfLine - InputFile->CurrentFilePointer;
   }
 
-  OutputString = malloc (CharsToCopy);
+  OutputString = malloc (CharsToCopy + 1);
   if (OutputString == NULL) {
     return NULL;
   }
@@ -227,7 +227,10 @@ Returns:
   //
   // Increment the current file pointer (include the 0x0A)
   //
-  InputFile->CurrentFilePointer += CharsToCopy + 1;
+  InputFile->CurrentFilePointer += CharsToCopy;
+  if (EndOfLine != 0) {
+    InputFile->CurrentFilePointer += 1;
+  }
   CheckMemoryFileState (InputMemoryFile);
 
   //
-- 
1.9.2


------------------------------------------------------------------------------
Is your legacy SCM system holding you back? Join Perforce May 7 to find out:
&#149; 3 signs your SCM is hindering your productivity
&#149; Requirements for releasing software faster
&#149; Expert tips and advice for migrating your SCM now
http://p.sf.net/sfu/perforce
_______________________________________________
edk2-buildtools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-buildtools-devel

Reply via email to