summaryrefslogtreecommitdiff
path: root/src/music
diff options
context:
space:
mode:
authorNiels Martin Hansen <nielsm@indvikleren.dk>2020-05-08 21:35:52 +0200
committerNiels Martin Hansen <nielsm@indvikleren.dk>2020-05-08 22:43:43 +0200
commit2c84549db02b9d13f88ce0c46dab651ea6d8bc08 (patch)
treeb7a8381277a395d69e8cd1b37030db170c3366d1 /src/music
parent170f3f9b2be8fd5ea65e1e189a5e52f5c4dd836e (diff)
downloadopenttd-2c84549db02b9d13f88ce0c46dab651ea6d8bc08.tar.xz
Fix: Two issues in MIDI file writer
Variable-length values would write threshold values with a byte too many. System Exclusive messages would cause write to fail since the end byte was treated as part of next message.
Diffstat (limited to 'src/music')
-rw-r--r--src/music/midifile.cpp10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/music/midifile.cpp b/src/music/midifile.cpp
index 197be14a1..67cc7b192 100644
--- a/src/music/midifile.cpp
+++ b/src/music/midifile.cpp
@@ -886,21 +886,21 @@ void MidiFile::MoveFrom(MidiFile &other)
static void WriteVariableLen(FILE *f, uint32 value)
{
- if (value < 0x7F) {
+ if (value <= 0x7F) {
byte tb = value;
fwrite(&tb, 1, 1, f);
- } else if (value < 0x3FFF) {
+ } else if (value <= 0x3FFF) {
byte tb[2];
tb[1] = value & 0x7F; value >>= 7;
tb[0] = (value & 0x7F) | 0x80; value >>= 7;
fwrite(tb, 1, sizeof(tb), f);
- } else if (value < 0x1FFFFF) {
+ } else if (value <= 0x1FFFFF) {
byte tb[3];
tb[2] = value & 0x7F; value >>= 7;
tb[1] = (value & 0x7F) | 0x80; value >>= 7;
tb[0] = (value & 0x7F) | 0x80; value >>= 7;
fwrite(tb, 1, sizeof(tb), f);
- } else if (value < 0x0FFFFFFF) {
+ } else if (value <= 0x0FFFFFFF) {
byte tb[4];
tb[3] = value & 0x7F; value >>= 7;
tb[2] = (value & 0x7F) | 0x80; value >>= 7;
@@ -1013,7 +1013,7 @@ bool MidiFile::WriteSMF(const char *filename)
ptrdiff_t sysexlen = sysexend - dp;
WriteVariableLen(f, sysexlen);
fwrite(dp, 1, sysexend - dp, f);
- dp = sysexend;
+ dp = sysexend + 1;
continue;
}