Improve error handling in `CMidiTrack::readVarLen()`

* Always check `failed()` aber `readByte()` consistently
* Simplify coding style
This commit is contained in:
Martchus 2023-12-26 22:41:45 +01:00
parent b3737c04c2
commit a8daa1bbff
2 changed files with 10 additions and 10 deletions

View File

@ -105,14 +105,14 @@ dword_t CMidiTrack::readVarLen()
if ((value = readByte()) & 0x80) if ((value = readByte()) & 0x80)
{ {
value &= 0x7F; value &= 0x7F;
for (i =0; i < 4; i++) if (failed()) {
{ return value;
value = ( value << 7 ) + (( c = readByte()) & 0x7F ); }
if (failed() == true) for (i = 0; i < 4; ++i) {
value = (value << 7) + (( c = readByte()) & 0x7F );
if (failed() || (c & 0x80) == 0)
break; break;
if ((c & 0x80) == 0) else if (i >= 3)
break;
else if (i>=3)
errorFail(SMF_END_OF_FILE); errorFail(SMF_END_OF_FILE);
} }
} }
@ -120,7 +120,7 @@ dword_t CMidiTrack::readVarLen()
if (value > 400) if (value > 400)
__dt(ppDebugTrack(2,"Large variable length data %d", value)); __dt(ppDebugTrack(2,"Large variable length data %d", value));
#endif #endif
return ( value ); return value;
} }
std::string CMidiTrack::readTextEvent() std::string CMidiTrack::readTextEvent()

View File

@ -72,7 +72,7 @@ public:
dword_t getTrackLength() {return m_trackLength;} dword_t getTrackLength() {return m_trackLength;}
void decodeTrack(); void decodeTrack();
bool failed() { return (m_midiError != SMF_NO_ERROR) ? true : false;} bool failed() { return m_midiError != SMF_NO_ERROR;}
midiErrors_t getMidiError() { return m_midiError;} midiErrors_t getMidiError() { return m_midiError;}
int length() {return m_trackEventQueue->length();} int length() {return m_trackEventQueue->length();}
@ -107,7 +107,7 @@ private:
if (m_trackLengthCounter != 0 ) if (m_trackLengthCounter != 0 )
{ {
c = static_cast<byte_t>(m_file.get()); c = static_cast<byte_t>(m_file.get());
if (m_file.fail() == true) if (m_file.fail())
errorFail(SMF_END_OF_FILE); errorFail(SMF_END_OF_FILE);
m_trackLengthCounter--; m_trackLengthCounter--;
} }