libxc: initialise rc to -1 at the beginning of meminit_hvm
PATCH 1/1 libxc: initialise rc to -1 at the beginning of meminit_hvm
Variable rc is only set either inside a loop or inside some if statements. To avoid confuse gcc with stricter setting we set rc to -1 at the beginning.
---
Cc: Ian Jackson <[email protected]>
Cc: Stefano Stabellini <[email protected]>
Cc: Roger Pau Monne <[email protected]>
--- tools/libxc/xc_dom_x86.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxc/xc_dom_x86.c +1 -1
@@ -1258,7 +1258,7 @@ static int meminit_hvm(struct xc_dom_image *dom)unsigned long p2m_size;unsigned long target_pages = dom->target_pages;unsigned long cur_pages, cur_pfn; -int rc; +int rc =-1 ;xen_capabilities_info_t caps;unsigned long stat_normal_pages =0 , stat_2mb_pages =0 , stat_1gb_pages =0 ;
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Wei Liu writes ("[PATCH] libxc: initialise rc to -1 at the beginning of meminit_hvm"):
Quoted 3 lines
Variable rc is only set either inside a loop or inside some if statements. To avoid confuse gcc with stricter setting we set rc to -1 at the beginning.
Is this really the best way to fix this ?
AFAICT the problem arises only for this code:
if ( rc != 0 )
{
DOMPRINTF("Could not allocate memory for HVM guest.");
goto error_out;
}which occurs after the loop. But that path happens only if
if ( rc != 0 )
break;is executed inside the loop.
If the error case was moved into the loop, there would be no need for the separate test of rc (which is confusing to humans as well as to the compiler).
Do you agree ?
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 20 lines · Ian Jackson
Wei Liu writes ("[PATCH] libxc: initialise rc to -1 at the beginning of
meminit_hvm"):Quoted 3 lines
Variable rc is only set either inside a loop or inside some if statements. To avoid confuse gcc with stricter setting we set rc to -1 at the beginning.
Is this really the best way to fix this ?
AFAICT the problem arises only for this code:
if ( rc != 0 ) { DOMPRINTF("Could not allocate memory for HVM guest."); goto error_out; }which occurs after the loop. But that path happens only if
if ( rc != 0 ) break;
Quoted 8 lines
is executed inside the loop.
If the error case was moved into the loop, there would be no need for the separate test of rc (which is confusing to humans as well as to the compiler).
Do you agree ?
Yes, that's better.
I will send v2 shortly.
Wei.
Quoted 1 line
Ian.
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel