X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fjtag%2Fdrivers%2Fjtag_usb_common.c;h=309f8c462fbca818a4656e400d7a2027c234502a;hb=a5471b1b2c5675fa0caa462e742916c54f9a08e2;hp=a0fa0586502e86643368499016ab7358a5479b7f;hpb=9655da5aede7927b18bd9ae92a9fe310b76a99de;p=fw%2Fopenocd diff --git a/src/jtag/drivers/jtag_usb_common.c b/src/jtag/drivers/jtag_usb_common.c index a0fa05865..309f8c462 100644 --- a/src/jtag/drivers/jtag_usb_common.c +++ b/src/jtag/drivers/jtag_usb_common.c @@ -15,18 +15,17 @@ static char *jtag_usb_location; * ------ * 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) @@ -42,8 +41,8 @@ bool jtag_usb_location_equal(uint8_t dev_bus, uint8_t *port_path, 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) { @@ -51,7 +50,7 @@ bool jtag_usb_location_equal(uint8_t dev_bus, uint8_t *port_path, goto done; } - string_length -= 1; + string_length -= strnlen(ptr, string_length); /* check bus mismatch */ if (atoi(ptr) != dev_bus) goto done; @@ -69,7 +68,7 @@ bool jtag_usb_location_equal(uint8_t dev_bus, uint8_t *port_path, break; path_step++; - string_length -= 2; + string_length -= strnlen(ptr, string_length) + 1; }; /* walked the full path, all elements match */