[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [bug-patch] [PATCH] avoid a used-uninitialized error
From: |
Jim Meyering |
Subject: |
Re: [bug-patch] [PATCH] avoid a used-uninitialized error |
Date: |
Wed, 25 May 2011 16:48:59 +0200 |
Andreas Gruenbacher wrote:
> On Tuesday 24 May 2011 13:15:37 Jim Meyering wrote:
>> I did not try to see if fixing this bug changes how patch works.
>
> It doesn't as far as I can see. It doesn't fix a real bug either, but avoids
> a static checker error (so it's a good thing). I'd rather initialize stamp
> completely at the top of the function though, like this:
>
> diff --git a/src/util.c b/src/util.c
> index 6950842..75486f4 100644
> --- a/src/util.c
> +++ b/src/util.c
> @@ -1428,6 +1428,7 @@ fetchname (char const *at, int strip_leading, bool
> maybe_quoted, char **pname,
> struct timespec stamp;
>
> stamp.tv_sec = -1;
> + stamp.tv_nsec = 0;
>
> while (ISSPACE ((unsigned char) *at))
> at++;
> @@ -1497,9 +1498,7 @@ fetchname (char const *at, int strip_leading, bool
> maybe_quoted, char **pname,
> timestr[u - t] = 0;
> }
>
> - if (*t == '\n')
> - stamp.tv_sec = -1;
> - else
> + if (*t != '\n')
Ok. I prefer that, too.
Thanks for the reviews.
>From b4c6b7086bd496bbc5b15de657247919a143e3b2 Mon Sep 17 00:00:00 2001
From: Andreas Gruenbacher <address@hidden>
Date: Tue, 24 May 2011 12:11:32 +0200
Subject: [PATCH] avoid a used-uninitialized error in fetchname
* src/util.c (fetchname): Avoid a used-uninitialized error.
Before, when "*t == '\n'", stamp.tv_nsec would have been
used undefined. The fix is to set that member rather than
stamp.tv_sec, which is already set to the desired value.
This was reported by coverity.
---
src/util.c | 5 ++---
1 files changed, 2 insertions(+), 3 deletions(-)
diff --git a/src/util.c b/src/util.c
index 6950842..75486f4 100644
--- a/src/util.c
+++ b/src/util.c
@@ -1428,6 +1428,7 @@ fetchname (char const *at, int strip_leading, bool
maybe_quoted, char **pname,
struct timespec stamp;
stamp.tv_sec = -1;
+ stamp.tv_nsec = 0;
while (ISSPACE ((unsigned char) *at))
at++;
@@ -1497,9 +1498,7 @@ fetchname (char const *at, int strip_leading, bool
maybe_quoted, char **pname,
timestr[u - t] = 0;
}
- if (*t == '\n')
- stamp.tv_sec = -1;
- else
+ if (*t != '\n')
{
if (! pstamp)
{
--
1.7.5.2.609.g6dbbf