From 98ec9e2a9c413f096c1b0c170d9336eb6c6a702f Mon Sep 17 00:00:00 2001 From: Vincent Batts Date: Mon, 10 Feb 2025 17:28:15 -0500 Subject: [PATCH] main: trying out assert and validations Signed-off-by: Vincent Batts --- main.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/main.cpp b/main.cpp index 179d7c9..c2cffa4 100644 --- a/main.cpp +++ b/main.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include "./common.h" #include "./account.h" @@ -26,6 +27,11 @@ Account* do_account() { Account* account = new Account(0.0); + assert(account); + if (nullptr == account) { + log_err("failed to allocate account"); + return nullptr; + } account->deposit(100.5); // Add some money account->deposit(50.25); // Add more money @@ -36,10 +42,15 @@ Account* do_account() { void scoped_account() { log_out("HERE"); auto account = do_account(); + if (nullptr == account) { + log_err("failed to allocate account"); + return; + } log_out("HERE"); account->withdraw(100); log_out("Current Balance: " << account->getBalance()); log_err("dang"); + delete account; }