diff options
author | Chris Dickens <christopher.a.dickens@gmail.com> | 2016-01-27 01:00:55 -0800 |
---|---|---|
committer | Chris Dickens <christopher.a.dickens@gmail.com> | 2016-01-27 01:02:02 -0800 |
commit | fc721ede3e901fd8f25d2cc904a924384cd23d5f (patch) | |
tree | 6c0925c9be6ec827a436f1a993b2a244e48469f8 | |
parent | 7de6c0f28186824ec04a33703ec079ed451c437d (diff) | |
download | libusb-fc721ede3e901fd8f25d2cc904a924384cd23d5f.tar.gz |
Windows: Replace open-coded string alloc + copy with _strdup()
Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
-rw-r--r-- | libusb/os/windows_nt_common.c | 3 | ||||
-rw-r--r-- | libusb/os/windows_winusb.c | 9 | ||||
-rw-r--r-- | libusb/version_nano.h | 2 |
3 files changed, 5 insertions, 9 deletions
diff --git a/libusb/os/windows_nt_common.c b/libusb/os/windows_nt_common.c index 8972865..9a4f854 100644 --- a/libusb/os/windows_nt_common.c +++ b/libusb/os/windows_nt_common.c @@ -267,13 +267,12 @@ unsigned long htab_hash(const char *str) // string (same hash, different string) at the same time is extremely low safe_free(htab_table[idx].str); htab_table[idx].used = hval; - htab_table[idx].str = malloc(safe_strlen(str) + 1); + htab_table[idx].str = _strdup(str); if (htab_table[idx].str == NULL) { usbi_err(NULL, "could not duplicate string for hash table"); usbi_mutex_unlock(&htab_write_mutex); return 0; } - memcpy(htab_table[idx].str, str, safe_strlen(str) + 1); ++htab_filled; usbi_mutex_unlock(&htab_write_mutex); diff --git a/libusb/os/windows_winusb.c b/libusb/os/windows_winusb.c index c6afb14..8670be7 100644 --- a/libusb/os/windows_winusb.c +++ b/libusb/os/windows_winusb.c @@ -549,11 +549,10 @@ static int get_sub_api(char *driver, int api) if (len == 0) return SUB_API_NOTSET; - tmp_str = calloc(1, len + 1); + tmp_str = _strdup(driver); if (tmp_str == NULL) return SUB_API_NOTSET; - memcpy(tmp_str, driver, len + 1); tok = strtok(tmp_str, sep_str); while (tok != NULL) { for (i = 0; i < usb_api_backend[api].nb_driver_names; i++) { @@ -1548,10 +1547,8 @@ static int windows_get_device_list(struct libusb_context *ctx, struct discovered break; default: // For other devices, the first interface is the same as the device - priv->usb_interface[0].path = calloc(1, safe_strlen(priv->path)); - if (priv->usb_interface[0].path != NULL) - safe_strcpy(priv->usb_interface[0].path, safe_strlen(priv->path) + 1, priv->path); - else + priv->usb_interface[0].path = _strdup(priv->path); + if (priv->usb_interface[0].path == NULL) usbi_warn(ctx, "could not duplicate interface path '%s'", priv->path); // The following is needed if we want API calls to work for both simple // and composite devices. diff --git a/libusb/version_nano.h b/libusb/version_nano.h index dfcc7c5..ca4d099 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 11037 +#define LIBUSB_NANO 11038 |