From 12a2c9441eff63f8cd3db594b826305454736182 Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Thu, 10 Apr 2014 00:29:11 -0400 Subject: midifile: Fix portability issue with malloc(0). In the C standards, malloc(0) may return NULL without indicating a failure to allocate. As values read from the MIDI file may be arbitrary, add one to the allocated length so that we always allocated a positive value. This fixes #165 (thanks nmain). --- src/midifile.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/midifile.c b/src/midifile.c index 00ff28d4..cb366774 100644 --- a/src/midifile.c +++ b/src/midifile.c @@ -176,9 +176,10 @@ static void *ReadByteSequence(unsigned int num_bytes, FILE *stream) unsigned int i; byte *result; - // Allocate a buffer: + // Allocate a buffer. Allocate one extra byte, as malloc(0) is + // non-portable. - result = malloc(num_bytes); + result = malloc(num_bytes + 1); if (result == NULL) { -- cgit v1.2.3