Skip to content

Commit

Permalink
descriptor: Fix addition overflow by correcting casts
Browse files Browse the repository at this point in the history
The addition could overflow, the upcast needs to be performed before,
not after.

Fixes all clang-tidy bugprone-misplaced-widening-cast warnings

References libusb#1479
  • Loading branch information
seanm authored and tormodvolden committed Jul 28, 2024
1 parent e3ccc46 commit 55f8c95
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 3 deletions.
1 change: 0 additions & 1 deletion .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ Checks: "-*,\
boost-*,\
bugprone-*,\
-bugprone-easily-swappable-parameters,\
-bugprone-misplaced-widening-cast,\
-bugprone-narrowing-conversions,\
-bugprone-signed-char-misuse,\
-bugprone-switch-missing-default-case,\
Expand Down
2 changes: 1 addition & 1 deletion libusb/descriptor.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ static int parse_configuration(struct libusb_context *ctx,
ptrdiff_t len = buffer - begin;
if (len > 0) {
uint8_t *extra = realloc((void *)config->extra,
(size_t)(config->extra_length + len));
(size_t)(config->extra_length) + (size_t)len);

if (!extra) {
r = LIBUSB_ERROR_NO_MEM;
Expand Down
2 changes: 1 addition & 1 deletion libusb/version_nano.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define LIBUSB_NANO 11923
#define LIBUSB_NANO 11924

0 comments on commit 55f8c95

Please sign in to comment.