kvmtool / kvmtool

Stand-alone Native Linux KVM Tool repo

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

‘value’may be used uninitialized in this function `kbd_io`

hburaylee opened this issue · comments

When build with gcc (GCC) 8.4.1, i got a error

hw/i8042.c: In function ‘kbd_io’:
hw/i8042.c:153:19: error: ‘value’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
   state.write_cmd = val;
   ~~~~~~~~~~~~~~~~^~~~~
hw/i8042.c:298:5: note: ‘value’ was declared here
  u8 value;
     ^~~~~
cc1: all warnings being treated as errors

I meet the same error as you, Have you address it ?

in function kbd_io(), when is_write is false, value won't be initialized,
so set a default value when define it, then every thing will be ok

static void kbd_io(struct kvm_cpu *vcpu, u64 addr, u8 *data, u32 len,
		   u8 is_write, void *ptr)
{
	u8 value = 0 ;  //set default value
	if (is_write)
		value = ioport__read8(data);

	switch (addr) {
	case I8042_COMMAND_REG:
		if (is_write)
			kbd_write_command(vcpu->kvm, value);
		else
			value = kbd_read_status();
		break;
    ....

@chennbnbnb Thank you, it works.

@xinying2 This info is helpful, thanks.

@chennbnbnb please, create a pull request.

Hi @leitao , I found this issue was not updated for a few days, and maybe other guys will encounter the issue when they try to use kvmtools for their developing or studying. Could you please review the above pr when convenient. Thanks.