diff options
author | Benjamin Dobell <benjamin.dobell+git@glassechidna.com.au> | 2012-10-07 23:33:16 +1100 |
---|---|---|
committer | Benjamin Dobell <benjamin.dobell+git@glassechidna.com.au> | 2012-10-07 23:33:44 +1100 |
commit | 8ac74126b4d8a295031ada29e3ff72d4fc5acbf4 (patch) | |
tree | ca070068b1f3f848bb09b38d5069d74cfcc71946 | |
parent | 4f3220646dfebd5c2ba554fca204f28665915955 (diff) | |
download | external_heimdall-8ac74126b4d8a295031ada29e3ff72d4fc5acbf4.zip external_heimdall-8ac74126b4d8a295031ada29e3ff72d4fc5acbf4.tar.gz external_heimdall-8ac74126b4d8a295031ada29e3ff72d4fc5acbf4.tar.bz2 |
PIT files are no longer always exactly 4096 bytes. Fixed a bug that was a
result of making this assumption.
-rw-r--r-- | heimdall/source/FlashAction.cpp | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/heimdall/source/FlashAction.cpp b/heimdall/source/FlashAction.cpp index d79235e..1ce8efb 100644 --- a/heimdall/source/FlashAction.cpp +++ b/heimdall/source/FlashAction.cpp @@ -444,21 +444,32 @@ static PitData *getPitData(const map<string, FILE *>& argumentFileMap, BridgeMan FILE *localPitFile = localPitFileIt->second; // Load the local pit file into memory. - unsigned char *pitFileBuffer = new unsigned char[4096]; - memset(pitFileBuffer, 0, 4096); - fseek(localPitFile, 0, SEEK_END); long localPitFileSize = ftell(localPitFile); rewind(localPitFile); + unsigned char *pitFileBuffer = new unsigned char[localPitFileSize]; + memset(pitFileBuffer, 0, localPitFileSize); + // dataRead is discarded, it's here to remove warnings. int dataRead = fread(pitFileBuffer, 1, localPitFileSize, localPitFile); - rewind(localPitFile); - localPitData = new PitData(); - localPitData->Unpack(pitFileBuffer); + if (dataRead > 0) + { + rewind(localPitFile); - delete [] pitFileBuffer; + localPitData = new PitData(); + localPitData->Unpack(pitFileBuffer); + + delete [] pitFileBuffer; + } + else + { + Interface::PrintError("Failed to read PIT file.\n"); + + delete [] pitFileBuffer; + return (nullptr); + } } if (repartition) |