*/
#include <helper/log.h>
+#include <string.h>
#include "jtag_usb_common.h"
* ------
* 16 chars
*/
-#define JTAG_USB_MAX_LOCATION_LENGHT 16
+#define JTAG_USB_MAX_LOCATION_LENGTH 16
void jtag_usb_set_location(const char *location)
{
- if (strnlen(location, JTAG_USB_MAX_LOCATION_LENGHT) ==
- JTAG_USB_MAX_LOCATION_LENGHT)
+ if (strnlen(location, JTAG_USB_MAX_LOCATION_LENGTH) ==
+ JTAG_USB_MAX_LOCATION_LENGTH)
LOG_WARNING("usb location string is too long!!\n");
- if (jtag_usb_location)
- free(jtag_usb_location);
+ free(jtag_usb_location);
- jtag_usb_location = strndup(location, JTAG_USB_MAX_LOCATION_LENGHT);
+ jtag_usb_location = strndup(location, JTAG_USB_MAX_LOCATION_LENGTH);
}
const char *jtag_usb_get_location(void)
bool equal = false;
/* strtok need non const char */
- loc = strndup(jtag_usb_get_location(), JTAG_USB_MAX_LOCATION_LENGHT);
- string_length = strnlen(loc, JTAG_USB_MAX_LOCATION_LENGHT);
+ loc = strndup(jtag_usb_get_location(), JTAG_USB_MAX_LOCATION_LENGTH);
+ string_length = strnlen(loc, JTAG_USB_MAX_LOCATION_LENGTH);
ptr = strtok(loc, "-");
- if (ptr == NULL) {
+ if (!ptr) {
LOG_WARNING("no '-' in usb path\n");
goto done;
}
- string_length -= 1;
+ string_length -= strnlen(ptr, string_length);
/* check bus mismatch */
if (atoi(ptr) != dev_bus)
goto done;
ptr = strtok(NULL, ".");
/* no more tokens in path */
- if (ptr == NULL)
+ if (!ptr)
break;
/* path mismatch at some step */
break;
path_step++;
- string_length -= 2;
+ string_length -= strnlen(ptr, string_length) + 1;
};
/* walked the full path, all elements match */