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

fix: remove memory leak iterative_factorial.cpp #2535

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions math/iterative_factorial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace math {
*/
uint64_t iterativeFactorial(uint8_t n) {
if (n > 20) {
throw new std::invalid_argument("Maximum n value is 20");
throw std::invalid_argument("Maximum n value is 20");
}

// 1 because it is the identity number of multiplication.
Expand Down Expand Up @@ -101,12 +101,14 @@ static void test() {
std::cout << "Exception test \n"
"Input: 21 \n"
"Expected output: Exception thrown \n";

bool wasExceptionThrown = false;
vil02 marked this conversation as resolved.
Show resolved Hide resolved
try {
math::iterativeFactorial(21);
} catch (std::invalid_argument* e) {
std::cout << "Exception thrown successfully \nContent: " << e->what()
<< "\n";
} catch (const std::invalid_argument&) {
wasExceptionThrown = true;
vil02 marked this conversation as resolved.
Show resolved Hide resolved
}
assert(wasExceptionThrown);
vil02 marked this conversation as resolved.
Show resolved Hide resolved

std::cout << "All tests have passed successfully.\n";
}
Expand Down