diff options
author | Szymon Janc <szymon.janc@tieto.com> | 2013-03-25 11:47:56 +0100 |
---|---|---|
committer | Samuel Ortiz <sameo@linux.intel.com> | 2013-03-28 16:35:37 +0100 |
commit | 74dec7c7520657ecd17067070bad37aeb98bc8f3 (patch) | |
tree | 6db68cbd6879aba0e1bebad23ad6c8ce9ebcae5e | |
parent | 28f331da1d1a4e782f17f0d5cf166ada51635143 (diff) | |
download | neard-74dec7c7520657ecd17067070bad37aeb98bc8f3.tar.gz neard-74dec7c7520657ecd17067070bad37aeb98bc8f3.tar.bz2 neard-74dec7c7520657ecd17067070bad37aeb98bc8f3.zip |
ndef: Simplify near_ndef_prepare_ac_and_cfg_records function
Make error path a bit cleaner and easier to understand. This also makes
code less confusing to some GCC version (eg. 4.6.3 on Debian ARM) about
variables mime_type and cdr being used without initialization.
make --no-print-directory all-am
CC src/ndef.o
src/ndef.c: In function ‘near_ndef_prepare_ac_and_cfg_records’:
src/ndef.c:1758:6: error: ‘mime_type’ may be used uninitialized in this
function [-Werror=uninitialized]
src/ndef.c:1781:8: note: ‘mime_type’ was declared here
src/ndef.c:1835:36: error: ‘cdr’ may be used uninitialized in this
function [-Werror=uninitialized]
cc1: all warnings being treated as errors
make[1]: *** [src/ndef.o] Error 1
make: *** [all] Error 2
-rw-r--r-- | src/ndef.c | 37 |
1 files changed, 10 insertions, 27 deletions
@@ -1776,22 +1776,16 @@ static int near_ndef_prepare_ac_and_cfg_records(enum handover_carrier carrier, struct near_ndef_mime_payload *mime, struct carrier_data *remote_carrier) { - struct carrier_data *local_carrier = NULL; + struct carrier_data *local_carrier; char cdr; char *mime_type, *carrier_string; uint16_t prop; - int err; DBG(""); if (ac == NULL || cfg == NULL) return -EINVAL; - /* to be safe side */ - *ac = NULL; - *cfg = NULL; - carrier_string = NULL; - switch (carrier) { case NEAR_CARRIER_BLUETOOTH: cdr = '0'; @@ -1818,40 +1812,29 @@ static int near_ndef_prepare_ac_and_cfg_records(enum handover_carrier carrier, case NEAR_CARRIER_EMPTY: case NEAR_CARRIER_UNKNOWN: - carrier_string = "Unknown"; - err = -EINVAL; - goto fail; + default: + return -EINVAL; } if (local_carrier == NULL) { DBG("Unable to retrieve local carrier %s data", carrier_string); - err = -ESRCH; - goto fail; + return -ESRCH; } *cfg = near_ndef_prepare_cfg_message(mime_type, local_carrier->data, local_carrier->size, cdr, 1); - if (*cfg == NULL) { - err = -ENOMEM; - goto fail; - } - *ac = near_ndef_prepare_ac_message(local_carrier->state, cdr); - if (*ac == NULL) { - err = -EINVAL; - goto fail; - } g_free(local_carrier); - return 0; + if (*cfg == NULL || *ac == NULL) { + free_ndef_message(*ac); + free_ndef_message(*cfg); -fail: - g_free(local_carrier); - free_ndef_message(*ac); - free_ndef_message(*cfg); + return -ENOMEM; + } - return err; + return 0; } static void free_ndef_list(gpointer data) |