ref: c4f640be999e80351f1c89c893a0d5ce39c20cd9
parent: d9f55dd56cc2a21dc6be97e9a2512d9bd8f05286
author: Simon Howard <[email protected]>
date: Sun Mar 29 18:55:55 EDT 2009
Clean up error messages, minor bugs etc. Subversion-branch: /branches/opl-branch Subversion-revision: 1492
--- 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 @@
if (!result)
{
- fprintf(stderr, "CheckChunkHeader: Expected '%s' chunk header!\n",
+ fprintf(stderr, "CheckChunkHeader: Expected '%s' chunk header\n",
expected_id);
}
@@ -150,7 +151,7 @@
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 @@
if (c == EOF)
{
+ fprintf(stderr, "ReadByte: Unexpected end of file\n");
return false;
}
else
@@ -216,7 +218,8 @@
{
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 @@
}
}
- 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 @@
{
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 @@
// (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 @@
if (!ReadByte(file, &b))
{
+ fprintf(stderr, "ReadChannelEvent: Error while reading channel "
+ "event parameters\n");
return false;
}
@@ -318,6 +331,8 @@
{
if (!ReadByte(file, &b))
{
+ fprintf(stderr, "ReadChannelEvent: Error while reading channel "
+ "event parameters\n");
return false;
}
@@ -389,7 +404,7 @@
event->data.meta.data = file->buffer;
- return false;
+ return true;
}
boolean MIDI_ReadEvent(midi_file_t *file, midi_event_t *event)