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

Closed
henriq4 opened this issue Oct 20, 2024 · 1 comment · Fixed by #2868
Closed

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

henriq4 opened this issue Oct 20, 2024 · 1 comment · Fixed by #2868
Labels
bug stale Author has not responded to the comments for over 2 weeks

Comments

@henriq4
Copy link
Contributor

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

Copy link
Contributor

This issue has been automatically marked as abandoned because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@github-actions github-actions bot added the stale Author has not responded to the comments for over 2 weeks label Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug stale Author has not responded to the comments for over 2 weeks
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant