Skip to contentSkip to conversation

] libxl/arm: Fix ARM build.

PATCH Superseded Andrii Anisov 3 participants 6 messages May 16, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ] libxl/arm: Fix ARM build.

From: Andrii Anisov <[email protected]>

Some compilers do not (validly?) detect that size will always be initialized when (rc > 0), so implicitly initialize it.

---
 tools/libxl/libxl_arm_acpi.c | 2 ++
 1 file changed, 2 insertions(+)
tools/libxl/libxl_arm_acpi.c +2 -0
index db113db..f61aec6 100644
@@ -73,6 +73,8 @@ static int libxl__estimate_madt_size(libxl__gc *gc,
 {
     int rc = 0;
 
+    *size = 0;
+
     switch (info->arch_arm.gic_version) {
     case LIBXL_GIC_VERSION_V2:
         *size = sizeof(struct acpi_table_madt) +
Signature · 7 lines
2.7.4


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#1 lore raw

CC Ian Jakson and Wei Liu as maintainers.

Sincerely,
Andrii Anisov.

2017-05-16 13:23 GMT+03:00 Andrii Anisov <[email protected]>:

Quoted 24 lines

From: Andrii Anisov <[email protected]>

Some compilers do not (validly?) detect that size will always be initialized when (rc > 0), so implicitly initialize it.

---
 tools/libxl/libxl_arm_acpi.c | 2 ++
 1 file changed, 2 insertions(+)
tools/libxl/libxl_arm_acpi.c +2 -1
index db113db..f61aec6 100644
@@ -73,6 +73,8 @@ static int libxl__estimate_madt_size(libxl__gc *gc,
 {
     int rc = 0;
 
+    *size = 0;
+
     switch (info->arch_arm.gic_version) {
     case LIBXL_GIC_VERSION_V2:
         *size = sizeof(struct acpi_table_madt) +
--
Quoted 3 lines

2.7.4

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#2 lore raw
Quoted 12 lines · Andrii Anisov

CC Ian Jakson and Wei Liu as maintainers.

Sincerely,
Andrii Anisov.

2017-05-16 13:23 GMT+03:00 Andrii Anisov <[email protected]>:

Quoted 5 lines

From: Andrii Anisov <[email protected]>

Some compilers do not (validly?) detect that size will always be initialized when (rc > 0), so implicitly initialize it.

I'm confused by the commit message.

When rc > 0 (the default branch), size is not initialised. I guess that's what gcc complains about?

If I'm right, would it be better to set *size to 0 in the default branch?

Quoted 13 lines
Quoted 13 lines
---
 tools/libxl/libxl_arm_acpi.c | 2 ++
 1 file changed, 2 insertions(+)
tools/libxl/libxl_arm_acpi.c +0 -0
index db113db..f61aec6 100644
@@ -73,6 +73,8 @@ static int libxl__estimate_madt_size(libxl__gc *gc,
 {
     int rc = 0;
 
Quoted 9 lines
Quoted 9 lines
tools/libxl/libxl_arm_acpi.c +2 -1
+    *size = 0;
+
     switch (info->arch_arm.gic_version) {
     case LIBXL_GIC_VERSION_V2:
         *size = sizeof(struct acpi_table_madt) +
--

2.7.4

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#3 lore raw
Quoted 10 lines · Wei Liu
Quoted 9 lines · Andrii Anisov

CC Ian Jakson and Wei Liu as maintainers.

Sincerely,
Andrii Anisov.

2017-05-16 13:23 GMT+03:00 Andrii Anisov <[email protected]>:

Quoted 2 lines

From: Andrii Anisov <[email protected]>

Quoted 7 lines
Quoted 3 lines
Quoted 3 lines

Some compilers do not (validly?) detect that size will always be initialized when (rc > 0), so implicitly initialize it.

I'm confused by the commit message.

When rc > 0 (the default branch), size is not initialised. I guess

Also rc can't be >0 because ERROR_* is negative...

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

#4 lore raw
In reply to Wei Liu

Dear Wei,

Quoted 1 line · Wei Liu

I'm confused by the commit message.

My bad, I did not pay enough attention to write the message. Would following be better?

Implicitly initialize a referenced ouput parameter for all code
branches
in order to not face a "variable may be used uninitialized"
compilation
error in a caller function, fired by some compilers under
circumstances.

Quoted 2 lines

If I'm right, would it be better to set *size to 0 in the default branch?

Agree.

Signature · 8 lines
*Andrii Anisov*



_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
#5 lore raw
Quoted 9 lines · Andrii Anisov

Dear Wei,

Quoted 1 line · Wei Liu

I'm confused by the commit message.

My bad, I did not pay enough attention to write the message. Would following be better?

Quoted 9 lines

Implicitly initialize a referenced ouput parameter for all code branches in order to not face a "variable may be used uninitialized" compilation error in a caller function, fired by some compilers under circumstances.

Quoted 2 lines

If I'm right, would it be better to set *size to 0 in the default branch?

Agree.

I suspect if you take this approach the commit message you proposed doesn't quite match either.

Just say:

Initialise *size in default branch to prevent certain compilers (which ones?) from reporting "variable may be used uninitialized" errors in caller function.

Quoted 10 lines
Signature · 8 lines
*Andrii Anisov*



_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel