diff options
author | David Robillard <d@drobilla.net> | 2018-11-11 15:29:59 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-06-21 18:12:04 +0200 |
commit | 5a83b1fcda6b091c224b1f1681ea7357ac805c92 (patch) | |
tree | 158669681821037f1a94375d7b3a7ec648921ee2 | |
parent | 8dec5c9b7663478c89e58dd64e47422d60a92ecb (diff) | |
download | serd-5a83b1fcda6b091c224b1f1681ea7357ac805c92.tar.gz serd-5a83b1fcda6b091c224b1f1681ea7357ac805c92.tar.bz2 serd-5a83b1fcda6b091c224b1f1681ea7357ac805c92.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 869ac21d..ad07f601 100644 --- a/src/reader.h +++ b/src/reader.h @@ -167,16 +167,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 |