Commit a52b4c51 by Patrick Steinhardt

odb: fix writing to fake write streams

In commit 7ec7aa4a (odb: assert on logic errors when writing objects,
2018-02-01), the check for whether we are trying to overflowing the fake
stream buffer was changed from returning an error to raising an assert.
The conversion forgot though that the logic around `assert`s are
basically inverted. Previously, if the statement

    stream->written + len > steram->size

evaluated to true, we would return a `-1`. Now we are asserting that
this statement is true, and in case it is not we will raise an error. So
the conversion to the `assert` in fact changed the behaviour to the
complete opposite intention.

Fix the assert by inverting its condition again and add a regression
test.
parent 904307af
...@@ -369,7 +369,7 @@ static int fake_wstream__write(git_odb_stream *_stream, const char *data, size_t ...@@ -369,7 +369,7 @@ static int fake_wstream__write(git_odb_stream *_stream, const char *data, size_t
{ {
fake_wstream *stream = (fake_wstream *)_stream; fake_wstream *stream = (fake_wstream *)_stream;
assert(stream->written + len > stream->size); assert(stream->written + len <= stream->size);
memcpy(stream->buffer + stream->written, data, len); memcpy(stream->buffer + stream->written, data, len);
stream->written += len; stream->written += len;
......
...@@ -50,3 +50,11 @@ void test_odb_backend_mempack__exists_with_existing_objects_succeeds(void) ...@@ -50,3 +50,11 @@ void test_odb_backend_mempack__exists_with_existing_objects_succeeds(void)
cl_git_pass(git_odb_write(&_oid, _odb, data, strlen(data) + 1, GIT_OBJ_BLOB)); cl_git_pass(git_odb_write(&_oid, _odb, data, strlen(data) + 1, GIT_OBJ_BLOB));
cl_assert(git_odb_exists(_odb, &_oid) == 1); cl_assert(git_odb_exists(_odb, &_oid) == 1);
} }
void test_odb_backend_mempack__blob_create_frombuffer_succeeds(void)
{
const char *data = "data";
cl_git_pass(git_blob_create_frombuffer(&_oid, _repo, data, strlen(data) + 1));
cl_assert(git_odb_exists(_odb, &_oid) == 1);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment