Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/in.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ ly_in_memory(struct ly_in *in, const char *str)

LY_CHECK_ARG_RET(NULL, in, in->type == LY_IN_MEMORY, NULL);

data = in->current;
data = in->start;

if (str) {
in->start = in->current = str;
Expand All @@ -240,7 +240,7 @@ ly_in_memory_chunk(struct ly_in *in, const void *mem, uint32_t mem_len)

LY_CHECK_ARG_RET(NULL, in, in->type == LY_IN_MEMORY, NULL);

data = in->current;
data = in->start;

if (mem) {
in->start = in->current = mem;
Expand Down
14 changes: 13 additions & 1 deletion tests/utests/basic/test_inout.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ static void
test_input_mem(void **UNUSED(state))
{
struct ly_in *in = NULL;
char *str1 = "a", *str2 = "b";
char *str1 = "a", *str2 = "b", *str3 = "abc";
char buf[2];

assert_int_equal(LY_EINVAL, ly_in_new_memory(NULL, NULL));
CHECK_LOG_LASTMSG("Invalid argument str (ly_in_new_memory()).");
Expand All @@ -95,6 +96,17 @@ test_input_mem(void **UNUSED(state))
assert_ptr_equal(str2, ly_in_memory(in, NULL));
assert_ptr_equal(str2, ly_in_memory(in, NULL));
ly_in_free(in, 0);

/* the previous start address is returned also after some data were read */
assert_int_equal(LY_SUCCESS, ly_in_new_memory(str3, &in));
assert_int_equal(LY_SUCCESS, ly_in_read(in, buf, 2));
assert_ptr_equal(str3, ly_in_memory(in, str1));
ly_in_free(in, 0);

assert_int_equal(LY_SUCCESS, ly_in_new_memory_chunk(str3, 3, &in));
assert_int_equal(LY_SUCCESS, ly_in_read(in, buf, 2));
assert_ptr_equal(str3, ly_in_memory_chunk(in, str1, 1));
ly_in_free(in, 0);
}

static void
Expand Down