|
From: <man...@us...> - 2013-06-28 21:02:41
|
Revision: 2433
http://sourceforge.net/p/modplug/code/2433
Author: manxorist
Date: 2013-06-28 21:02:30 +0000 (Fri, 28 Jun 2013)
Log Message:
-----------
[Fix] Replace ReadArray and ReadVector with ReadArrayLE and ReadVectorLE where appropriate.
Modified Paths:
--------------
trunk/OpenMPT/soundlib/FileReader.h
trunk/OpenMPT/soundlib/LOAD_AMF.CPP
trunk/OpenMPT/soundlib/Load_ams.cpp
trunk/OpenMPT/soundlib/Load_it.cpp
Modified: trunk/OpenMPT/soundlib/FileReader.h
===================================================================
--- trunk/OpenMPT/soundlib/FileReader.h 2013-06-28 20:43:06 UTC (rev 2432)
+++ trunk/OpenMPT/soundlib/FileReader.h 2013-06-28 21:02:30 UTC (rev 2433)
@@ -859,12 +859,13 @@
}
}
- // Read an array.
+ // Read an array of byte-sized values.
// If successful, the file cursor is advanced by the size of the array.
// Otherwise, the target is zeroed.
template<typename T, off_t destSize>
bool ReadArray(T (&destArray)[destSize])
{
+ //STATIC_ASSERT(sizeof(T) == 1);
if(CanRead(sizeof(destArray)))
{
for(std::size_t i = 0; i < destSize; ++i)
@@ -879,12 +880,33 @@
}
}
- // Read destSize elements of type T into a vector.
+ // Read an array.
+ // If successful, the file cursor is advanced by the size of the array.
+ // Otherwise, the target is zeroed.
+ template<typename T, off_t destSize>
+ bool ReadArrayLE(T (&destArray)[destSize])
+ {
+ if(CanRead(sizeof(destArray)))
+ {
+ for(std::size_t i = 0; i < destSize; ++i)
+ {
+ destArray[i] = ReadIntLE<T>();
+ }
+ return true;
+ } else
+ {
+ MemsetZero(destArray);
+ return false;
+ }
+ }
+
+ // Read destSize elements of byte-sized type T into a vector.
// If successful, the file cursor is advanced by the size of the vector.
// Otherwise, the vector is resized to destSize, but possibly existing contents are not cleared.
template<typename T>
bool ReadVector(std::vector<T> &destVector, size_t destSize)
{
+ STATIC_ASSERT(sizeof(T) == 1);
const off_t readSize = sizeof(T) * destSize;
destVector.resize(destSize);
if(CanRead(readSize))
@@ -900,6 +922,27 @@
}
}
+ // Read destSize elements of type T into a vector.
+ // If successful, the file cursor is advanced by the size of the vector.
+ // Otherwise, the vector is resized to destSize, but possibly existing contents are not cleared.
+ template<typename T>
+ bool ReadVectorLE(std::vector<T> &destVector, size_t destSize)
+ {
+ const off_t readSize = sizeof(T) * destSize;
+ destVector.resize(destSize);
+ if(CanRead(readSize))
+ {
+ for(std::size_t i = 0; i < destSize; ++i)
+ {
+ destVector[i] = ReadIntLE<T>();
+ }
+ return true;
+ } else
+ {
+ return false;
+ }
+ }
+
// Compare a magic string with the current stream position.
// Returns true if they are identical and advances the file cursor by the the length of the "magic" string.
// Returns false if the string could not be found. The file cursor is not advanced in this case.
Modified: trunk/OpenMPT/soundlib/LOAD_AMF.CPP
===================================================================
--- trunk/OpenMPT/soundlib/LOAD_AMF.CPP 2013-06-28 20:43:06 UTC (rev 2432)
+++ trunk/OpenMPT/soundlib/LOAD_AMF.CPP 2013-06-28 21:02:30 UTC (rev 2433)
@@ -513,7 +513,7 @@
// Read Track Mapping Table
std::vector<uint16> trackMap;
- file.ReadVector(trackMap, fileHeader.numTracks);
+ file.ReadVectorLE(trackMap, fileHeader.numTracks);
uint16 trackCount = 0;
for(std::vector<uint16>::const_iterator i = trackMap.begin(); i != trackMap.end(); i++)
{
@@ -573,7 +573,7 @@
// Get table with per-channel track assignments
file.Seek(trackStartPos + pat * (GetNumChannels() * 2 + (fileHeader.version >= 14 ? 2 : 0)));
std::vector<uint16> tracks;
- file.ReadVector(tracks, GetNumChannels());
+ file.ReadVectorLE(tracks, GetNumChannels());
for(CHANNELINDEX chn = 0; chn < GetNumChannels(); chn++)
{
Modified: trunk/OpenMPT/soundlib/Load_ams.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_ams.cpp 2013-06-28 20:43:06 UTC (rev 2432)
+++ trunk/OpenMPT/soundlib/Load_ams.cpp 2013-06-28 21:02:30 UTC (rev 2433)
@@ -469,12 +469,12 @@
// Read Order List
std::vector<uint16> orders;
- if(file.ReadVector(orders, fileHeader.numOrds))
+ if(file.ReadVectorLE(orders, fileHeader.numOrds))
{
Order.resize(fileHeader.numOrds);
for(size_t i = 0; i < fileHeader.numOrds; i++)
{
- Order[i] = SwapBytesLE(orders[i]);
+ Order[i] = orders[i];
}
}
@@ -913,12 +913,12 @@
// Read Order List
std::vector<uint16> orders;
- if(file.ReadVector(orders, fileHeader.numOrds))
+ if(file.ReadVectorLE(orders, fileHeader.numOrds))
{
Order.resize(fileHeader.numOrds);
for(size_t i = 0; i < fileHeader.numOrds; i++)
{
- Order[i] = SwapBytesLE(orders[i]);
+ Order[i] = orders[i];
}
}
Modified: trunk/OpenMPT/soundlib/Load_it.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_it.cpp 2013-06-28 20:43:06 UTC (rev 2432)
+++ trunk/OpenMPT/soundlib/Load_it.cpp 2013-06-28 21:02:30 UTC (rev 2433)
@@ -482,9 +482,9 @@
// Reading instrument, sample and pattern offsets
std::vector<uint32> insPos, smpPos, patPos;
- file.ReadVector(insPos, fileHeader.insnum);
- file.ReadVector(smpPos, fileHeader.smpnum);
- file.ReadVector(patPos, fileHeader.patnum);
+ file.ReadVectorLE(insPos, fileHeader.insnum);
+ file.ReadVectorLE(smpPos, fileHeader.smpnum);
+ file.ReadVectorLE(patPos, fileHeader.patnum);
// Find the first parapointer.
// This is used for finding out whether the edit history is actually stored in the file or not,
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|