Skip to content

Commit

Permalink
usb.c: change a cast that was causing a problem on MSVC.
Browse files Browse the repository at this point in the history
I guess doing a '(long) UINT_MAX' was causing a problem with MSVC, so
remove that.

A usb 'bus' can only be uint8_t, so if it is larger than that - fail.

Signed-off-by: Robin Getz <[email protected]>
  • Loading branch information
rgetz committed Jun 2, 2020
1 parent 0f943c8 commit 7657cef
Showing 1 changed file with 3 additions and 9 deletions.
12 changes: 3 additions & 9 deletions usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ struct iio_context * usb_create_context_from_uri(const char *uri)

errno = 0;
bus = strtol(ptr, &end, 10);
if (ptr == end || *end != '.' || errno == ERANGE)
if (ptr == end || *end != '.' || errno == ERANGE || bus < 0 || bus > UINT8_MAX)
goto err_bad_uri;

ptr = (const char *) ((uintptr_t) end + 1);
Expand All @@ -1140,7 +1140,7 @@ struct iio_context * usb_create_context_from_uri(const char *uri)

errno = 0;
address = strtol(ptr, &end, 10);
if (ptr == end || errno == ERANGE)
if (ptr == end || errno == ERANGE || address < 0 || address > UINT8_MAX)
goto err_bad_uri;

if (*end == '\0') {
Expand All @@ -1152,18 +1152,12 @@ struct iio_context * usb_create_context_from_uri(const char *uri)

errno = 0;
intrfc = strtol(ptr, &end, 10);
if (ptr == end || *end != '\0' || errno == ERANGE)
if (ptr == end || *end != '\0' || errno == ERANGE || intrfc < 0 || intrfc > UINT8_MAX)
goto err_bad_uri;
} else {
goto err_bad_uri;
}

if (bus < 0 || address < 0 || intrfc < 0)
goto err_bad_uri;

if (bus > (long) UINT_MAX || address > UINT8_MAX || intrfc > UINT8_MAX)
goto err_bad_uri;

if (scan) {
iio_context_info_list_free(info);
iio_scan_context_destroy(scan_ctx);
Expand Down

0 comments on commit 7657cef

Please sign in to comment.