summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <cmn@dwim.me>2015-10-30 21:36:51 +0100
committerCarlos Martín Nieto <cmn@dwim.me>2015-10-30 21:36:51 +0100
commit3547b122b57f4aafd173013d7f82e326b9cffb24 (patch)
treeb97df13d518ffe491b3ef509b68e566c048efcf7
parenteb5977991a75f8d1630348a529805ba40765a616 (diff)
downloadlibgit2-cmn/config-checksum.tar.gz
filebuf: use an internal buffercmn/config-checksum
This reduces the chances of a crash in the thread tests. This shouldn't affect general usage too much, since the main usage of these functions are to read into an empty buffer.
-rw-r--r--src/fileops.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/src/fileops.c b/src/fileops.c
index 9bef02847..cfc22bb53 100644
--- a/src/fileops.c
+++ b/src/fileops.c
@@ -153,14 +153,15 @@ int git_futils_readbuffer_fd(git_buf *buf, git_file fd, size_t len)
}
int git_futils_readbuffer_updated(
- git_buf *buf, const char *path, git_oid *checksum, int *updated)
+ git_buf *out, const char *path, git_oid *checksum, int *updated)
{
int error;
git_file fd;
struct stat st;
+ git_buf buf = GIT_BUF_INIT;
git_oid checksum_new;
- assert(buf && path && *path);
+ assert(out && path && *path);
if (updated != NULL)
*updated = 0;
@@ -182,15 +183,15 @@ int git_futils_readbuffer_updated(
if ((fd = git_futils_open_ro(path)) < 0)
return fd;
- if (git_futils_readbuffer_fd(buf, fd, (size_t)st.st_size) < 0) {
+ if (git_futils_readbuffer_fd(&buf, fd, (size_t)st.st_size) < 0) {
p_close(fd);
return -1;
}
p_close(fd);
- if ((error = git_hash_buf(&checksum_new, buf->ptr, buf->size)) < 0) {
- git_buf_free(buf);
+ if ((error = git_hash_buf(&checksum_new, buf.ptr, buf.size)) < 0) {
+ git_buf_free(&buf);
return error;
}
@@ -198,7 +199,7 @@ int git_futils_readbuffer_updated(
* If we were given a checksum, we only want to use it if it's different
*/
if (checksum && !git_oid__cmp(checksum, &checksum_new)) {
- git_buf_free(buf);
+ git_buf_free(&buf);
if (updated)
*updated = 0;
@@ -214,6 +215,9 @@ int git_futils_readbuffer_updated(
if (updated != NULL)
*updated = 1;
+ git_buf_swap(out, &buf);
+ git_buf_free(&buf);
+
return 0;
}