diff options
author | David Robillard <d@drobilla.net> | 2021-07-08 16:15:46 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2022-01-13 23:03:31 -0500 |
commit | 5c90b6aff410bb4a9737680baffd79d10b5281fd (patch) | |
tree | e6f4c94fbc1c230fb238e3c91d8dc85adc0a1dec /src/stack.h | |
parent | 00af9fa4e0344b1ff642a7ccd63626f77521ea8a (diff) | |
download | serd-5c90b6aff410bb4a9737680baffd79d10b5281fd.tar.gz serd-5c90b6aff410bb4a9737680baffd79d10b5281fd.tar.bz2 serd-5c90b6aff410bb4a9737680baffd79d10b5281fd.zip |
Use a fixed-size reader stack
Diffstat (limited to 'src/stack.h')
-rw-r--r-- | src/stack.h | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/stack.h b/src/stack.h index b49d645a..f2ab836b 100644 --- a/src/stack.h +++ b/src/stack.h @@ -66,9 +66,9 @@ 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; return ret; @@ -85,12 +85,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 size_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 |