Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Incorrect Exception Handling in Recursive Factorial Function #2867

Open
henriq4 opened this issue Oct 20, 2024 · 0 comments · May be fixed by #2868
Open

[BUG] Incorrect Exception Handling in Recursive Factorial Function #2867

henriq4 opened this issue Oct 20, 2024 · 0 comments · May be fixed by #2868
Labels

Comments

@henriq4
Copy link

henriq4 commented Oct 20, 2024

Description

The bug occurs in a recursive factorial function that incorrectly throws an exception when n is less than 20, instead of when n exceeds 20.

Expected behavior

  • The function should return the factorial of n for valid inputs between 0 and 20, inclusive.
  • If n > 20, an exception should be thrown indicating that the maximum allowable value is 20.

Actual behavior

  • The function currently throws an exception if n < 20, which is incorrect.
  • Input values of n > 20 are allowed, potentially leading to integer overflow.

Steps to reproduce

  • Call factorial(10) or any n less than 20. The function incorrectly throws an exception.
  • Call factorial(25). No exception is thrown, but the value is incorrect or may result in integer overflow.

Context

  • The function is designed to calculate the factorial of a number n using recursion.
  • The valid range of n for uint64_t is 0 <= n <= 20 because the factorial of numbers larger than 20 exceeds the maximum value of a uint64_t.

Additional information

No response

@henriq4 henriq4 added the bug label Oct 20, 2024
@henriq4 henriq4 linked a pull request Oct 20, 2024 that will close this issue
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant