aboutsummaryrefslogtreecommitdiffstats
path: root/src/stack.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-05-12 20:39:23 +0200
committerDavid Robillard <d@drobilla.net>2018-05-27 21:10:21 +0200
commitc4b5d8a5f6973952b510ebd321cbac8aa5fb5267 (patch)
treec4b80c9b612f3f6bb8eb2561da9cd26f826579cb /src/stack.h
parent582bfbe1cb0a6aa833f56c5bd8cf42abe5c5d13a (diff)
downloadserd-c4b5d8a5f6973952b510ebd321cbac8aa5fb5267.tar.gz
serd-c4b5d8a5f6973952b510ebd321cbac8aa5fb5267.tar.bz2
serd-c4b5d8a5f6973952b510ebd321cbac8aa5fb5267.zip
Use fixed size stack
Diffstat (limited to 'src/stack.h')
-rw-r--r--src/stack.h11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/stack.h b/src/stack.h
index 122b3b14..3848af66 100644
--- a/src/stack.h
+++ b/src/stack.h
@@ -61,8 +61,7 @@ serd_stack_push(SerdStack* stack, size_t n_bytes)
{
const size_t new_size = stack->size + n_bytes;
if (stack->buf_size < new_size) {
- stack->buf_size += (stack->buf_size >> 1); // *= 1.5
- stack->buf = (char*)realloc(stack->buf, stack->buf_size);
+ return NULL;
}
char* const ret = (stack->buf + stack->size);
stack->size = new_size;
@@ -80,12 +79,16 @@ static inline void*
serd_stack_push_aligned(SerdStack* stack, size_t n_bytes, size_t align)
{
// Push one byte to ensure space for a pad count
- serd_stack_push(stack, 1);
+ if (!serd_stack_push(stack, 1)) {
+ return NULL;
+ }
// Push padding if necessary
const uint8_t pad = align - stack->size % align;
if (pad > 0) {
- serd_stack_push(stack, pad);
+ if (!serd_stack_push(stack, pad)) {
+ return NULL;
+ }
}
// Set top of stack to pad count so we can properly pop later