Workaround gcc -Wmaybe-uninitialised false positive reports
cover Workaround gcc -Wmaybe-uninitialised false positive reports
On my Debian Jessie build box gcc complains about various maybe uninitialised variables when -g is in use. In fact gcc -Wmaybe-uninitialized is not very reliable according to gcc manpage, various search results and answer from someone on freenode #gcc channel.
I go through those failures and try to provide some workaround for them. Please have a look if these fixes make sense or my analysis is correct.
Wei.
Wei Liu (6):
rombios/tcgbios: initialise size in tcpa_extend_acpi_log rombios/tcgbios: initialise entry in HashLogEvent32 rombios/tcgbios: initialise logdataptr in HashLogEvent32
blktap2: initialise buf in vhd_util_check_footer
blktap2: initialise buf to NULL in img2qcow.c:main
blktap2: initialise buf in qcow2raw.c:main
tools/blktap2/drivers/img2qcow.c | 2 +- tools/blktap2/drivers/qcow2raw.c | 2 +- tools/blktap2/vhd/lib/vhd-util-check.c | 2 +- tools/firmware/rombios/32bit/tcgbios/tcgbios.c | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-)
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH 1/6 rombios/tcgbios: initialise size in tcpa_extend_acpi_log
Gcc complains:
tcgbios.c:362:3: error: ‘size’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
memcpy((char *)lasa_last, (char *)entry_ptr, size);
It fails to figure out if size is used in memcpy it is always initialised.
--- tools/firmware/rombios/32bit/tcgbios/tcgbios.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/firmware/rombios/32bit/tcgbios/tcgbios.c +1 -1
@@ -330,7 +330,7 @@ uint32_t tcpa_extend_acpi_log(uint32_t entry_ptr)uint32_t res =0 ;unsigned char *lasa_last =tcpa_get_lasa_last_ptr ();unsigned char *lasa_base =tcpa_get_lasa_base_ptr (); -uint32_t size; +uint32_t size =0 ;uint16_t entry_count = tcpa_acpi.entry_count;struct pcpes *pcpes = (struct pcpes *)entry_ptr;
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH 2/6 rombios/tcgbios: initialise entry in HashLogEvent32
In reply to Wei LiuGcc complains:
tcgbios.c:1142:22: error: ‘entry’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
hleo->eventnumber = entry;
It fails to figure out if entry is used it is always initialised in previous if block.
--- tools/firmware/rombios/32bit/tcgbios/tcgbios.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/firmware/rombios/32bit/tcgbios/tcgbios.c +1 -1
@@ -1100,7 +1100,7 @@ uint32_t HashLogEvent32(struct hlei *hlei, struct hleo *hleo, }if (rc ==0 ) { -uint32_t entry; +uint32_t entry =0 ; hashdataptr = hlei->hashdataptr; hashdatalen = hlei->hashdatalen;
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH 3/6 rombios/tcgbios: initialise logdataptr in HashLogEvent32
In reply to Wei LiuGcc complains:
tcgbios.c: In function ‘HashLogEvent32’:
tcgbios.c:1131:10: error: ‘logdataptr’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
entry = tcpa_extend_acpi_log(logdataptr);
It fails to figure out when logdataptr is used it is always initialised in a if block a few line above.
--- tools/firmware/rombios/32bit/tcgbios/tcgbios.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/firmware/rombios/32bit/tcgbios/tcgbios.c +1 -1
@@ -1062,7 +1062,7 @@ uint32_t HashLogEvent32(struct hlei *hlei, struct hleo *hleo, {uint32_t rc =0 ;uint16_t size; -uint32_t logdataptr; +uint32_t logdataptr =0 ;uint32_t logdatalen;uint32_t hashdataptr;uint32_t hashdatalen;
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH 4/6 blktap2: initialise buf in vhd_util_check_footer
In reply to Wei LiuGcc complains:
vhd-util-check.c: In function ‘vhd_util_check_footer’:
vhd-util-check.c:413:2: error: ‘buf’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
memcpy(&backup, buf, sizeof(backup));
In fact buf is initialised a few lines above.
---
I can't figure out why buf may be uninitialised and this seems to be the only way to convince gcc it is ok to proceed.
--- tools/blktap2/vhd/lib/vhd-util-check.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/blktap2/vhd/lib/vhd-util-check.c +1 -1
@@ -335,7 +335,7 @@ vhd_util_check_footer(int fd, vhd_footer_t *footer, int ignore) {size_t size;int err, opened; -char *msg, *buf; +char *msg, *buf =NULL ;off_t eof, off;vhd_footer_t primary, backup;
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH 5/6 blktap2: initialise buf to NULL in img2qcow.c:main
In reply to Wei LiuGcc complains:
qcow2raw.c: In function ‘main’:
qcow2raw.c:387:17: error: ‘buf’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
treq.buf = buf;
^But at the point of that assignment, buf is a valid buffer allocated by posix_memalign and filled in by read.
--- tools/blktap2/drivers/img2qcow.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/blktap2/drivers/img2qcow.c +1 -1
@@ -166,7 +166,7 @@ int main(int argc, const char *argv[])int ret =-1 , fd, len, err;struct timeval timeout;uint64_t i; -char *buf; +char *buf =NULL ;td_request_t treq;td_disk_info_t info;td_vbd_request_t * vreq;
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
PATCH 6/6 blktap2: initialise buf in qcow2raw.c:main
In reply to Wei LiuGcc complains:
qcow2raw.c: In function ‘main’:
qcow2raw.c:387:17: error: ‘buf’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
treq.buf = buf;
^But buf is a valid buffer allocated by posix_memalign at that point.
--- tools/blktap2/drivers/qcow2raw.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/blktap2/drivers/qcow2raw.c +1 -1
@@ -202,7 +202,7 @@ int main(int argc, const char *argv[])uint64_t size;struct timeval timeout;uint64_t i; -char *buf; +char *buf =NULL ;struct stat finfo;td_request_t treq;td_vbd_request_t * vreq;
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] http://lists.xen.org/xen-devel
Quoted 10 lines · Wei Liu
On my Debian Jessie build box gcc complains about various maybe uninitialised variables when -g is in use. In fact gcc -Wmaybe-uninitialized is not very reliable according to gcc manpage, various search results and answer from someone on freenode #gcc channel.
I go through those failures and try to provide some workaround for them. Please have a look if these fixes make sense or my analysis is correct.
Wei.
Quoted 8 lines
Wei Liu (6):
rombios/tcgbios: initialise size intcpa_extend_acpi_logrombios/tcgbios: initialise entry in HashLogEvent32 rombios/tcgbios: initialise logdataptr in HashLogEvent32
blktap2: initialise buf invhd_util_check_footer
blktap2: initialise buf to NULL in img2qcow.c:main
blktap2: initialise buf in qcow2raw.c:main
Ping?
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 18 lines · Wei Liu
On my Debian Jessie build box gcc complains about various maybe uninitialised variables when -g is in use. In fact gcc -Wmaybe-uninitialized is not very reliable according to gcc manpage, various search results and answer from someone on freenode #gcc channel.
I go through those failures and try to provide some workaround for them. Please have a look if these fixes make sense or my analysis is correct.
Wei.
Wei Liu (6):
rombios/tcgbios: initialise size intcpa_extend_acpi_logrombios/tcgbios: initialise entry in HashLogEvent32 rombios/tcgbios: initialise logdataptr in HashLogEvent32
blktap2: initialise buf invhd_util_check_footer
blktap2: initialise buf to NULL in img2qcow.c:main
blktap2: initialise buf in qcow2raw.c:main
Quoted 6 lines
tools/blktap2/drivers/img2qcow.c | 2 +- tools/blktap2/drivers/qcow2raw.c | 2 +- tools/blktap2/vhd/lib/vhd-util-check.c | 2 +- tools/firmware/rombios/32bit/tcgbios/tcgbios.c | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-)
For the whole series:
Signature · 1 line
Doug Goldstein
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 26 lines · Doug Goldstein
Quoted 18 lines · Wei Liu
On my Debian Jessie build box gcc complains about various maybe uninitialised variables when -g is in use. In fact gcc -Wmaybe-uninitialized is not very reliable according to gcc manpage, various search results and answer from someone on freenode #gcc channel.
I go through those failures and try to provide some workaround for them. Please have a look if these fixes make sense or my analysis is correct.
Wei.
Wei Liu (6):
rombios/tcgbios: initialise size intcpa_extend_acpi_logrombios/tcgbios: initialise entry in HashLogEvent32 rombios/tcgbios: initialise logdataptr in HashLogEvent32
blktap2: initialise buf invhd_util_check_footer
blktap2: initialise buf to NULL in img2qcow.c:main
blktap2: initialise buf in qcow2raw.c:mainQuoted 6 lines
tools/blktap2/drivers/img2qcow.c | 2 +- tools/blktap2/drivers/qcow2raw.c | 2 +- tools/blktap2/vhd/lib/vhd-util-check.c | 2 +- tools/firmware/rombios/32bit/tcgbios/tcgbios.c | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-)
Quoted 4 lines
For the whole series:
Reviewed-by Doug Goldstein <[email protected]>
Thanks.
I chatted with Ian on IRC he said he didn't quite like this approach but didn't have better suggestion so I should go ahead.
I've queued this series up for committing.
Wei.
Quoted 3 lines
Signature · 1 line
Doug Goldstein
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel