diff options
Diffstat (limited to 'src/reader.h')
-rw-r--r-- | src/reader.h | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/reader.h b/src/reader.h index 302f8c6f..a98d5ef8 100644 --- a/src/reader.h +++ b/src/reader.h @@ -178,19 +178,23 @@ 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* const reader, + SerdNode* const node, + const uint8_t* const bytes, + const size_t len) { - 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]); - } + if (reader->stack.buf_size < reader->stack.size + len) { + return SERD_BAD_STACK; + } + + const size_t begin = reader->stack.size - 1U; + for (unsigned i = 0U; i < len; ++i) { + reader->stack.buf[begin + i] = (char)bytes[i]; } - return has_space ? SERD_SUCCESS : SERD_BAD_STACK; + reader->stack.size += len; + node->length += len; + return SERD_SUCCESS; } #endif // SERD_SRC_READER_H |