Merge pull request #1105 from delanne/invalid_read_config_file Fix invalid read reported by valgrind
diff --git a/src/config_file.c b/src/config_file.c
index 232dcc4..1209c53 100644
--- a/src/config_file.c
+++ b/src/config_file.c
@@ -1220,7 +1220,7 @@ static int config_write(diskfile_backend *cfg, const char *key, const regex_t *p
}
/* If we are here, there is at least a section line */
- if (*(cfg->reader.buffer.ptr + cfg->reader.buffer.size - 1) != '\n')
+ if (cfg->reader.buffer.size > 0 && *(cfg->reader.buffer.ptr + cfg->reader.buffer.size - 1) != '\n')
git_filebuf_write(&file, "\n", 1);
git_filebuf_printf(&file, "\t%s = %s\n", name, value);