|
From: <man...@us...> - 2013-10-22 05:58:54
|
Revision: 2975
http://sourceforge.net/p/modplug/code/2975
Author: manxorist
Date: 2013-10-22 05:58:46 +0000 (Tue, 22 Oct 2013)
Log Message:
-----------
[Ref] Like ReadVector, make ReadArray only accept arrays of single-byte type to make it harder to forget converting endiannesss on the read data.
[Ref] Some small related changes.
Modified Paths:
--------------
trunk/OpenMPT/soundlib/FileReader.h
trunk/OpenMPT/soundlib/Load_dsm.cpp
trunk/OpenMPT/soundlib/Load_stm.cpp
Modified: trunk/OpenMPT/soundlib/FileReader.h
===================================================================
--- trunk/OpenMPT/soundlib/FileReader.h 2013-10-21 19:53:42 UTC (rev 2974)
+++ trunk/OpenMPT/soundlib/FileReader.h 2013-10-22 05:58:46 UTC (rev 2975)
@@ -869,7 +869,7 @@
template<typename T, off_t destSize>
bool ReadArray(T (&destArray)[destSize])
{
- //STATIC_ASSERT(sizeof(T) == 1);
+ STATIC_ASSERT(sizeof(T) == 1);
if(CanRead(sizeof(destArray)))
{
for(std::size_t i = 0; i < destSize; ++i)
Modified: trunk/OpenMPT/soundlib/Load_dsm.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_dsm.cpp 2013-10-21 19:53:42 UTC (rev 2974)
+++ trunk/OpenMPT/soundlib/Load_dsm.cpp 2013-10-22 05:58:46 UTC (rev 2975)
@@ -129,14 +129,20 @@
{
file.Rewind();
- char fileMagic[3][4];
- file.ReadArray(fileMagic);
- if(!memcmp(fileMagic[0], "RIFF", 4)
- && !memcmp(fileMagic[2], "DSMF", 4))
+ char fileMagic0[4];
+ char fileMagic1[4];
+ char fileMagic2[4];
+
+ if(!file.ReadArray(fileMagic0)) return false;
+ if(!file.ReadArray(fileMagic1)) return false;
+ if(!file.ReadArray(fileMagic2)) return false;
+
+ if(!memcmp(fileMagic0, "RIFF", 4)
+ && !memcmp(fileMagic2, "DSMF", 4))
{
// "Normal" DSM files with RIFF header
// <RIFF> <file size> <DSMF>
- } else if(!memcmp(fileMagic[0], "DSMF", 4))
+ } else if(!memcmp(fileMagic0, "DSMF", 4))
{
// DSM files with alternative header
// <DSMF> <4 bytes, usually 4x NUL or RIFF> <file size> <4 bytes, usually DSMF but not always>
Modified: trunk/OpenMPT/soundlib/Load_stm.cpp
===================================================================
--- trunk/OpenMPT/soundlib/Load_stm.cpp 2013-10-21 19:53:42 UTC (rev 2974)
+++ trunk/OpenMPT/soundlib/Load_stm.cpp 2013-10-22 05:58:46 UTC (rev 2975)
@@ -109,6 +109,18 @@
STATIC_ASSERT(sizeof(STMPatternEntry) == 4);
+struct PACKED STMPatternData
+{
+ STMPatternEntry entry[64 * 4];
+ void ConvertEndianness()
+ {
+ // nothing
+ }
+};
+
+STATIC_ASSERT(sizeof(STMPatternData) == 4*64*4);
+
+
#ifdef NEEDS_PRAGMA_PACK
#pragma pack(pop)
#endif
@@ -179,9 +191,9 @@
for(PATTERNINDEX pat = 0; pat < fileHeader.numPatterns; pat++)
{
- STMPatternEntry patternData[64 * 4];
+ STMPatternData patternData;
- if(!(loadFlags & loadPatternData) || Patterns.Insert(pat, 64) || !file.ReadArray(patternData))
+ if(!(loadFlags & loadPatternData) || Patterns.Insert(pat, 64) || !file.ReadConvertEndianness(patternData))
{
file.Skip(sizeof(patternData));
continue;
@@ -193,7 +205,7 @@
for(size_t n = 0; n < 64 * 4; n++, m++)
{
- const STMPatternEntry &entry = patternData[n];
+ const STMPatternEntry &entry = patternData.entry[n];
if(entry.note == 0xFE || entry.note == 0xFC)
{
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|