raspberrypi / utils

A collection of scripts and simple applications
BSD 3-Clause "New" or "Revised" License
136 stars 41 forks source link

vclog: Fix uninitialised variables warning #22

Closed popcornmix closed 1 year ago

popcornmix commented 1 year ago
vcdbg.c: In function ‘find_hdr_requested_log’:
vcdbg.c:576:10: warning: ‘val’ may be used uninitialized [-Wmaybe-uninitialized]
  576 |   return correct_to_be_in_virtual_loc(toc, val);
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
vcdbg.c:555:12: note: ‘val’ was declared here
  555 |   uint32_t val;
      |            ^~~
vcdbg.c: In function ‘main’:
vcdbg.c:356:9: warning: ‘header_current_msg’ may be used uninitialized [-Wmaybe-uninitialized]
  356 |         memcpy_vc_memory(start_circular_buff + offset_of_current_read_pos,
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  357 |                          buffer_start + offset_of_current_read_pos,
      |                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  358 |                          left_in_buffer);
      |                          ~~~~~~~~~~~~~~~
vcdbg.c:283:8: note: ‘header_current_msg’ was declared here
  283 |       *header_current_msg;  /*header of first message to parse*/
      |        ^~~~~~~~~~~~~~~~~~

The first is a logic bug.

The second looks like a spurious compiler diagnostic as num_times_checked_if_new_logs = 0 and print_logs = true initially so header_current_msg will always be initialised before being used.

But initialise it to NULL to keep compiler happy

popcornmix commented 1 year ago

Ping @pelwell and @HiassofT (reporter).

pelwell commented 1 year ago

LGTM.