Re: [PATCH] tools lib traceevent: Fix compile warnings in tools/lib/traceevent/event-parse.c

From: Arnaldo Carvalho de Melo
Date: Tue Nov 27 2018 - 07:36:01 EST


Em Thu, Nov 22, 2018 at 01:29:37PM +0200, Adrian Hunter escreveu:
> Fix following warnings:

Steven, any problem if I apply these? I think I've hit these warnings on
Clear Linux too.

- Arnaldo

> event-parse.c: In function âtep_find_event_by_nameâ:
> event-parse.c:3521:21: warning: âeventâ may be used uninitialized in this function [-Wmaybe-uninitialized]
> pevent->last_event = event;
> ~~~~~~~~~~~~~~~~~~~^~~~~~~
> CC ui/gtk/hists.o
> LINK plugin_mac80211.so
> CC nlattr.o
> event-parse.c: In function âtep_data_lat_fmtâ:
> event-parse.c:5200:4: warning: âmigrate_disableâ may be used uninitialized in this function [-Wmaybe-uninitialized]
> trace_seq_printf(s, "%d", migrate_disable);
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> event-parse.c:5207:4: warning: âlock_depthâ may be used uninitialized in this function [-Wmaybe-uninitialized]
> trace_seq_printf(s, "%d", lock_depth);
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> LINK plugin_sched_switch.so
> LINK plugin_function.so
> LINK plugin_xen.so
> event-parse.c: In function âtep_event_infoâ:
> event-parse.c:5047:7: warning: âlen_argâ may be used uninitialized in this function [-Wmaybe-uninitialized]
> trace_seq_printf(s, format, len_arg, (char)val);
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> event-parse.c:4884:6: note: âlen_argâ was declared here
> int len_arg;
> ^~~~~~~
> event-parse.c:4338:11: warning: âvsizeâ may be used uninitialized in this function [-Wmaybe-uninitialized]
> val = tep_read_number(pevent, bptr, vsize);
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> event-parse.c:4224:6: note: âvsizeâ was declared here
> int vsize;
> ^~~~~
>
> $ gcc --version
> gcc (Clear Linux OS for Intel Architecture) 8.2.1 20180502
>
> Signed-off-by: Adrian Hunter <adrian.hunter@xxxxxxxxx>
> ---
> tools/lib/traceevent/event-parse.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
> index 3692f29fee46..fbd6d6813fab 100644
> --- a/tools/lib/traceevent/event-parse.c
> +++ b/tools/lib/traceevent/event-parse.c
> @@ -3498,7 +3498,7 @@ struct tep_event_format *
> tep_find_event_by_name(struct tep_handle *pevent,
> const char *sys, const char *name)
> {
> - struct tep_event_format *event;
> + struct tep_event_format *event = NULL;
> int i;
>
> if (pevent->last_event &&
> @@ -4221,7 +4221,7 @@ static struct tep_print_arg *make_bprint_args(char *fmt, void *data, int size, s
> unsigned long long ip, val;
> char *ptr;
> void *bptr;
> - int vsize;
> + int vsize = 0;
>
> field = pevent->bprint_buf_field;
> ip_field = pevent->bprint_ip_field;
> @@ -4881,7 +4881,7 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct tep_e
> char format[32];
> int show_func;
> int len_as_arg;
> - int len_arg;
> + int len_arg = 0;
> int len;
> int ls;
>
> @@ -5146,8 +5146,8 @@ void tep_data_lat_fmt(struct tep_handle *pevent,
> static int migrate_disable_exists;
> unsigned int lat_flags;
> unsigned int pc;
> - int lock_depth;
> - int migrate_disable;
> + int lock_depth = 0;
> + int migrate_disable = 0;
> int hardirq;
> int softirq;
> void *data = record->data;
> --
> 2.17.1

--

- Arnaldo