[PATCH] Fix alloc_filespec() initialization
This simplifies and fixes the initialization of a "diff_filespec" when allocated. The old code would not initialize "sha1_valid". Noticed by valgrind. Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Linus Torvalds committed
Sep 14, 2005 at 13:41 UTC
705a7148ba1bb9597b1837b7f64a0dcb67f1ad0c
1 file changed
+3
-7
diff.c
+3
-7
@@ -214,14 +214,10 @@ struct diff_filespec *alloc_filespec(const char *path)
214
{
215
int namelen = strlen(path);
216
struct diff_filespec *spec = xmalloc(sizeof(*spec) + namelen + 1);
217
+
218
+ memset(spec, 0, sizeof(*spec));
219
spec->path = (char *)(spec + 1);
218
- strcpy(spec->path, path);
219
- spec->should_free = spec->should_munmap = 0;
220
- spec->xfrm_flags = 0;
221
- spec->size = 0;
222
- spec->data = NULL;
223
- spec->mode = 0;
224
- memset(spec->sha1, 0, 20);
220
+ memcpy(spec->path, path, namelen+1);
221
return spec;
222
}
223