Skip to content

Commit 5db3e69

Browse files
committed
vclog: Fix uninitialised variables warning
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
1 parent d01de85 commit 5db3e69

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

vclog/vcdbg.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ int32_t main(int32_t argc, char *argv[]) {
280280
true; /*Set to true at first and changes at the end of the loop depending
281281
on whether the user decided to keep checking for new messages */
282282
const Individual_msg_hdr_t
283-
*header_current_msg; /*header of first message to parse*/
283+
*header_current_msg = NULL; /*header of first message to parse*/
284284
const size_t size_of_msg_header =
285285
sizeof(Individual_msg_hdr_t); /*Individual messages each have headers that
286286
are always the same size, which we will
@@ -567,7 +567,7 @@ static VC_region_requested_hdr_t *find_hdr_requested_log(
567567
val = toc->virtual->ptr_log_msg;
568568
break;
569569
default:
570-
break;
570+
return NULL;
571571
}
572572

573573
/*This pointer is currently pointing to the physical memory of VC :

0 commit comments

Comments
 (0)