tools/libxl: Fix build following c/s c3c8da9
PATCH 1/1 tools/libxl: Fix build following c/s c3c8da9
c/s c3c8da9 "libxl: ao: datacopier callback gets an rc" caused libxl__domain_save_device_model() to pass its rc directly into the callback.
However in the preexisting code, there were 3 "goto out;" paths which left rc uninitialised, which is cause by GCC 4.8's -Wmaybe-uninitialized
--- tools/libxl/libxl_dom.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/libxl/libxl_dom.c +1 -1
@@ -2147,7 +2147,7 @@ void libxl__domain_save_device_model(libxl__egc *egc,STATE_AO_GC (dss->ao);struct stat st;uint32_t qemu_state_len; -int rc; +int rc =-1 ; dss->save_dm_callback = callback;
Signature · 1 line
1.7.10.4
Andrew Cooper writes ("[PATCH] tools/libxl: Fix build following c/s c3c8da9"):
Quoted 5 lines
c/s c3c8da9 "libxl: ao: datacopier callback gets an rc" caused
libxl__domain_save_device_model()to pass its rc directly into the callback.However in the preexisting code, there were 3 "goto out;" paths which left rc uninitialised, which is cause by GCC 4.8's -Wmaybe-uninitialized
The solution is not to initialise rc (to a bogus value) but to fix the goto out paths to explicitly set rc.
Can you easily confirm that this fixes it ?
Ian.
tools/libxl/libxl_dom.c +3 -0
@@ -2190,17 +2190,20 @@ void libxl__domain_save_device_model(libxl__egc *egc, dc->readfd =open (filename,O_RDONLY );if (dc->readfd <0 ) {LOGE (ERROR ,"unable to open %s" , dc->readwhat); + rc =ERROR_FAIL ; goto out; }if (fstat (dc->readfd, &st)) {LOGE (ERROR ,"unable to fstat %s" , dc->readwhat); + rc =ERROR_FAIL ; goto out; }if (!S_ISREG (st.st_mode)) {LOG (ERROR ,"%s is not a plain file!" , dc->readwhat); + rc =ERROR_FAIL ; goto out; }
Quoted 10 lines · Ian Jackson
Andrew Cooper writes ("[PATCH]
tools/libxl: Fix build following c/s c3c8da9"):Quoted 5 lines
c/s c3c8da9 "libxl: ao: datacopier callback gets an rc" caused
libxl__domain_save_device_model()to pass its rc directly into the callback.However in the preexisting code, there were 3 "goto out;" paths which left rc uninitialised, which is cause by GCC 4.8's -Wmaybe-uninitialized
The solution is not to initialise rc (to a bogus value) but to fix the goto out paths to explicitly set rc.
Can you easily confirm that this fixes it ?
It does indeed. Tested-by: Andrew Cooper <[email protected]>
However, the problem with this style is that it is subverted by:
rc = libxl__datacopier_start(dc);
if (rc) goto out;
out of context below, which cases rc to be initialised on all subsequent error paths, and thus miss further issues where it is set incorrectly.
I would suggest introducing another int to hold the temporary from libxl__datacopier_start().
~Andrew
Quoted 28 lines
Ian.
tools/libxl/libxl_dom.c +3
-0@@ -2190,17 +2190,20 @@ void libxl__domain_save_device_model(libxl__egc *egc, dc->readfd =open (filename,O_RDONLY );if (dc->readfd <0 ) {LOGE (ERROR ,"unable to open %s" , dc->readwhat); + rc =ERROR_FAIL ; goto out; }if (fstat (dc->readfd, &st)) {LOGE (ERROR ,"unable to fstat %s" , dc->readwhat); + rc =ERROR_FAIL ; goto out; }if (!S_ISREG (st.st_mode)) {LOG (ERROR ,"%s is not a plain file!" , dc->readwhat); + rc =ERROR_FAIL ; goto out; }
Andrew Cooper writes ("Re: [PATCH] tools/libxl: Fix build following c/s c3c8da9"):
Quoted 5 lines · Ian Jackson
Quoted 1 line
Can you easily confirm that this fixes it ?
It does indeed. Tested-by: Andrew Cooper <[email protected]>
Quoted 7 lines
However, the problem with this style is that it is subverted by:
rc =
libxl__datacopier_start(dc);
if (rc) goto out;out of context below, which cases rc to be initialised on all subsequent error paths, and thus miss further issues where it is set incorrectly.
Yes, I agree that this is less than ideal. It means that not all such uninitialised rc's will be found, but ...
Quoted 2 lines
I would suggest introducing another int to hold the temporary from
libxl__datacopier_start().
... this would be quite inconvenient.
The right answer IMO is to replace the idiom
rc = some_function(...); if (rc) goto out;
with a macro invocation
CHECKING_RC( some_function(...) );
and maybe have a `goto out' macro, too
GOTO_OUT_RC(FAIL);
But I'm not sure my co-maintainers agree.
Anyway, thanks for the tested-by. I will make a proper commit message etc. and apply my patch.
Ian.
PATCH 1/1 libxl: Fix uninitialised rc in libxl__domain_save_device_model
c3c8da9 "libxl: ao: datacopier callback gets an rc" caused libxl__domain_save_device_model() to pass its rc directly into the callback.
However in the preexisting code, there were 3 "goto out;" paths which left rc uninitialised. This causes a build failure with GCC 4.8's -Wmaybe-uninitialized.
Set the rc explicitly on each goto out path.
--- tools/libxl/libxl_dom.c | 3 +++ 1 file changed, 3 insertions(+)
tools/libxl/libxl_dom.c +3 -0
@@ -2190,17 +2190,20 @@ void libxl__domain_save_device_model(libxl__egc *egc, dc->readfd =open (filename,O_RDONLY );if (dc->readfd <0 ) {LOGE (ERROR ,"unable to open %s" , dc->readwhat); + rc =ERROR_FAIL ; goto out; }if (fstat (dc->readfd, &st)) {LOGE (ERROR ,"unable to fstat %s" , dc->readwhat); + rc =ERROR_FAIL ; goto out; }if (!S_ISREG (st.st_mode)) {LOG (ERROR ,"%s is not a plain file!" , dc->readwhat); + rc =ERROR_FAIL ; goto out; }
Signature · 1 line
1.7.10.4