Skip to content

Commit

Permalink
Fix UB in function add_with_overflow_check_subopt()
Browse files Browse the repository at this point in the history
  • Loading branch information
Fanda Vacek committed Oct 30, 2024
1 parent 0b61764 commit fc31f75
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions libshvchainpack/c/ccpon.c
Original file line number Diff line number Diff line change
Expand Up @@ -803,11 +803,11 @@ const char* ccpon_unpack_skip_insignificant(ccpcp_unpack_context* unpack_context

static bool add_with_overflow_check_subopt(int64_t a, int b, int64_t *result)
{
int64_t res = a + b;
if (res < 0) {
return true;
// Check for overflow
if (a > INT64_MAX - b) {
return true; // Overflow occurred
}
*result = res;
*result = a + b;
return false;
}

Expand Down

0 comments on commit fc31f75

Please sign in to comment.