diff options
author | David Robillard <d@drobilla.net> | 2018-11-11 15:29:59 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-10-27 13:13:58 +0100 |
commit | b3069ee3a97d7c15ce391655b74fa166248c6394 (patch) | |
tree | d55ac8ebe958d2434b2edd6eb2d08ea82680629a | |
parent | 8f1a097f5140155804109154cc4b660efd21f3f0 (diff) | |
download | serd-b3069ee3a97d7c15ce391655b74fa166248c6394.tar.gz serd-b3069ee3a97d7c15ce391655b74fa166248c6394.tar.bz2 serd-b3069ee3a97d7c15ce391655b74fa166248c6394.zip |
Simplify reader stack pushing code
-rw-r--r-- | src/reader.h | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/src/reader.h b/src/reader.h index f19038f8..7d911cb4 100644 --- a/src/reader.h +++ b/src/reader.h @@ -159,16 +159,18 @@ push_byte(SerdReader* reader, SerdNode* node, const int c) } static inline SerdStatus -push_bytes(SerdReader* reader, SerdNode* ref, const uint8_t* bytes, unsigned len) +push_bytes(SerdReader* reader, + SerdNode* ref, + const uint8_t* bytes, + unsigned len) { - if (reader->stack.buf_size < reader->stack.size + len) { - return SERD_ERR_OVERFLOW; - } - - for (unsigned i = 0; i < len; ++i) { - push_byte(reader, ref, bytes[i]); + const bool has_space = reader->stack.buf_size >= reader->stack.size + len; + if (has_space) { + for (unsigned i = 0; i < len; ++i) { + push_byte(reader, ref, bytes[i]); + } } - return SERD_SUCCESS; + return has_space ? SERD_SUCCESS : SERD_ERR_OVERFLOW; } #endif // SERD_READER_H |