Fix "Generate from selection into clipboard" crash regression

Fix #13818
This commit is contained in:
Don Ho 2023-06-21 19:35:23 +02:00
parent b14810d087
commit 6131195da7

View File

@ -3287,31 +3287,35 @@ void Notepad_plus::command(int id)
uint8_t hash[HASH_MAX_LENGTH] {}; uint8_t hash[HASH_MAX_LENGTH] {};
wchar_t hashStr[HASH_STR_MAX_LENGTH] {}; wchar_t hashStr[HASH_STR_MAX_LENGTH] {};
int hashLen = 0;
switch (id) switch (id)
{ {
case IDM_TOOL_SHA1_GENERATEINTOCLIPBOARD: case IDM_TOOL_SHA1_GENERATEINTOCLIPBOARD:
{ {
calc_sha1(hash, reinterpret_cast<const uint8_t*>(selectedStr), strlen(selectedStr)); calc_sha1(hash, reinterpret_cast<const uint8_t*>(selectedStr), strlen(selectedStr));
hashLen = hash_sha1;
} }
break; break;
case IDM_TOOL_SHA256_GENERATEINTOCLIPBOARD: case IDM_TOOL_SHA256_GENERATEINTOCLIPBOARD:
{ {
calc_sha_256(hash, reinterpret_cast<const uint8_t*>(selectedStr), strlen(selectedStr)); calc_sha_256(hash, reinterpret_cast<const uint8_t*>(selectedStr), strlen(selectedStr));
hashLen = hash_sha256;
} }
break; break;
case IDM_TOOL_SHA512_GENERATEINTOCLIPBOARD: case IDM_TOOL_SHA512_GENERATEINTOCLIPBOARD:
{ {
calc_sha_512(hash, reinterpret_cast<const uint8_t*>(selectedStr), strlen(selectedStr)); calc_sha_512(hash, reinterpret_cast<const uint8_t*>(selectedStr), strlen(selectedStr));
hashLen = hash_sha512;
} }
break; break;
default: default:
return; return;
} }
for (int i = 0; i < id; i++) for (int i = 0; i < hashLen; i++)
wsprintf(hashStr + i * 2, TEXT("%02x"), hash[i]); wsprintf(hashStr + i * 2, TEXT("%02x"), hash[i]);
str2Clipboard(hashStr, _pPublicInterface->getHSelf()); str2Clipboard(hashStr, _pPublicInterface->getHSelf());