diff --git a/src/TortoiseProc/ProgressDlg.cpp b/src/TortoiseProc/ProgressDlg.cpp index f4547bc733..3cab654463 100644 --- a/src/TortoiseProc/ProgressDlg.cpp +++ b/src/TortoiseProc/ProgressDlg.cpp @@ -610,7 +610,6 @@ void CProgressDlg::RemoveLastLine(CString &str) start=str.ReverseFind(_T('\n')); if(start>0) str=str.Left(start); - return; } // CProgressDlg message handlers diff --git a/src/TortoiseProc/UpdateCrypto.cpp b/src/TortoiseProc/UpdateCrypto.cpp index f37a06e01a..9ba549d239 100644 --- a/src/TortoiseProc/UpdateCrypto.cpp +++ b/src/TortoiseProc/UpdateCrypto.cpp @@ -575,59 +575,56 @@ static int parse_public_key(const uint8_t *p_key_data, size_t i_key_len, public_ static int LoadSignature(const CString &signatureFilename, signature_packet_t *p_sig) { - FILE * pFile = _tfsopen(signatureFilename, _T("rb"), SH_DENYWR); - if (pFile) - { - int size = 65536; - std::unique_ptr buffer(new unsigned char[size]); - int length = 0; - if ((length = (int)fread(buffer.get(), sizeof(char), size, pFile)) >= 8) - { - fclose(pFile); - // is unpacking needed? - if ((uint8_t)buffer[0] < 0x80) - { - std::unique_ptr unpacked(new unsigned char[size]); - size = pgp_unarmor((char *)buffer.get(), length, unpacked.get(), length); + FILE* pFile = _tfsopen(signatureFilename, _T("rb"), SH_DENYWR); + if (!pFile) + return -1; - if (size < 2) - return -1; + int size = 65536; + std::unique_ptr buffer(new unsigned char[size]); + int length = (int)fread(buffer.get(), sizeof(char), size, pFile); + fclose(pFile); + if (length < 8) + return -1; - buffer.swap(unpacked); - } - else - size = length; + // is unpacking needed? + if ((uint8_t)buffer[0] < 0x80) + { + std::unique_ptr unpacked(new unsigned char[size]); + size = pgp_unarmor((char *)buffer.get(), length, unpacked.get(), length); - if (packet_type(buffer[0]) != SIGNATURE_PACKET) - return -1; + if (size < 2) + return -1; + + buffer.swap(unpacked); + } + else + size = length; - DWORD i_header_len = packet_header_len(buffer[0]); - if ((i_header_len != 1 && i_header_len != 2 && i_header_len != 4) || i_header_len + 1 > (DWORD)size) - return -1; + if (packet_type(buffer[0]) != SIGNATURE_PACKET) + return -1; - DWORD i_len = scalar_number((uint8_t *)(buffer.get() + 1), i_header_len); - if (i_len + i_header_len + 1 != (DWORD)size) - return -1; + DWORD i_header_len = packet_header_len(buffer[0]); + if ((i_header_len != 1 && i_header_len != 2 && i_header_len != 4) || i_header_len + 1 > (DWORD)size) + return -1; - if (parse_signature_packet(p_sig, (uint8_t *)(buffer.get() + 1 + i_header_len), i_len)) - return -1; + DWORD i_len = scalar_number((uint8_t *)(buffer.get() + 1), i_header_len); + if (i_len + i_header_len + 1 != (DWORD)size) + return -1; - if (p_sig->type != BINARY_SIGNATURE && p_sig->type != TEXT_SIGNATURE) - { - if (p_sig->version == 4) - { - free(p_sig->specific.v4.hashed_data); - free(p_sig->specific.v4.unhashed_data); - } - return -1; - } + if (parse_signature_packet(p_sig, (uint8_t *)(buffer.get() + 1 + i_header_len), i_len)) + return -1; - return 0; + if (p_sig->type != BINARY_SIGNATURE && p_sig->type != TEXT_SIGNATURE) + { + if (p_sig->version == 4) + { + free(p_sig->specific.v4.hashed_data); + free(p_sig->specific.v4.unhashed_data); } - else - fclose(pFile); + return -1; } - return -1; + + return 0; } static void CryptHashChar(HCRYPTHASH hHash, const int c) diff --git a/src/Utils/MiscUI/SciEdit.cpp b/src/Utils/MiscUI/SciEdit.cpp index c0873f31db..94cf2ea68f 100644 --- a/src/Utils/MiscUI/SciEdit.cpp +++ b/src/Utils/MiscUI/SciEdit.cpp @@ -1680,23 +1680,19 @@ void CSciEdit::SetUDiffStyle() int CSciEdit::LoadFromFile(CString &filename) { CAutoFILE fp = _tfsopen(filename, _T("rb"), _SH_DENYWR); - if (fp) + if (!fp) + return -1; + + char data[4096] = { 0 }; + size_t lenFile = fread(data, 1, sizeof(data), fp); + bool bUTF8 = IsUTF8(data, lenFile); + while (lenFile > 0) { - //SetTitle(); - char data[4096] = { 0 }; - size_t lenFile = fread(data, 1, sizeof(data), fp); - bool bUTF8 = IsUTF8(data, lenFile); - while (lenFile > 0) - { - Call(SCI_ADDTEXT, lenFile, - reinterpret_cast(static_cast(data))); - lenFile = fread(data, 1, sizeof(data), fp); - } - Call(SCI_SETCODEPAGE, bUTF8 ? SC_CP_UTF8 : GetACP()); - return 0; + Call(SCI_ADDTEXT, lenFile, reinterpret_cast(static_cast(data))); + lenFile = fread(data, 1, sizeof(data), fp); } - else - return -1; + Call(SCI_SETCODEPAGE, bUTF8 ? SC_CP_UTF8 : GetACP()); + return 0; } void CSciEdit::RestyleBugIDs()