libbladeRF: Addressed warning from GCC -Os in device_identifier.c

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.
This commit is contained in:
Jon Szymaniak 2016-01-04 09:12:02 -05:00
commit 8bbf917446

View file

@ -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);