tools/libxg: Fix uninitialised variable in write_x86_cpu_policy_records()
authorAndrew Cooper <andrew.cooper3@citrix.com>
Thu, 11 Feb 2021 14:25:57 +0000 (14:25 +0000)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 17 Feb 2021 12:37:08 +0000 (12:37 +0000)
commit60773532231d3b6ecdc98913832ca78c3d9a4371
tree2d6b6273790fe26978ca958cb2164339f4234088
parent8e5b2029feee1961d6753127bf249c7a8c8f89a5
tools/libxg: Fix uninitialised variable in write_x86_cpu_policy_records()

Various version of gcc, when compiling with -Og, complain:

  xg_sr_common_x86.c: In function 'write_x86_cpu_policy_records':
  xg_sr_common_x86.c:92:12: error: 'rc' may be used uninitialized in this function [-Werror=maybe-uninitialized]
     92 |     return rc;
        |            ^~

The complaint is legitimate, and can occur with unexpected behaviour of two
related hypercalls in combination with a libc which permits zero-length
malloc()s.

Have an explicit rc = 0 on the success path, and make the MSRs record error
handling consistent with the CPUID record before it.

Fixes: f6b2b8ec53d ("libxc/save: Write X86_{CPUID,MSR}_DATA records")
Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Release-Acked-by: Ian Jackson <iwj@xenproject.org>
tools/libs/guest/xg_sr_common_x86.c