Merge pull request #1323 from RaiKoHoff/Dev_RC_Fixes

Some little bugfixes
This commit is contained in:
Rainer Kottenhoff 2019-06-08 14:21:17 +02:00 committed by GitHub
commit efbac8a1e6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 72 additions and 65 deletions

View File

@ -1 +1 @@
2244
2247

View File

@ -407,8 +407,8 @@ int ReadAndDecryptFile(HWND hwnd, HANDLE hFile, DWORD size, void** result, DWORD
AES_bin_setup(&fileDecode, AES_DIR_DECRYPT, KEY_BYTES * 8, binFileKey);
AES_bin_cipherInit(&fileCypher, AES_MODE_CBC, &rawdata[PREAMBLE_SIZE]); // IV is next
{ // finally, decrypt the actual data
int nbb = BAD_CIPHER_STATE;
int nbp = BAD_CIPHER_STATE;
long nbb = BAD_CIPHER_STATE;
long nbp = BAD_CIPHER_STATE;
if ((readsize - code_offset) >= PAD_SLOP) {
nbb = AES_blockDecrypt(&fileCypher, &fileDecode, &rawdata[code_offset], readsize - code_offset - PAD_SLOP, rawdata);
}
@ -416,9 +416,9 @@ int ReadAndDecryptFile(HWND hwnd, HANDLE hFile, DWORD size, void** result, DWORD
nbp = AES_padDecrypt(&fileCypher, &fileDecode, &rawdata[code_offset + nbb], readsize - code_offset - nbb, rawdata + nbb);
}
if (nbp >= 0) {
int nb = nbb + nbp;
rawdata[nb] = (char)0;
rawdata[nb + 1] = (char)0; // two zeros in case it's multi-byte
unsigned long const nb = nbb + nbp;
rawdata[nb] = '\0';
rawdata[nb + 1] = '\0'; // two zeros in case it's multi-byte
*resultlen = (DWORD)nb;
}
else {

View File

@ -568,7 +568,7 @@ int AES_padDecrypt
return BAD_CIPHER_STATE;
}
return 16 * numBlocks - padLen;
return (16 * numBlocks) - padLen;
}
#ifdef INTERMEDIATE_VALUE_KAT

View File

@ -90,8 +90,8 @@ BEGIN
MENUITEM "UTF-8 with &Signature", IDM_ENCODING_UTF8SIGN
MENUITEM "&Altri...\tF9", IDM_ENCODING_SELECT
MENUITEM SEPARATOR
MENUITEM "Ricodifica con Encoding di &Default\tCtrl-Alt-F", CMD_RECODEDEFAULT
MENUITEM "Ricodifica come &ANSI\tCtrl-Shift+A", CMD_RECODEANSI
MENUITEM "Ricodifica con Encoding di &Default\tCtrl+Alt+F", CMD_RECODEDEFAULT
MENUITEM "Ricodifica come &ANSI\tCtrl+Shift+A", CMD_RECODEANSI
MENUITEM "Ricodifica come &OEM\tCtrl+Shift+O", CMD_RECODEOEM
MENUITEM "Ricodifica come &GB18030\tCtrl+Shift+F10", CMD_RECODEGB18030
MENUITEM "Ricodifica a UCHARDET Analysis", CMD_RELOADFORCEDETECTION

View File

@ -3,7 +3,7 @@
<assemblyIdentity
name="Notepad3"
processorArchitecture="*"
version="5.19.605.2244"
version="5.19.608.2247"
type="win32"
/>
<description>Notepad3 RC2</description>

View File

@ -337,7 +337,7 @@ bool EditConvertText(HWND hwnd, cpi_enc_t encSource, cpi_enc_t encDest, bool bSe
DocPos const length = SciCall_GetTextLength();
if (length == 0)
if (length <= 0)
{
EditSetNewText(hwnd, "", 0, bSetSavePoint);
}
@ -708,7 +708,7 @@ bool EditCopyAppend(HWND hwnd, bool bAppend)
length = SciCall_GetTextLength();
pszText = SciCall_GetRangePointer(0, length);
}
if (length == 0) {
if (length <= 0) {
res = true; // nothing to copy or append
return res;
}
@ -986,7 +986,7 @@ bool EditLoadFile(
}
DWORD cbData = 0L;
int const readFlag = ReadAndDecryptFile(hwnd, hFile, dwBufSize - 2, (void**)& lpData, &cbData);
int const readFlag = ReadAndDecryptFile(hwnd, hFile, dwBufSize, (void**)&lpData, &cbData);
Globals.dwLastError = GetLastError();
CloseHandle(hFile);
@ -1113,16 +1113,19 @@ bool EditLoadFile(
SciCall_SetEOLMode(Settings.DefaultEOLMode);
FreeMem(lpData);
}
// === UNICODE ===
else if (bIsUnicodeForced || (!bIsForced && bIsUnicodeAnalyzed && bIsUnicodeValid))
{
if (iForcedEncoding == CPI_UNICODE) {
bBOM = Has_UTF16_LE_BOM(lpData, clampi((int)cbData, 0, 8));
// === UNICODE ===
bool const bBOM_LE = Has_UTF16_LE_BOM(lpData, cbData);
bool const bBOM_BE = Has_UTF16_BE_BOM(lpData, cbData);
if ((iForcedEncoding == CPI_UNICODE) || bBOM_LE) {
bBOM = bBOM_LE;
bReverse = false;
}
else if (iForcedEncoding == CPI_UNICODEBE) {
bBOM = Has_UTF16_BE_BOM(lpData, clampi((int)cbData, 0, 8));
else if ((iForcedEncoding == CPI_UNICODEBE) || bBOM_BE) {
bBOM = bBOM_BE;
bReverse = true;
}
@ -1138,7 +1141,7 @@ bool EditLoadFile(
char* lpDataUTF8 = AllocMem((cbData * 3) + 2, HEAP_ZERO_MEMORY);
DWORD convCnt = (DWORD)WideCharToMultiByte(Encoding_SciCP, 0, (bBOM) ? (LPWSTR)lpData + 1 : (LPWSTR)lpData,
(bBOM) ? (cbData) / sizeof(WCHAR) : cbData / sizeof(WCHAR) + 1, lpDataUTF8, (MBWC_DocPos_Cast)SizeOfMem(lpDataUTF8), NULL, NULL);
(bBOM) ? (cbData / sizeof(WCHAR)) : (cbData / sizeof(WCHAR) + 1), lpDataUTF8, (MBWC_DocPos_Cast)SizeOfMem(lpDataUTF8), NULL, NULL);
if (convCnt == 0) {
status->bUnicodeErr = true;
@ -1269,7 +1272,6 @@ bool EditSaveFile(
bool bWriteSuccess;
char* lpData;
DWORD cbData;
DWORD dwBytesWritten;
status->bCancelDataLoss = false;
@ -1315,20 +1317,20 @@ bool EditSaveFile(
}
// get text
cbData = (DWORD)SciCall_GetTextLength();
DocPos cbData = SciCall_GetTextLength();
if (cbData == 0) {
if (cbData <= 0) {
bWriteSuccess = SetEndOfFile(hFile);
Globals.dwLastError = GetLastError();
}
else {
lpData = AllocMem(cbData + 4 + PAD_SLOP, HEAP_ZERO_MEMORY); //fix: +bom
SciCall_GetText((DocPos)cbData+1, lpData);
lpData = AllocMem(cbData + 4, HEAP_ZERO_MEMORY); //fix: +bom
cbData = SciCall_GetText((cbData+1), lpData);
// FIXME: move checks in front of disk file access
// Msg if file tag encoding does not correspond to BOM
/*if ((g_Encodings[iEncoding].uFlags & NCP_UNICODE) == 0 && (g_Encodings[iEncoding].uFlags & NCP_UTF8_SIGN) == 0) {
// Msg if file tag encoding does not correspond to BOM
/*if ((g_Encodings[iEncoding].uFlags & NCP_UNICODE) == 0 && (g_Encodings[iEncoding].uFlags & NCP_UTF8_SIGN) == 0) {
bool bEncodingMismatch = true;
FILEVARS fv;
FileVars_Init(lpData,cbData,&fv);
@ -1353,7 +1355,7 @@ bool EditSaveFile(
{
SetEndOfFile(hFile);
LPWSTR lpDataWide = AllocMem(cbData * 2 + PAD_SLOP, HEAP_ZERO_MEMORY);
LPWSTR lpDataWide = AllocMem((cbData+1) * 2 + 2, HEAP_ZERO_MEMORY);
int bomoffset = 0;
if (Encoding_IsUNICODE_BOM(status->iEncoding)) {
const char* bom = "\xFF\xFE";
@ -1361,7 +1363,7 @@ bool EditSaveFile(
bomoffset = 1;
}
int const cbDataWide = bomoffset +
MultiByteToWideChar(Encoding_SciCP, 0, lpData, cbData, &lpDataWide[bomoffset],
MultiByteToWideChar(Encoding_SciCP, 0, lpData, (MBWC_DocPos_Cast)cbData, &lpDataWide[bomoffset],
(MBWC_DocPos_Cast)((SizeOfMem(lpDataWide) / sizeof(WCHAR)) - bomoffset));
if (Encoding_IsUNICODE_REVERSE(status->iEncoding)) {
_swab((char*)lpDataWide, (char*)lpDataWide, cbDataWide * sizeof(WCHAR));
@ -1377,15 +1379,15 @@ bool EditSaveFile(
{
SetEndOfFile(hFile);
DocPos bomoffset = 0;
if (Encoding_IsUTF8_SIGN(status->iEncoding)) {
const char* bom = "\xEF\xBB\xBF";
DWORD const bomoffset = 3;
bomoffset = 3;
MoveMemory(&lpData[bomoffset], lpData, cbData);
CopyMemory(lpData, bom, bomoffset);
cbData += bomoffset;
}
}
//bWriteSuccess = WriteFile(hFile,lpData,cbData,&dwBytesWritten,NULL);
bWriteSuccess = EncryptAndWriteFile(hwnd, hFile, (BYTE*)lpData, cbData, &dwBytesWritten);
bWriteSuccess = EncryptAndWriteFile(hwnd, hFile, (BYTE*)lpData, (DWORD)(cbData + bomoffset), &dwBytesWritten);
Globals.dwLastError = GetLastError();
FreeMem(lpData);
@ -1396,23 +1398,24 @@ bool EditSaveFile(
BOOL bCancelDataLoss = FALSE;
UINT uCodePage = Encoding_GetCodePage(status->iEncoding);
LPWSTR lpDataWide = AllocMem(cbData * 2 + PAD_SLOP, HEAP_ZERO_MEMORY);
int cbDataWide = MultiByteToWideChar(Encoding_SciCP,0,lpData,cbData,
lpDataWide,(MBWC_DocPos_Cast)(SizeOfMem(lpDataWide)/sizeof(WCHAR)));
LPWSTR lpDataWide = AllocMem((cbData+1) * 2, HEAP_ZERO_MEMORY);
int const cbDataWide = MultiByteToWideChar(Encoding_SciCP,0,lpData, (MBWC_DocPos_Cast)cbData,
lpDataWide, (MBWC_DocPos_Cast)(SizeOfMem(lpDataWide)/sizeof(WCHAR)));
int cbDataNew = 0;
if (Encoding_IsMBCS(status->iEncoding)) {
FreeMem(lpData);
lpData = AllocMem(SizeOfMem(lpDataWide) * 2, HEAP_ZERO_MEMORY); // need more space
cbData = WideCharToMultiByte(uCodePage, 0, lpDataWide, cbDataWide,
cbDataNew = WideCharToMultiByte(uCodePage, 0, lpDataWide, cbDataWide,
lpData, (MBWC_DocPos_Cast)SizeOfMem(lpData), NULL, NULL);
}
else {
ZeroMemory(lpData, SizeOfMem(lpData));
cbData = WideCharToMultiByte(uCodePage,WC_NO_BEST_FIT_CHARS,lpDataWide,cbDataWide,
cbDataNew = WideCharToMultiByte(uCodePage,WC_NO_BEST_FIT_CHARS,lpDataWide,cbDataWide,
lpData,(MBWC_DocPos_Cast)SizeOfMem(lpData),NULL,&bCancelDataLoss);
if (!bCancelDataLoss) {
cbData = WideCharToMultiByte(uCodePage,0,lpDataWide,cbDataWide,
lpData,(MBWC_DocPos_Cast)SizeOfMem(lpData),NULL,NULL);
cbDataNew = WideCharToMultiByte(uCodePage,0,lpDataWide,cbDataWide,
lpData,(MBWC_DocPos_Cast)SizeOfMem(lpData),NULL,NULL);
bCancelDataLoss = FALSE;
}
}
@ -1420,7 +1423,7 @@ bool EditSaveFile(
if (!bCancelDataLoss || InfoBoxLng(MB_OKCANCEL,L"MsgConv3",IDS_MUI_ERR_UNICODE2) == IDOK) {
SetEndOfFile(hFile);
bWriteSuccess = EncryptAndWriteFile(hwnd, hFile, (BYTE*)lpData, cbData, &dwBytesWritten);
bWriteSuccess = EncryptAndWriteFile(hwnd, hFile, (BYTE*)lpData, cbDataNew, &dwBytesWritten);
Globals.dwLastError = GetLastError();
}
else {
@ -1432,7 +1435,7 @@ bool EditSaveFile(
else {
SetEndOfFile(hFile);
bWriteSuccess = EncryptAndWriteFile(hwnd, hFile, (BYTE*)lpData, cbData, &dwBytesWritten);
bWriteSuccess = EncryptAndWriteFile(hwnd, hFile, (BYTE*)lpData, (DWORD)cbData, &dwBytesWritten);
Globals.dwLastError = GetLastError();
FreeMem(lpData);
}
@ -3684,7 +3687,7 @@ void EditRemoveBlankLines(HWND hwnd, bool bMerge, bool bRemoveWhiteSpace)
}
const DocPos iSelStart = (SciCall_IsSelectionEmpty() ? 0 : SciCall_GetSelectionStart());
const DocPos iSelEnd = (SciCall_IsSelectionEmpty() ? (Sci_GetDocEndPosition()-1) : SciCall_GetSelectionEnd());
const DocPos iSelEnd = (SciCall_IsSelectionEmpty() ? Sci_GetDocEndPosition() : SciCall_GetSelectionEnd());
DocLn iBegLine = SciCall_LineFromPosition(iSelStart);
DocLn iEndLine = SciCall_LineFromPosition(iSelEnd);
@ -6054,13 +6057,13 @@ bool EditFindPrev(HWND hwnd, LPCEDITFINDREPLACE lpefr, bool bExtendSelection, bo
if (slen <= 0)
return false;
DocPos const iTextLength = Sci_GetDocEndPosition() + 1;
DocPos const iDocEndPos = Sci_GetDocEndPosition();
DocPos start = SciCall_GetCurrentPos();
DocPos end = 0;
if (start <= end) {
if (IDOK == InfoBoxLng(MB_OKCANCEL, L"MsgFindWrap1", IDS_MUI_FIND_WRAPFW)) {
end = start; start = iTextLength;
end = start; start = iDocEndPos;
}
else
bSuppressNotFound = true;
@ -6075,13 +6078,13 @@ bool EditFindPrev(HWND hwnd, LPCEDITFINDREPLACE lpefr, bool bExtendSelection, bo
InfoBoxLng(MB_ICONWARNING, L"MsgInvalidRegex", IDS_MUI_REGEX_INVALID);
bSuppressNotFound = true;
}
else if ((iPos < 0) && (start <= iTextLength) && !bExtendSelection)
else if ((iPos < 0) && (start <= iDocEndPos) && !bExtendSelection)
{
UpdateStatusbar(false);
if (!lpefr->bNoFindWrap && !bSuppressNotFound)
{
if (IDOK == InfoBoxLng(MB_OKCANCEL, L"MsgFindWrap2", IDS_MUI_FIND_WRAPRE)) {
end = start; start = iTextLength;
end = start; start = iDocEndPos;
iPos = _FindInTarget(hwnd, szFind, slen, (int)(lpefr->fuFlags), &start, &end, false, FRMOD_WRAPED);

View File

@ -648,16 +648,18 @@ int Encoding_GetNameW(const cpi_enc_t iEncoding, LPWSTR buffer, size_t cwch)
bool Has_UTF16_LE_BOM(const char* pBuf, size_t cnt)
{
int iTest = IS_TEXT_UNICODE_SIGNATURE;
bool const ok = IsTextUnicode(pBuf, (int)cnt, &iTest);
return (ok && ((iTest & IS_TEXT_UNICODE_SIGNATURE) != 0));
/*bool const ok =*/ (void)IsTextUnicode(pBuf, clampi((int)cnt, 0, 4), &iTest);
//~return (ok && ((iTest & IS_TEXT_UNICODE_SIGNATURE) != 0));
return ((iTest & IS_TEXT_UNICODE_SIGNATURE) != 0); // don't rely on result ok
}
// ----------------------------------------------------------------------------
bool Has_UTF16_BE_BOM(const char* pBuf, size_t cnt)
{
int iTest = IS_TEXT_UNICODE_REVERSE_SIGNATURE;
bool const ok = IsTextUnicode(pBuf, (int)cnt, &iTest);
return (ok && ((iTest & IS_TEXT_UNICODE_REVERSE_SIGNATURE) != 0));
/*bool const ok =*/ (void)IsTextUnicode(pBuf, clampi((int)cnt, 0, 4), &iTest);
//~return (ok && ((iTest & IS_TEXT_UNICODE_REVERSE_SIGNATURE) != 0));
return ((iTest & IS_TEXT_UNICODE_REVERSE_SIGNATURE) != 0); // don't rely on result ok
}
// ============================================================================
@ -677,7 +679,7 @@ bool IsValidUnicode(const char* pBuffer, const size_t len, bool* lpbBOM, bool* l
int const iAllTests = IS_TEXT_UNICODE_UNICODE_MASK | IS_TEXT_UNICODE_REVERSE_MASK | IS_TEXT_UNICODE_NOT_UNICODE_MASK | IS_TEXT_UNICODE_NOT_ASCII_MASK;
int iTest = iAllTests;
(void) IsTextUnicode(pBuffer, (int)cb, &iTest);
/*bool const ok =*/ (void)IsTextUnicode(pBuffer, (int)cb, &iTest); // don't rely on result ok
if (iTest == iAllTests) {
iTest = 0; // iTest doesn't seem to have been modified ...

View File

@ -98,7 +98,7 @@ static bool _LngStrToMultiLngStr(WCHAR* pLngStr, WCHAR* pLngMultiStr, size_t ln
if ((strLen > 0) && pLngMultiStr && (lngMultiStrSize > 0)) {
WCHAR* lngMultiStrPtr = pLngMultiStr;
WCHAR* last = pLngStr + (Has_UTF16_LE_BOM((char*)pLngStr, clampi((int)strLen, 0, 8)) ? 1 : 0);
WCHAR* last = pLngStr + (Has_UTF16_LE_BOM((char*)pLngStr, (strLen * sizeof(WCHAR))) ? 1 : 0);
while (last && rtnVal) {
// make sure you validate the user input
WCHAR* next = StrNextTok(last, L",; :");

View File

@ -436,21 +436,23 @@ inline bool IsSaveNeeded(const SAVE_NEEDED_QUERY query)
static void _SetSaveNeededFlag(const bool setSaveNeeded)
{
bool const isDocModified = setSaveNeeded || SciCall_GetModify(); // consistency
bool const bGetModify = SciCall_GetModify();
bool const isDocModified = setSaveNeeded || bGetModify; // consistency
// update on change
if (IsSaveNeeded(ISN_GET) != isDocModified)
{
IsSaveNeeded(isDocModified ? ISN_SET : ISN_CLEAR);
UpdateToolbar();
UpdateStatusbar(false);
UpdateStatusbar(true);
}
if (setSaveNeeded) {
// Force trigger modified (e.g. RelaunchElevated)
if (!SciCall_GetModify()) {
SciCall_AppendText(1, " "); // trigger dirty flag
SciCall_DeleteRange(Sci_GetDocEndPosition(), 1);
if (!bGetModify) {
DocPos const posDocEnd = Sci_GetDocEndPosition();
SciCall_AppendText(1, "\v"); // trigger dirty flag
SciCall_DeleteRange(posDocEnd, 1);
}
// notify Search/Replace dialog
if (IsWindow(Globals.hwndDlgFindReplace)) {
@ -2895,7 +2897,7 @@ LRESULT MsgInitMenu(HWND hwnd, WPARAM wParam, LPARAM lParam)
EnableCmd(hmenu,IDM_EDIT_REDO,SciCall_CanRedo() && !ro);
bool const s = SciCall_IsSelectionEmpty();
bool const e = (SciCall_GetTextLength() == 0);
bool const e = (SciCall_GetTextLength() <= 0);
bool const p = SciCall_CanPaste();
bool const mls = Sci_IsMultiLineSelection();
@ -3564,7 +3566,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
_IGNORE_NOTIFY_CHANGE_;
if (EditSetNewEncoding(Globals.hwndEdit, iNewEncoding, (s_flagSetEncoding != CPI_NONE))) {
if (SciCall_GetTextLength() == 0) {
if (SciCall_GetTextLength() <= 0) {
Encoding_Current(iNewEncoding);
Encoding_HasChanged(iNewEncoding);
}
@ -4681,7 +4683,7 @@ LRESULT MsgCommand(HWND hwnd, UINT umsg, WPARAM wParam, LPARAM lParam)
case IDM_EDIT_SELTONEXT:
case IDM_EDIT_SELTOPREV:
if (SciCall_GetTextLength() == 0) { break; }
if (SciCall_GetTextLength() <= 0) { break; }
if (IsFindPatternEmpty() && !StringCchLenA(Settings.EFR_Data.szFind, COUNTOF(Settings.EFR_Data.szFind)))
{
@ -10155,7 +10157,7 @@ bool FileSave(bool bSaveAlways, bool bAsk, bool bSaveAs, bool bSaveCopy)
bool bIsEmptyNewFile = false;
if (StringCchLenW(Globals.CurrentFile, COUNTOF(Globals.CurrentFile)) == 0) {
DocPos const cchText = SciCall_GetTextLength();
if (cchText == 0) {
if (cchText <= 0) {
bIsEmptyNewFile = true;
}
else if (cchText < 2048) {

View File

@ -540,7 +540,7 @@ DeclareSciCallR0(IsSelectionRectangle, SELECTIONISRECTANGLE, bool)
#define Sci_GetNetLineLength(line) (SciCall_GetLineEndPosition(line) - SciCall_PositionFromLine(line))
//~#define Sci_GetDocEndPosition() (SciCall_GetTextLength() - 1)
#define Sci_GetDocEndPosition() SciCall_GetLineEndPosition(SciCall_GetLineCount() - 1)
#define Sci_GetDocEndPosition() SciCall_GetLineEndPosition(SciCall_GetLineCount())
// max. line length in range (incl. line-breaks)
inline DocPos Sci_GetRangeMaxLineLength(DocLn iBeginLine, DocLn iEndLine) {

View File

@ -7,8 +7,8 @@
#define SAPPNAME "Notepad3"
#define VERSION_MAJOR 5
#define VERSION_MINOR 19
#define VERSION_REV 605
#define VERSION_BUILD 2244
#define VERSION_REV 608
#define VERSION_BUILD 2247
#define SCINTILLA_VER 415+
#define ONIGMO_REGEX_VER 6.2.0
#define VERSION_PATCH RC2