diff options
author | Max Kellermann <max@duempel.org> | 2012-02-13 18:05:42 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2012-02-13 18:17:05 +0100 |
commit | 7855a3257980e45dec7cc57e998a5b4fa1504903 (patch) | |
tree | 613bdb2c5b58e4778247269c3dc1cd36c2d130df /src | |
parent | 9c92afa5fef58f3a7781d9cd95de26ab07cdd079 (diff) | |
download | mpd-7855a3257980e45dec7cc57e998a5b4fa1504903.tar.gz mpd-7855a3257980e45dec7cc57e998a5b4fa1504903.tar.xz mpd-7855a3257980e45dec7cc57e998a5b4fa1504903.zip |
pcm_buffer: pcm_buffer_get() never returns NULL
This fixes a bug when libsamplerate returns an empty buffer for a very
small input buffer. The caller thinks this is an error, bug there is
no GError object.
Diffstat (limited to 'src')
-rw-r--r-- | src/pcm_buffer.c | 5 | ||||
-rw-r--r-- | src/pcm_buffer.h | 4 |
2 files changed, 9 insertions, 0 deletions
diff --git a/src/pcm_buffer.c b/src/pcm_buffer.c index b0449d44e..60a699b20 100644 --- a/src/pcm_buffer.c +++ b/src/pcm_buffer.c @@ -34,6 +34,11 @@ pcm_buffer_get(struct pcm_buffer *buffer, size_t size) { assert(buffer != NULL); + if (size == 0) + /* never return NULL, because NULL would be assumed to + be an error condition */ + size = 1; + if (buffer->size < size) { /* free the old buffer */ g_free(buffer->buffer); diff --git a/src/pcm_buffer.h b/src/pcm_buffer.h index fe223c742..b132d4fd2 100644 --- a/src/pcm_buffer.h +++ b/src/pcm_buffer.h @@ -63,6 +63,10 @@ pcm_buffer_deinit(struct pcm_buffer *buffer) /** * Get the buffer, and guarantee a minimum size. This buffer becomes * invalid with the next pcm_buffer_get() call. + * + * This function will never return NULL, even if size is zero, because + * the PCM library uses the NULL return value to signal "error". An + * empty destination buffer is not always an error. */ G_GNUC_MALLOC void * |