Commit f2696fa412299cfe9c8db53779af62eb4ffacb02

delanne 2012-11-26T12:12:41

Fix invalid read reported by valgrind

1
2
3
4
5
6
7
8
9
10
11
12
13
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);