summaryrefslogtreecommitdiff
path: root/src/odb.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2018-03-23 09:59:46 +0000
committerPatrick Steinhardt <ps@pks.im>2018-03-23 10:06:22 +0000
commita52b4c51c0a7de341f5b2cef48ac6d7c8b9476e1 (patch)
treeaab5ab0ee9bfaeae3b6c9f36b1032aa4bb59e7fd /src/odb.c
parent904307af38a717c6dc4fd72855914e60b1930d2d (diff)
downloadlibgit2-a52b4c51c0a7de341f5b2cef48ac6d7c8b9476e1.tar.gz
odb: fix writing to fake write streams
In commit 7ec7aa4a7 (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.
Diffstat (limited to 'src/odb.c')
-rw-r--r--src/odb.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/src/odb.c b/src/odb.c
index 07206c1ac..ef9c87555 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -369,7 +369,7 @@ static int fake_wstream__write(git_odb_stream *_stream, const char *data, size_t
{
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);
stream->written += len;