gdb: initialize the data_head variable to eliminate compilation warnings
authorEnze Li <enze.li@hotmail.com>
Sat, 11 Jun 2022 10:36:48 +0000 (18:36 +0800)
committerEnze Li <enze.li@hotmail.com>
Fri, 8 Jul 2022 13:48:15 +0000 (21:48 +0800)
On a machine with gcc 12, I get this warning:

  CXX    nat/linux-btrace.o
In function ‘btrace_error linux_read_bts(btrace_data_bts*, btrace_target_info*, btrace_read_type)’,
    inlined from ‘btrace_error linux_read_btrace(btrace_data*, btrace_target_info*, btrace_read_type)’ at ../gdb/nat/linux-btrace.c:935:29:
../gdb/nat/linux-btrace.c:865:21: warning: ‘data_head’ may be used uninitialized [-Wmaybe-uninitialized]
  865 |   pevent->last_head = data_head;
      |   ~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
../gdb/nat/linux-btrace.c: In function ‘btrace_error linux_read_btrace(btrace_data*, btrace_target_info*, btrace_read_type)’:
../gdb/nat/linux-btrace.c:792:9: note: ‘data_head’ was declared here
  792 |   __u64 data_head, data_tail;
      |         ^~~~~~~~~

Fix this by initializing the 'data_head' variable.

Tested by rebuilding on x86_64 openSUSE Tumbleweed with gcc 12.

gdb/nat/linux-btrace.c

index b0d6dcd7cf16c5e3cf0b7b720a4191cbc006abe5..c31fb5ffe43fc16fe441a5bed7e2fce28e6c6786 100644 (file)
@@ -789,7 +789,7 @@ linux_read_bts (struct btrace_data_bts *btrace,
   struct perf_event_buffer *pevent;
   const uint8_t *begin, *end, *start;
   size_t buffer_size, size;
-  __u64 data_head, data_tail;
+  __u64 data_head = 0, data_tail;
   unsigned int retries = 5;
 
   pevent = &tinfo->variant.bts.bts;