Commit 07067f8b authored by Max Kellermann's avatar Max Kellermann

pcm_buffer: add assertions

parent a1e824ad
...@@ -32,6 +32,8 @@ align_8k(size_t size) ...@@ -32,6 +32,8 @@ align_8k(size_t size)
void * void *
pcm_buffer_get(struct pcm_buffer *buffer, size_t size) pcm_buffer_get(struct pcm_buffer *buffer, size_t size)
{ {
assert(buffer != NULL);
if (buffer->size < size) { if (buffer->size < size) {
/* free the old buffer */ /* free the old buffer */
g_free(buffer->buffer); g_free(buffer->buffer);
...@@ -40,5 +42,7 @@ pcm_buffer_get(struct pcm_buffer *buffer, size_t size) ...@@ -40,5 +42,7 @@ pcm_buffer_get(struct pcm_buffer *buffer, size_t size)
buffer->buffer = g_malloc(buffer->size); buffer->buffer = g_malloc(buffer->size);
} }
assert(buffer->size >= size);
return buffer->buffer; return buffer->buffer;
} }
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#include <glib.h> #include <glib.h>
#include <assert.h>
/** /**
* Manager for a temporary buffer which grows as needed. We could * Manager for a temporary buffer which grows as needed. We could
* allocate a new buffer every time pcm_convert() is called, but that * allocate a new buffer every time pcm_convert() is called, but that
...@@ -39,6 +41,8 @@ struct pcm_buffer { ...@@ -39,6 +41,8 @@ struct pcm_buffer {
static inline void static inline void
pcm_buffer_init(struct pcm_buffer *buffer) pcm_buffer_init(struct pcm_buffer *buffer)
{ {
assert(buffer != NULL);
buffer->buffer = NULL; buffer->buffer = NULL;
buffer->size = 0; buffer->size = 0;
} }
...@@ -49,6 +53,8 @@ pcm_buffer_init(struct pcm_buffer *buffer) ...@@ -49,6 +53,8 @@ pcm_buffer_init(struct pcm_buffer *buffer)
static inline void static inline void
pcm_buffer_deinit(struct pcm_buffer *buffer) pcm_buffer_deinit(struct pcm_buffer *buffer)
{ {
assert(buffer != NULL);
g_free(buffer->buffer); g_free(buffer->buffer);
buffer->buffer = NULL; buffer->buffer = NULL;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment