From e24c5e05d6ab923f1d9ee22d0fdafb893d9732b1 Mon Sep 17 00:00:00 2001
From: lurumdare <8020186+lurumdare@users.noreply.github.com>
Date: 周六, 07 9月 2019 22:00:55 +0800
Subject: [PATCH] NULL to nullptr (#34)

---
 src/tools/base_lib/win/CryptoHelperWindows.cpp |   34 +++++++++++++++++-----------------
 1 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/src/tools/base_lib/win/CryptoHelperWindows.cpp b/src/tools/base_lib/win/CryptoHelperWindows.cpp
index cdef638..7bf0ffb 100644
--- a/src/tools/base_lib/win/CryptoHelperWindows.cpp
+++ b/src/tools/base_lib/win/CryptoHelperWindows.cpp
@@ -62,7 +62,7 @@
 	KEYLENGTH | CRYPT_EXPORTABLE, &m_hCryptKey)) {
 		dwErrCode = GetLastError();
 		throw logic_error(
-				string("Error generating keys ") + to_string(dwErrCode));
+				string("Error generating keys ") + to_string(static_cast<long long>(dwErrCode)));
 	}
 }
 
@@ -73,7 +73,7 @@
 	HRESULT hr = S_OK;
 	DWORD dwErrCode;
 	DWORD dwBlobLen;
-	BYTE *pbKeyBlob = NULL;
+	BYTE *pbKeyBlob = nullptr;
 	stringstream ss;
 	// If the handle to key container is NULL, fail.
 	if (m_hCryptKey == NULL)
@@ -82,14 +82,14 @@
 	// blob.
 	if (!CryptExportKey(m_hCryptKey,
 	NULL, PUBLICKEYBLOB, 0,
-	NULL, &dwBlobLen)) {
+	nullptr, &dwBlobLen)) {
 		dwErrCode = GetLastError();
 		throw logic_error(
 				string("Error calculating size of public key ")
-						+ to_string(dwErrCode));
+						+ to_string(static_cast<long long>(dwErrCode)));
 	}
 	// Allocate memory for the pbKeyBlob.
-	if ((pbKeyBlob = new BYTE[dwBlobLen]) == NULL) {
+	if ((pbKeyBlob = new BYTE[dwBlobLen]) == nullptr) {
 		throw logic_error(string("Out of memory exporting public key "));
 	}
 	// Do the actual exporting into the key BLOB.
@@ -98,7 +98,7 @@
 		delete pbKeyBlob;
 		dwErrCode = GetLastError();
 		throw logic_error(
-				string("Error exporting public key ") + to_string(dwErrCode));
+				string("Error exporting public key ") + to_string(static_cast<long long>(dwErrCode)));
 	} else {
 		ss << "\t";
 		for (unsigned int i = 0; i < dwBlobLen; i++) {
@@ -108,7 +108,7 @@
 					ss << "\\" << endl << "\t";
 				}
 			}
-			ss << to_string(pbKeyBlob[i]);
+			ss << to_string(static_cast<long long>(pbKeyBlob[i]));
 		}
 		delete pbKeyBlob;
 	}
@@ -142,14 +142,14 @@
 	// blob.
 	if (!CryptExportKey(m_hCryptKey,
 	NULL, PRIVATEKEYBLOB, 0,
-	NULL, &dwBlobLen)) {
+	nullptr, &dwBlobLen)) {
 		dwErrCode = GetLastError();
 		throw logic_error(
 				string("Error calculating size of private key ")
-						+ to_string(dwErrCode));
+						+ to_string(static_cast<long long>(dwErrCode)));
 	}
 	// Allocate memory for the pbKeyBlob.
-	if ((pbKeyBlob = new BYTE[dwBlobLen]) == NULL) {
+	if ((pbKeyBlob = new BYTE[dwBlobLen]) == nullptr) {
 		throw logic_error(string("Out of memory exporting private key "));
 	}
 
@@ -159,7 +159,7 @@
 		delete pbKeyBlob;
 		dwErrCode = GetLastError();
 		throw logic_error(
-				string("Error exporting private key ") + to_string(dwErrCode));
+				string("Error exporting private key ") + to_string(static_cast<long long>(dwErrCode)));
 	} else {
 		ss << "\t";
 		for (unsigned int i = 0; i < dwBlobLen; i++) {
@@ -169,7 +169,7 @@
 					ss << "\\" << endl << "\t";
 				}
 			}
-			ss << to_string(pbKeyBlob[i]);
+			ss << to_string(static_cast<long long>(pbKeyBlob[i]));
 		}
 		delete pbKeyBlob;
 	}
@@ -201,7 +201,7 @@
 const string CryptoHelperWindows::signString(const void* privateKey,
 		size_t pklen, const string& license) const {
 	BYTE *pbBuffer = (BYTE *) license.c_str();
-	DWORD dwBufferLen = (DWORD)strlen((char *)pbBuffer);
+	const DWORD dwBufferLen = (DWORD)strlen((char *)pbBuffer);
 	HCRYPTHASH hHash;
 
 	HCRYPTKEY hKey;
@@ -216,7 +216,7 @@
 			&hKey)) {
 		throw logic_error(
 				string("Error in importing the PrivateKey ")
-						+ to_string(GetLastError()));
+						+ to_string(static_cast<long long>(GetLastError())));
 	}
 
 	//-------------------------------------------------------------------
@@ -243,7 +243,7 @@
 	// Determine the size of the signature and allocate memory.
 
 	dwSigLen = 0;
-	if (CryptSignHash(hHash, AT_SIGNATURE, NULL, 0, NULL, &dwSigLen)) {
+	if (CryptSignHash(hHash, AT_SIGNATURE, nullptr, 0, nullptr, &dwSigLen)) {
 		printf("Signature length %d found.\n", dwSigLen);
 	} else {
 		throw logic_error(string("Error during CryptSignHash."));
@@ -260,7 +260,7 @@
 	// Sign the hash object.
 
 	if (CryptSignHash(hHash, AT_SIGNATURE,
-	NULL, 0, pbSignature, &dwSigLen)) {
+	nullptr, 0, pbSignature, &dwSigLen)) {
 		printf("pbSignature is the signature length. %d\n", dwSigLen);
 	} else {
 		throw logic_error(string("Error during CryptSignHash."));
@@ -272,7 +272,7 @@
 	CryptDestroyKey(hKey);
 
 	CryptBinaryToString(pbSignature, dwSigLen,
-			CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, NULL, &strLen);
+			CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, nullptr, &strLen);
 	vector<char> buffer(strLen);
 	CryptBinaryToString(pbSignature, dwSigLen,
 			CRYPT_STRING_BASE64 | CRYPT_STRING_NOCRLF, &buffer[0], &strLen);

--
Gitblit v1.9.1