Commit 1e9b7a09ff3d16c3d7a132cfaacb9d68b253e924

Vicent Martí 2011-06-02T15:12:37

Merge pull request #144 from nordsturm/fix_fakewstream Fix fake wstream write

diff --git a/src/blob.c b/src/blob.c
index 75eda44..6ab58d6 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -64,7 +64,10 @@ int git_blob_create_frombuffer(git_oid *oid, git_repository *repo, const void *b
 	if ((error = git_odb_open_wstream(&stream, repo->db, len, GIT_OBJ_BLOB)) < GIT_SUCCESS)
 		return git__rethrow(error, "Failed to create blob");
 
-	stream->write(stream, buffer, len);
+	if ((error = stream->write(stream, buffer, len)) < GIT_SUCCESS) {
+		stream->free(stream);
+		return error;
+	}
 
 	error = stream->finalize_write(oid, stream);
 	stream->free(stream);
diff --git a/src/odb.c b/src/odb.c
index 080dfa2..1f3848f 100644
--- a/src/odb.c
+++ b/src/odb.c
@@ -170,7 +170,7 @@ static int fake_wstream__write(git_odb_stream *_stream, const char *data, size_t
 {
 	fake_wstream *stream = (fake_wstream *)_stream;
 
-	if (stream->written + len >= stream->size)
+	if (stream->written + len > stream->size)
 		return GIT_ENOMEM;
 
 	memcpy(stream->buffer + stream->written, data, len);