Skip to contentSkip to conversation

libxl: fix unitialized variables in libxl__primary_console_find

PATCH In review Olaf Hering 2 participants 5 messages Jul 4, 2012 – Jul 30, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libxl: fix unitialized variables in libxl__primary_console_find

# HG changeset patch
# User Olaf Hering <[email protected]>
# Date 1341404234 -7200
# Node ID 5668cb98eebb0a27530c8b52f3ae8cce87d3b863
# Parent 42f76d536b116d2ebad1b6705ae51ecd171d2581
libxl: fix unitialized variables in libxl__primary_console_find

gcc 4.5 as shipped with openSuSE 11.4 does not recognize the case of LIBXL_DOMAIN_TYPE_INVALID properly:

cc1: warnings being treated as errors
libxl.c: In function 'libxl_primary_console_exec':
libxl.c:1408:14: error: 'domid' may be used uninitialized in this function libxl.c:1409:9: error: 'cons_num' may be used uninitialized in this function libxl.c:1410:24: error: 'type' may be used uninitialized in this function libxl.c: In function 'libxl_primary_console_get_tty':
libxl.c:1421:14: error: 'domid' may be used uninitialized in this function libxl.c:1422:9: error: 'cons_num' may be used uninitialized in this function libxl.c:1423:24: error: 'type' may be used uninitialized in this function make[3]: *** [libxl.o] Error 1

Fix this by adding a default case.

tools/libxl/libxl.c +1 -0
diff -r 42f76d536b11 -r 5668cb98eebb tools/libxl/libxl.c
@@ -1392,6 +1392,7 @@ static int libxl__primary_console_find(l
             *type = LIBXL_CONSOLE_TYPE_PV;
             break;
         case LIBXL_DOMAIN_TYPE_INVALID:
+        default:
             rc = ERROR_INVAL;
             goto out;
         }
#1 lore raw
Quoted 6 lines · Olaf Hering

# HG changeset patch
# User Olaf Hering <[email protected]>
# Date 1341404234 -7200
# Node ID 5668cb98eebb0a27530c8b52f3ae8cce87d3b863
# Parent 42f76d536b116d2ebad1b6705ae51ecd171d2581
libxl: fix unitialized variables in libxl__primary_console_find

Olaf,

I have a vague recollection of some discussion of this and a different fix but I can't actually find any such discussion and the patch is still in my queue. Is this still needed?

Quoted 2 lines

gcc 4.5 as shipped with openSuSE 11.4 does not recognize the case of LIBXL_DOMAIN_TYPE_INVALID properly:

That's kind of lame of gcc...

I wonder if default: abort() might be more appropriate (I'm not sure what our policy here ended up being).

Quoted 31 lines

cc1: warnings being treated as errors
libxl.c: In function 'libxl_primary_console_exec':
libxl.c:1408:14: error: 'domid' may be used uninitialized in this function libxl.c:1409:9: error: 'cons_num' may be used uninitialized in this function libxl.c:1410:24: error: 'type' may be used uninitialized in this function libxl.c: In function 'libxl_primary_console_get_tty':
libxl.c:1421:14: error: 'domid' may be used uninitialized in this function libxl.c:1422:9: error: 'cons_num' may be used uninitialized in this function libxl.c:1423:24: error: 'type' may be used uninitialized in this function make[3]: *** [libxl.o] Error 1

Fix this by adding a default case.

diff -r 42f76d536b11 -r 5668cb98eebb tools/libxl/libxl.c

tools/libxl/libxl.c +1 -0
@@ -1392,6 +1392,7 @@ static int libxl__primary_console_find(l
             *type = LIBXL_CONSOLE_TYPE_PV;
             break;
         case LIBXL_DOMAIN_TYPE_INVALID:
+        default:
             rc = ERROR_INVAL;
             goto out;
         }

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

#2 lore raw
Quoted 8 lines · Ian Campbell
Quoted 6 lines · Olaf Hering

# HG changeset patch
# User Olaf Hering <[email protected]>
# Date 1341404234 -7200
# Node ID 5668cb98eebb0a27530c8b52f3ae8cce87d3b863
# Parent 42f76d536b116d2ebad1b6705ae51ecd171d2581
libxl: fix unitialized variables in libxl__primary_console_find

Quoted 5 lines

Olaf,

I have a vague recollection of some discussion of this and a different fix but I can't actually find any such discussion and the patch is still in my queue. Is this still needed?

Yes.

Quoted 7 lines
Quoted 2 lines

gcc 4.5 as shipped with openSuSE 11.4 does not recognize the case of LIBXL_DOMAIN_TYPE_INVALID properly:

That's kind of lame of gcc...

I wonder if default: abort() might be more appropriate (I'm not sure what our policy here ended up being).

libxl__domain_type is a simple and internal function. Perhaps a comment about why a 'default' case exists is enough.

Olaf

#3 lore raw
Quoted 21 lines · Olaf Hering
Quoted 8 lines · Ian Campbell
Quoted 6 lines · Olaf Hering

# HG changeset patch
# User Olaf Hering <[email protected]>
# Date 1341404234 -7200
# Node ID 5668cb98eebb0a27530c8b52f3ae8cce87d3b863
# Parent 42f76d536b116d2ebad1b6705ae51ecd171d2581
libxl: fix unitialized variables in libxl__primary_console_find

Quoted 5 lines

Olaf,

I have a vague recollection of some discussion of this and a different fix but I can't actually find any such discussion and the patch is still in my queue. Is this still needed?

Yes.

Quoted 3 lines
Quoted 2 lines

gcc 4.5 as shipped with openSuSE 11.4 does not recognize the case of LIBXL_DOMAIN_TYPE_INVALID properly:

Quoted 7 lines
Quoted 4 lines

That's kind of lame of gcc...

I wonder if default: abort() might be more appropriate (I'm not sure what our policy here ended up being).

libxl__domain_type is a simple and internal function. Perhaps a comment about why a 'default' case exists is enough.

I think we've mostly been considering that the "abort()" is in itself enough documentation that this should never happen.

Ian.

#4 lore raw
Quoted 2 lines · Ian Campbell

I think we've mostly been considering that the "abort()" is in itself enough documentation that this should never happen.

I have posted a patch which does that. Other places in that file have the same 'default: abort();' already.

Olaf