threads / patch / 17536

patchdelete_ref(): fix uninitialized value, found by valgrind

Subject: [PATCH] delete_ref(): fix uninitialized value, found by valgrind

## tl;dr

3 messages between Feb 3, 2009 and Feb 4, 2009. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Johannes Schindelin· Feb 3, 2009, 18:12 UTC · lore
The variable 'err' was not necessarily initialized before it was used.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 refs.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
Show changes to refs.c +1 −1
diff --git a/refs.c b/refs.c
index b13e01b..ded7ec4 100644
--- a/refs.c
+++ b/refs.c
@@ -929,7 +929,7 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,
 int delete_ref(const char *refname, const unsigned char *sha1, int delopt)
 {
 	struct ref_lock *lock;
-	int err, i = 0, ret = 0, flag = 0;
+	int err = 0, i = 0, ret = 0, flag = 0;
 	struct stat loginfo;
 	int log = !lstat(git_path("logs/%s", refname), &loginfo);
 
-- 
1.6.1.2.574.g140d5
Junio C Hamano· Feb 4, 2009, 06:00 UTC · re: Johannes Schindelin · lore

Re: [PATCH] delete_ref(): fix uninitialized value, found by valgrind

Johannes Schindelin <johannes.schindelin@gmx.de> writes:
Show 19 quoted lines
> The variable 'err' was not necessarily initialized before it was used.
>
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> ---
>  refs.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/refs.c b/refs.c
> index b13e01b..ded7ec4 100644
> --- a/refs.c
> +++ b/refs.c
> @@ -929,7 +929,7 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,
>  int delete_ref(const char *refname, const unsigned char *sha1, int delopt)
>  {
>  	struct ref_lock *lock;
> -	int err, i = 0, ret = 0, flag = 0;
> +	int err = 0, i = 0, ret = 0, flag = 0;
>  	struct stat loginfo;
>  	int log = !lstat(git_path("logs/%s", refname), &loginfo);
Sorry, I do not see it.
There are two uses of "err" in this function, both of which looks like:
	if (err && errno != ENOENT)
but both of these places have
	err = unlink(...)
immediately before it.
Johannes Schindelin· Feb 4, 2009, 09:57 UTC · re: Junio C Hamano · lore

Re: [PATCH] delete_ref(): fix uninitialized value, found by valgrind

Hi,
On Tue, 3 Feb 2009, Junio C Hamano wrote:
Show 33 quoted lines
> Johannes Schindelin <johannes.schindelin@gmx.de> writes:
> 
> > The variable 'err' was not necessarily initialized before it was used.
> >
> > Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> > ---
> >  refs.c |    2 +-
> >  1 files changed, 1 insertions(+), 1 deletions(-)
> >
> > diff --git a/refs.c b/refs.c
> > index b13e01b..ded7ec4 100644
> > --- a/refs.c
> > +++ b/refs.c
> > @@ -929,7 +929,7 @@ static int log_ref_write(const char *ref_name, const unsigned char *old_sha1,
> >  int delete_ref(const char *refname, const unsigned char *sha1, int delopt)
> >  {
> >  	struct ref_lock *lock;
> > -	int err, i = 0, ret = 0, flag = 0;
> > +	int err = 0, i = 0, ret = 0, flag = 0;
> >  	struct stat loginfo;
> >  	int log = !lstat(git_path("logs/%s", refname), &loginfo);
> 
> Sorry, I do not see it.
> 
> There are two uses of "err" in this function, both of which looks like:
> 
> 	if (err && errno != ENOENT)
> 
> but both of these places have
> 
> 	err = unlink(...)
> 
> immediately before it.

I should know better by now than to base my work on the tip of my Git tree. Sure enough I have an attempt at resolving the "deleting a branch deletes its reflog, too" issue, which has that bug.

Sorry for the noise, Dscho

← back to recent threads