From a358337b928a6503b1925fee5d29c2fc1b79e517 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 090e0306d8..9368c480a1 100644 --- a/src/rpc/server.cpp +++ b/src/rpc/server.cpp @@ -31,6 +31,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 524e808838..501dabc249 100644 --- a/src/rpc/server.h +++ b/src/rpc/server.h @@ -203,6 +203,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 86f06c08ac..7f0aad9124 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -449,7 +449,7 @@ UniValue sendtoaddress(const JSONRPCRequest& request) 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(); }