linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hciemu: Always initialize status in hci_host_control
@ 2012-02-27 12:03 Szymon Janc
  2012-02-27 17:20 ` Marcel Holtmann
  0 siblings, 1 reply; 2+ messages in thread
From: Szymon Janc @ 2012-02-27 12:03 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: kanak.gupta, Szymon Janc

Assign 0x00 to status on intialization instead of assigning it in each
switch case. This helps to avoid errors when one forget to proper
intialize status in new case.

This fix following compilation error:

  CC     test/hciemu.o
cc1: warnings being treated as errors
test/hciemu.c: In function ‘hci_host_control’:
test/hciemu.c:786: error: ‘status’ may be used uninitialized in this function
make[1]: *** [test/hciemu.o] Error 1
---
 test/hciemu.c |   14 +-------------
 1 files changed, 1 insertions(+), 13 deletions(-)

diff --git a/test/hciemu.c b/test/hciemu.c
index ffe04f8..69e21f5 100644
--- a/test/hciemu.c
+++ b/test/hciemu.c
@@ -662,24 +662,21 @@ static void hci_host_control(uint16_t ocf, int plen, uint8_t *data)
 	read_ext_inquiry_response_rp ir;
 	read_simple_pairing_mode_rp pm;
 	read_le_host_supported_rp hs;
-	uint8_t status;
+	uint8_t status = 0x00;
 
 	const uint16_t ogf = OGF_HOST_CTL;
 
 	switch (ocf) {
 	case OCF_RESET:
-		status = 0x00;
 		reset_vdev();
 		command_complete(ogf, ocf, 1, &status);
 		break;
 
 	case OCF_SET_EVENT_FLT:
-		status = 0x00;
 		command_complete(ogf, ocf, 1, &status);
 		break;
 
 	case OCF_CHANGE_LOCAL_NAME:
-		status = 0x00;
 		memcpy(vdev.name, data, sizeof(vdev.name));
 		command_complete(ogf, ocf, 1, &status);
 		break;
@@ -692,7 +689,6 @@ static void hci_host_control(uint16_t ocf, int plen, uint8_t *data)
 
 	case OCF_WRITE_CONN_ACCEPT_TIMEOUT:
 	case OCF_WRITE_PAGE_TIMEOUT:
-		status = 0x00;
 		command_complete(ogf, ocf, 1, &status);
 		break;
 
@@ -703,18 +699,15 @@ static void hci_host_control(uint16_t ocf, int plen, uint8_t *data)
 		break;
 
 	case OCF_WRITE_SCAN_ENABLE:
-		status = 0x00;
 		vdev.scan_enable = scan_enable(data);
 		command_complete(ogf, ocf, 1, &status);
 		break;
 
 	case OCF_WRITE_AUTH_ENABLE:
-		status = 0x00;
 		command_complete(ogf, ocf, 1, &status);
 		break;
 
 	case OCF_WRITE_ENCRYPT_MODE:
-		status = 0x00;
 		command_complete(ogf, ocf, 1, &status);
 		break;
 
@@ -725,7 +718,6 @@ static void hci_host_control(uint16_t ocf, int plen, uint8_t *data)
 		break;
 
 	case OCF_WRITE_CLASS_OF_DEV:
-		status = 0x00;
 		memcpy(vdev.dev_class, data, 3);
 		command_complete(ogf, ocf, 1, &status);
 		break;
@@ -737,7 +729,6 @@ static void hci_host_control(uint16_t ocf, int plen, uint8_t *data)
 		break;
 
 	case OCF_WRITE_INQUIRY_MODE:
-		status = 0x00;
 		vdev.inq_mode = data[0];
 		command_complete(ogf, ocf, 1, &status);
 		break;
@@ -750,7 +741,6 @@ static void hci_host_control(uint16_t ocf, int plen, uint8_t *data)
 		break;
 
 	case OCF_WRITE_EXT_INQUIRY_RESPONSE:
-		status = 0x00;
 		vdev.eir_fec = data[0];
 		memcpy(vdev.eir_data, data + 1, HCI_MAX_EIR_LENGTH);
 		command_complete(ogf, ocf, 1, &status);
@@ -763,7 +753,6 @@ static void hci_host_control(uint16_t ocf, int plen, uint8_t *data)
 		break;
 
 	case OCF_WRITE_SIMPLE_PAIRING_MODE:
-		status = 0x00;
 		vdev.ssp_mode = data[0];
 		command_complete(ogf, ocf, 1, &status);
 		break;
@@ -776,7 +765,6 @@ static void hci_host_control(uint16_t ocf, int plen, uint8_t *data)
 		break;
 
 	case OCF_WRITE_LE_HOST_SUPPORTED:
-		status = 0x00;
 		vdev.le_mode = data[0];
 		vdev.le_simul = data[1];
 		command_complete(ogf, ocf, 1, &status);
-- 
on behalf of ST-Ericsson


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] hciemu: Always initialize status in hci_host_control
  2012-02-27 12:03 [PATCH] hciemu: Always initialize status in hci_host_control Szymon Janc
@ 2012-02-27 17:20 ` Marcel Holtmann
  0 siblings, 0 replies; 2+ messages in thread
From: Marcel Holtmann @ 2012-02-27 17:20 UTC (permalink / raw)
  To: Szymon Janc; +Cc: linux-bluetooth, kanak.gupta

Hi Szymon,

> Assign 0x00 to status on intialization instead of assigning it in each
> switch case. This helps to avoid errors when one forget to proper
> intialize status in new case.
> 
> This fix following compilation error:
> 
>   CC     test/hciemu.o
> cc1: warnings being treated as errors
> test/hciemu.c: In function ‘hci_host_control’:
> test/hciemu.c:786: error: ‘status’ may be used uninitialized in this function
> make[1]: *** [test/hciemu.o] Error 1

actually gcc warns here rightfully, but the fix is actually a different
one:

@@ -783,7 +783,7 @@ static void hci_host_control(uint16_t ocf, int plen, uint8_t
                break;
 
        default:
-               command_status(ogf, ocf, status);
+               command_status(ogf, ocf, 0x01);
                break;
        }

Pushed that one upstream.

I am always suspicious if the fix to a compiler warning like this is
just to initialize the variable. We prefer not to do that since then it
starts hiding real bugs. This is a good example.

Regards

Marcel



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-02-27 17:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-02-27 12:03 [PATCH] hciemu: Always initialize status in hci_host_control Szymon Janc
2012-02-27 17:20 ` Marcel Holtmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).