Skip to content

Commit

Permalink
[PATCH] Fix alloc_filespec() initialization
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Linus Torvalds authored and Junio C Hamano committed Sep 14, 2005
1 parent c80522e commit 705a714
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,10 @@ struct diff_filespec *alloc_filespec(const char *path)
{
int namelen = strlen(path);
struct diff_filespec *spec = xmalloc(sizeof(*spec) + namelen + 1);

memset(spec, 0, sizeof(*spec));
spec->path = (char *)(spec + 1);
strcpy(spec->path, path);
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);
memcpy(spec->path, path, namelen+1);
return spec;
}

Expand Down

0 comments on commit 705a714

Please sign in to comment.