Discussion:
[PATCH 1/2] powertop:fix return of uninitalized variable
Peter Huewe
2012-04-24 21:19:39 UTC
Permalink
If we e.g. pass pevent->last_event = NULL and pevent->nr_events = -1 to
pevent_find_event_by_name we skip all the code and return event
unitialized and set pevent->last_event to an arbitrary value, which
obviously is a bad idea.

This patch fixes this by initalizing event with NULL

Signed-off-by: Peter Huewe <peterhuewe-***@public.gmane.org>
---
pevent/parse-events.c | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/pevent/parse-events.c b/pevent/parse-events.c
index 58716e9..e1dde50 100644
--- a/pevent/parse-events.c
+++ b/pevent/parse-events.c
@@ -2917,7 +2917,7 @@ struct event_format *
pevent_find_event_by_name(struct pevent *pevent,
const char *sys, const char *name)
{
- struct event_format *event;
+ struct event_format *event = NULL;
int i;

if (pevent->last_event &&
--
1.7.3.4
Peter Huewe
2012-04-24 21:19:40 UTC
Permalink
In the current code we asign vsize=8 and then fall through to the
default and asign vsize=1. -> probably the break is missing here,
otherwise we can remove the case.

Signed-off-by: Peter Huewe <peterhuewe-***@public.gmane.org>
---
pevent/parse-events.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/pevent/parse-events.c b/pevent/parse-events.c
index e1dde50..861612e 100644
--- a/pevent/parse-events.c
+++ b/pevent/parse-events.c
@@ -3441,6 +3441,7 @@ static struct print_arg *make_bprint_args(char *fmt, void *data, int size, struc
break;
case 2:
vsize = 8;
+ break;
default:
vsize = ls; /* ? */
break;
--
1.7.3.4
Peter Hüwe
2012-05-10 21:30:22 UTC
Permalink
Post by Peter Huewe
In the current code we asign vsize=8 and then fall through to the
default and asign vsize=1. -> probably the break is missing here,
otherwise we can remove the case.
---
pevent/parse-events.c | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/pevent/parse-events.c b/pevent/parse-events.c
index e1dde50..861612e 100644
--- a/pevent/parse-events.c
+++ b/pevent/parse-events.c
@@ -3441,6 +3441,7 @@ static struct print_arg *make_bprint_args(char *fmt,
void *data, int size, struc break;
vsize = 8;
+ break;
vsize = ls; /* ? */
break;
Any reason for not picking up these two patches, or did you miss them?

Thanks,
Peter

Loading...