diff options
author | David Robillard <d@drobilla.net> | 2018-11-11 15:29:59 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2019-12-19 20:55:41 -0500 |
commit | 1caa335dfe89da0a4d3190d02b133f34fb68ec74 (patch) | |
tree | dd5e36a273a330b509aa4f744abd4f351ad33015 /src | |
parent | aec6a5355d36123b4cb100a5b77c9a7e2c3d1d84 (diff) | |
download | serd-1caa335dfe89da0a4d3190d02b133f34fb68ec74.tar.gz serd-1caa335dfe89da0a4d3190d02b133f34fb68ec74.tar.bz2 serd-1caa335dfe89da0a4d3190d02b133f34fb68ec74.zip |
Simplify reader stack pushing code
Diffstat (limited to 'src')
-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 20bc7b91..9f087d7e 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 |