From 2a34dbdaa505e47bdfb865efa8b77fe9fe0c7f11 Mon Sep 17 00:00:00 2001 From: instagibbs Date: Thu, 28 Apr 2016 14:47:07 -0400 Subject: [PATCH] Introduce user getter to avoid null pointers --- src/rpc/server.cpp | 4 ++++ src/rpc/server.h | 2 ++ src/wallet/rpcwallet.cpp | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/rpc/server.cpp b/src/rpc/server.cpp index 3abf44be88..5c303deed2 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -30,6 +30,10 @@ //Thread local rpc user name for logging purposes boost::thread_specific_ptr userInstance; +std::string getUser() { + return (userInstance.get() ? *userInstance.get() : "UNDEFINED_USER"); +} + using namespace RPCServer; using namespace std; diff --git a/src/rpc/server.h b/src/rpc/server.h index da6ca01791..be2d85bfd1 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -193,6 +193,8 @@ extern std::string HelpRequiringPassphrase(); extern std::string HelpExampleCli(const std::string& methodname, const std::string& args); extern std::string HelpExampleRpc(const std::string& methodname, const std::string& args); +extern std::string getUser(); + extern void EnsureWalletIsUnlocked(); bool StartRPC(); diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 7c17840d9c..e8e0a811c0 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -442,7 +442,7 @@ UniValue sendtoaddress(const UniValue& params, bool fHelp) SendMoney(address.Get(), nAmount, fSubtractFeeFromAmount, confidentiality_pubkey, wtx); - AuditLogPrintf("%s : sendtoaddress %s %d", *userInstance.get(), wtx.GetHash().GetHex(), nAmount); + AuditLogPrintf("%s : sendtoaddress %s %d", getUser(), wtx.GetHash().GetHex(), nAmount); return wtx.GetHash().GetHex(); }