From 8bbf91744625f4a86aa478c97d30122b00f3a3fe Mon Sep 17 00:00:00 2001 From: Jon Szymaniak Date: Mon, 4 Jan 2016 09:12:02 -0500 Subject: [PATCH] libbladeRF: Addressed warning from GCC -Os in device_identifier.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only seeing this warning with GCC - haven't observed this with Clang or Coverity scans. host/libraries/libbladeRF/src/device_identifier.c:121:22: error: ‘val’ may be used uninitialized in this function [-Werror=maybe-uninitialized] value[i] = tolower((unsigned char) c); ^ host/libraries/libbladeRF/src/device_identifier.c:175:34: note: ‘val’ was declared here char *dev_id, *token, *arg, *val, *saveptr; ^ Addressing this by initializing ptrs to NULL and status variables to BLADERF_ERR_UNEXPECTED. Added NULL pointer checks. --- .../libbladeRF/src/device_identifier.c | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/host/libraries/libbladeRF/src/device_identifier.c b/host/libraries/libbladeRF/src/device_identifier.c index b841c65d..ad957f46 100644 --- a/host/libraries/libbladeRF/src/device_identifier.c +++ b/host/libraries/libbladeRF/src/device_identifier.c @@ -92,6 +92,10 @@ static int handle_instance(struct bladerf_devinfo *d, char *value) { bool ok; + if (value == NULL) { + return BLADERF_ERR_INVAL; + } + d->instance = str2uint(value, 0, DEVINFO_INST_ANY - 1, &ok); if (!ok) { log_debug("Bad instance: %s\n", value); @@ -106,8 +110,13 @@ static int handle_serial(struct bladerf_devinfo *d, char *value) { char c; size_t i; - const size_t len = strlen(value); + size_t len; + if (value == NULL) { + return BLADERF_ERR_INVAL; + } + + len = strlen(value); if (len > (BLADERF_SERIAL_LENGTH - 1)) { log_debug("Provided serial # string too long: %"PRIu64"\n", (uint64_t) len); @@ -157,6 +166,7 @@ static int next_arg(char **saveptr, char **arg, char **value) *arg = strtok_r(token, "=", &saveptr_local); if (!*arg) { + *value = NULL; return BLADERF_ERR_INVAL; } @@ -172,8 +182,13 @@ static int next_arg(char **saveptr, char **arg, char **value) int str2devinfo(const char *dev_id_const, struct bladerf_devinfo *d) { - char *dev_id, *token, *arg, *val, *saveptr; - int status, arg_status; + char *dev_id = NULL; + char *token = NULL; + char *arg = NULL; + char *val = NULL; + char *saveptr = NULL; + int status = BLADERF_ERR_UNEXPECTED; + int arg_status = BLADERF_ERR_UNEXPECTED; assert(d);