summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSimon Howard2009-03-29 22:55:55 +0000
committerSimon Howard2009-03-29 22:55:55 +0000
commitc4f640be999e80351f1c89c893a0d5ce39c20cd9 (patch)
tree0078986faa556797024817afce518e5aac3debda /src
parentd9f55dd56cc2a21dc6be97e9a2512d9bd8f05286 (diff)
downloadchocolate-doom-c4f640be999e80351f1c89c893a0d5ce39c20cd9.tar.gz
chocolate-doom-c4f640be999e80351f1c89c893a0d5ce39c20cd9.tar.bz2
chocolate-doom-c4f640be999e80351f1c89c893a0d5ce39c20cd9.zip
Clean up error messages, minor bugs etc.
Subversion-branch: /branches/opl-branch Subversion-revision: 1492
Diffstat (limited to 'src')
-rw-r--r--src/midifile.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/src/midifile.c b/src/midifile.c
index 1b8a8786..ed60958d 100644
--- a/src/midifile.c
+++ b/src/midifile.c
@@ -33,6 +33,7 @@
#define HEADER_CHUNK_ID "MThd"
#define TRACK_CHUNK_ID "MTrk"
+#define MAX_BUFFER_SIZE 0x10000
typedef struct
{
@@ -68,7 +69,7 @@ static boolean CheckChunkHeader(chunk_header_t *chunk,
if (!result)
{
- fprintf(stderr, "CheckChunkHeader: Expected '%s' chunk header!\n",
+ fprintf(stderr, "CheckChunkHeader: Expected '%s' chunk header\n",
expected_id);
}
@@ -150,7 +151,7 @@ midi_file_t *MIDI_OpenFile(char *filename)
if (file->stream == NULL)
{
- fprintf(stderr, "Failed to open '%s'\n", filename);
+ fprintf(stderr, "MIDI_OpenFile: Failed to open '%s'\n", filename);
free(file);
return NULL;
}
@@ -193,6 +194,7 @@ static boolean ReadByte(midi_file_t *file, byte *result)
if (c == EOF)
{
+ fprintf(stderr, "ReadByte: Unexpected end of file\n");
return false;
}
else
@@ -216,7 +218,8 @@ static boolean ReadVariableLength(midi_file_t *file, unsigned int *result)
{
if (!ReadByte(file, &b))
{
- fprintf(stderr, "Error while reading variable-length value\n");
+ fprintf(stderr, "ReadVariableLength: Error while reading "
+ "variable-length value\n");
return false;
}
@@ -233,7 +236,8 @@ static boolean ReadVariableLength(midi_file_t *file, unsigned int *result)
}
}
- fprintf(stderr, "Variable-length value too long: maximum of four bytes!\n");;
+ fprintf(stderr, "ReadVariableLength: Variable-length value too "
+ "long: maximum of four bytes\n");
return false;
}
@@ -243,6 +247,13 @@ static boolean ExpandBuffer(midi_file_t *file, unsigned int new_size)
{
byte *new_buffer;
+ if (new_size > MAX_BUFFER_SIZE)
+ {
+ fprintf(stderr, "ExpandBuffer: Tried to expand buffer to %u bytes\n",
+ new_size);
+ return false;
+ }
+
if (file->buffer_size < new_size)
{
// Reallocate to a larger size:
@@ -294,7 +305,7 @@ static boolean ReadByteSequence(midi_file_t *file, unsigned int num_bytes)
// (three byte) otherwise it is single parameter (two byte)
static boolean ReadChannelEvent(midi_file_t *file, midi_event_t *event,
- int event_type, boolean two_param)
+ byte event_type, boolean two_param)
{
byte b;
@@ -307,6 +318,8 @@ static boolean ReadChannelEvent(midi_file_t *file, midi_event_t *event,
if (!ReadByte(file, &b))
{
+ fprintf(stderr, "ReadChannelEvent: Error while reading channel "
+ "event parameters\n");
return false;
}
@@ -318,6 +331,8 @@ static boolean ReadChannelEvent(midi_file_t *file, midi_event_t *event,
{
if (!ReadByte(file, &b))
{
+ fprintf(stderr, "ReadChannelEvent: Error while reading channel "
+ "event parameters\n");
return false;
}
@@ -389,7 +404,7 @@ static boolean ReadMetaEvent(midi_file_t *file, midi_event_t *event)
event->data.meta.data = file->buffer;
- return false;
+ return true;
}
boolean MIDI_ReadEvent(midi_file_t *file, midi_event_t *event)