Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Sven Strickroth <[email protected]>
Signed-off-by: Sup Yut Sum <[email protected]>
  • Loading branch information
csware authored and ch3cooli committed Dec 11, 2015
1 parent 1119989 commit 6c06a5c
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 59 deletions.
1 change: 0 additions & 1 deletion src/TortoiseProc/ProgressDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
83 changes: 40 additions & 43 deletions src/TortoiseProc/UpdateCrypto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<unsigned char[]> 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<unsigned char[]> 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<unsigned char[]> 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<unsigned char[]> 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)
Expand Down
26 changes: 11 additions & 15 deletions src/Utils/MiscUI/SciEdit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<LPARAM>(static_cast<char *>(data)));
lenFile = fread(data, 1, sizeof(data), fp);
}
Call(SCI_SETCODEPAGE, bUTF8 ? SC_CP_UTF8 : GetACP());
return 0;
Call(SCI_ADDTEXT, lenFile, reinterpret_cast<LPARAM>(static_cast<char *>(data)));
lenFile = fread(data, 1, sizeof(data), fp);
}
else
return -1;
Call(SCI_SETCODEPAGE, bUTF8 ? SC_CP_UTF8 : GetACP());
return 0;
}

void CSciEdit::RestyleBugIDs()
Expand Down

0 comments on commit 6c06a5c

Please sign in to comment.