[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>
This commit is contained in:
Linus Torvalds 2005-09-14 13:41:24 -07:00 committed by Junio C Hamano
parent c80522e30f
commit 705a7148ba

10
diff.c
View File

@ -214,14 +214,10 @@ struct diff_filespec *alloc_filespec(const char *path)
{ {
int namelen = strlen(path); int namelen = strlen(path);
struct diff_filespec *spec = xmalloc(sizeof(*spec) + namelen + 1); struct diff_filespec *spec = xmalloc(sizeof(*spec) + namelen + 1);
memset(spec, 0, sizeof(*spec));
spec->path = (char *)(spec + 1); spec->path = (char *)(spec + 1);
strcpy(spec->path, path); memcpy(spec->path, path, namelen+1);
spec->should_free = spec->should_munmap = 0;
spec->xfrm_flags = 0;
spec->size = 0;
spec->data = NULL;
spec->mode = 0;
memset(spec->sha1, 0, 20);
return spec; return spec;
} }