diff --git a/src/Dialogs.c b/src/Dialogs.c index 3652c9595..eae79f9c7 100644 --- a/src/Dialogs.c +++ b/src/Dialogs.c @@ -144,7 +144,7 @@ int MsgBoxLng(int iType, UINT uIdMsg, ...) StringCchCat(szText, COUNTOF(szText), lpMsgBuf); LocalFree(lpMsgBuf); } - wcht = *CharPrev(szText, StrEnd(szText)); + wcht = *CharPrev(szText, StrEnd(szText, COUNTOF(szText))); if (IsCharAlphaNumeric(wcht) || wcht == '"' || wcht == '\'') StringCchCat(szText, COUNTOF(szText), L"."); } @@ -415,7 +415,7 @@ static DWORD CALLBACK _LoadRtfCallback( ) { LPSTR* pstr = (LPSTR*)dwCookie; - LONG len = (LONG)strlen(*pstr); + LONG len = (LONG)StringCchLenA(*pstr,0); if (len < cb) { @@ -3359,7 +3359,7 @@ int Toolbar_SetButtons(HWND hwnd, int cmdBase, LPCWSTR lpszButtons, LPCTBBUTTON TrimStringW(tchButtons); WCHAR *p = StrStr(tchButtons, L" "); while (p) { - MoveMemory((WCHAR*)p, (WCHAR*)p + 1, (lstrlen(p) + 1) * sizeof(WCHAR)); + MoveMemory((WCHAR*)p, (WCHAR*)p + 1, (StringCchLen(p,0) + 1) * sizeof(WCHAR)); p = StrStr(tchButtons, L" "); // next } c = (int)SendMessage(hwnd, TB_BUTTONCOUNT, 0, 0); @@ -3380,7 +3380,7 @@ int Toolbar_SetButtons(HWND hwnd, int cmdBase, LPCWSTR lpszButtons, LPCTBBUTTON } } } - p = StrEnd(p) + 1; + p = StrEnd(p,0) + 1; } return((int)SendMessage(hwnd, TB_BUTTONCOUNT, 0, 0)); } @@ -3511,7 +3511,7 @@ DLGTEMPLATE* LoadThemedDialogTemplate(LPCTSTR lpDialogTemplateID, HINSTANCE hIns pbNew = (BYTE*)wchFaceName; pb = DialogTemplate_GetFontSizeField(pTemplate); - cbOld = (int)(bHasFont ? cbFontAttr + 2 * (lstrlen((WCHAR*)(pb + cbFontAttr)) + 1) : 0); + cbOld = (int)(bHasFont ? cbFontAttr + 2 * (StringCchLen((WCHAR*)(pb + cbFontAttr),0) + 1) : 0); pOldControls = (BYTE*)(((DWORD_PTR)pb + cbOld + 3) & ~(DWORD_PTR)3); pNewControls = (BYTE*)(((DWORD_PTR)pb + cbNew + 3) & ~(DWORD_PTR)3); diff --git a/src/Edit.c b/src/Edit.c index 8307273aa..38f3a5f7c 100644 --- a/src/Edit.c +++ b/src/Edit.c @@ -339,7 +339,7 @@ void EditInitWordDelimiter(HWND hwnd) StringCchCopyA(WhiteSpaceCharsAccelerated, COUNTOF(WhiteSpaceCharsAccelerated), WhiteSpaceCharsDefault); // add only 7-bit-ASCII chars to accelerated whitespace list - for (size_t i = 0; i < strlen(whitesp); i++) { + for (size_t i = 0; i < StringCchLenA(whitesp, ANSI_CAHR_BUFFER); i++) { if (whitesp[i] & 0x7F) { if (!StrChrA(WhiteSpaceCharsAccelerated, whitesp[i])) { StringCchCatNA(WhiteSpaceCharsAccelerated, COUNTOF(WhiteSpaceCharsAccelerated), &(whitesp[i]), 1); @@ -350,7 +350,7 @@ void EditInitWordDelimiter(HWND hwnd) // construct word char array StringCchCopyA(WordCharsAccelerated, COUNTOF(WordCharsAccelerated), WordCharsDefault); // init // add punctuation chars not listed in white-space array - for (size_t i = 0; i < strlen(PunctuationCharsDefault); i++) { + for (size_t i = 0; i < StringCchLenA(PunctuationCharsDefault, ANSI_CAHR_BUFFER); i++) { if (!StrChrA(WhiteSpaceCharsAccelerated, PunctuationCharsDefault[i])) { StringCchCatNA(WordCharsAccelerated, COUNTOF(WordCharsAccelerated), &(PunctuationCharsDefault[i]), 1); } @@ -367,7 +367,7 @@ void EditInitWordDelimiter(HWND hwnd) WideCharToMultiByteStrg(CP_ACP, buffer, autocompl); } // add only 7-bit-ASCII chars to accelerated whitespace list - for (size_t i = 0; i < strlen(autocompl); i++) { + for (size_t i = 0; i < StringCchLenA(autocompl, ANSI_CAHR_BUFFER); i++) { if (autocompl[i] & 0x7F) { if (!StrChrA(AutoCompleteWordASCII, autocompl[i])) { StringCchCatNA(AutoCompleteWordASCII, COUNTOF(AutoCompleteWordASCII), &(autocompl[i]), 1); @@ -721,7 +721,7 @@ char* EditGetClipboardText(HWND hwnd, bool bCheckEncoding, int* pLineCount, int* bool EditSetClipboardText(HWND hwnd, const char* pszText) { if (!IsClipboardFormatAvailable(CF_UNICODETEXT)) { - SciCall_CopyText((DocPos)strlen(pszText), pszText); + SciCall_CopyText((DocPos)StringCchLenA(pszText,0), pszText); return true; } @@ -861,19 +861,19 @@ bool EditCopyAppend(HWND hwnd, bool bAppend) HANDLE hOld = GetClipboardData(CF_UNICODETEXT); WCHAR* pszOld = GlobalLock(hOld); - int sizeNew = 0; + size_t sizeNew = 0; if (pszOld && pszTextW) - sizeNew = lstrlen(pszOld) + lstrlen(pszTextW) + 1; + sizeNew = StringCchLen(pszOld,0) + StringCchLen(pszTextW,0) + 1; const WCHAR *pszSep = L"\r\n"; - sizeNew += (int)lstrlen(pszSep); + sizeNew += StringCchLen(pszSep,0); // Copy Clip WCHAR* pszNewTextW = LocalAlloc(LPTR, sizeof(WCHAR) * sizeNew); - if (pszOld && pszNewTextW) + if (pszOld && pszNewTextW) { StringCchCopy(pszNewTextW, sizeNew, pszOld); - + } GlobalUnlock(hOld); CloseClipboard(); @@ -1888,7 +1888,7 @@ void EditChar2Hex(HWND hwnd) { } SendMessage(hwnd, SCI_REPLACESEL, 0, (LPARAM)ch); - const DocPos iReplLen = StringCchLenA(ch, COUNTOF(ch)); + DocPos const iReplLen = (DocPos)StringCchLenA(ch, COUNTOF(ch)); if (iCurPos < iAnchorPos) { EditSelectEx(hwnd, iCurPos + iReplLen, iCurPos, -1, -1); @@ -2067,7 +2067,7 @@ void EditModifyNumber(HWND hwnd,bool bIncrease) { StringCchPrintfA(chFormat, COUNTOF(chFormat), "%%0%ii", iWidth); StringCchPrintfA(chNumber, COUNTOF(chNumber), chFormat, iNumber); SciCall_ReplaceSel(chNumber); - SciCall_SetSel(iSelStart, iSelStart + StringCchLenA(chNumber, COUNTOF(chNumber))); + SciCall_SetSel(iSelStart, iSelStart + (DocPos)StringCchLenA(chNumber, COUNTOF(chNumber))); } } else if (sscanf_s(chNumber, "%x", &iNumber) == 1) { @@ -2093,7 +2093,7 @@ void EditModifyNumber(HWND hwnd,bool bIncrease) { StringCchPrintfA(chNumber, COUNTOF(chNumber), chFormat, iNumber); SciCall_ReplaceSel(chNumber); - SciCall_SetSel(iSelStart, iSelStart + StringCchLenA(chNumber, COUNTOF(chNumber))); + SciCall_SetSel(iSelStart, iSelStart + (DocPos)StringCchLenA(chNumber, COUNTOF(chNumber))); } } } @@ -2866,7 +2866,7 @@ void EditAlignText(HWND hwnd,int nMode) WCHAR wchNewLineBuf[BUFSIZE_ALIGN * 3] = { L'\0' }; int length = BUFSIZE_ALIGN * 3; StringCchCopy(wchNewLineBuf,COUNTOF(wchNewLineBuf),pWords[0]); - p = StrEnd(wchNewLineBuf); + p = StrEnd(wchNewLineBuf, COUNTOF(wchNewLineBuf)); for (i = 1; i < iWords; i++) { for (j = 0; j < iSpacesPerGap; j++) { @@ -2878,7 +2878,7 @@ void EditAlignText(HWND hwnd,int nMode) *p = 0; } StringCchCat(p,(length - StringCchLenW(wchNewLineBuf,COUNTOF(wchNewLineBuf))),pWords[i]); - p = StrEnd(p); + p = StrEnd(p,0); } int cch = WideCharToMultiByteStrg(Encoding_SciCP,wchNewLineBuf,g_pTempLineBuffer) - 1; @@ -2892,13 +2892,13 @@ void EditAlignText(HWND hwnd,int nMode) WCHAR wchNewLineBuf[BUFSIZE_ALIGN] = { L'\0' }; StringCchCopy(wchNewLineBuf,COUNTOF(wchNewLineBuf),pWords[0]); - p = StrEnd(wchNewLineBuf); + p = StrEnd(wchNewLineBuf, COUNTOF(wchNewLineBuf)); for (int i = 1; i < iWords; i++) { *p++ = L' '; *p = 0; StringCchCat(p,(COUNTOF(wchNewLineBuf) - StringCchLenW(wchNewLineBuf,COUNTOF(wchNewLineBuf))),pWords[i]); - p = StrEnd(p); + p = StrEnd(p,0); } int cch = WideCharToMultiByteStrg(Encoding_SciCP,wchNewLineBuf,g_pTempLineBuffer) - 1; @@ -2937,7 +2937,7 @@ void EditAlignText(HWND hwnd,int nMode) StringCchCat(p,(COUNTOF(wchNewLineBuf) - StringCchLenW(wchNewLineBuf,COUNTOF(wchNewLineBuf))),L" "); iOddSpaces--; } - p = StrEnd(p); + p = StrEnd(p,0); } int cch = WideCharToMultiByteStrg(Encoding_SciCP,wchNewLineBuf,g_pTempLineBuffer) - 1; @@ -3002,8 +3002,8 @@ void EditEncloseSelection(HWND hwnd, LPCWSTR pwszOpen, LPCWSTR pwszClose) if (StrIsNotEmpty(pwszOpen)) { WideCharToMultiByteStrg(Encoding_SciCP, pwszOpen, mszOpen); } if (StrIsNotEmpty(pwszClose)) { WideCharToMultiByteStrg(Encoding_SciCP, pwszClose, mszClose); } - const DocPos iLenOpen = StringCchLenA(mszOpen, COUNTOF(mszOpen)); - const DocPos iLenClose = StringCchLenA(mszClose, COUNTOF(mszClose)); + DocPos const iLenOpen = (DocPos)StringCchLenA(mszOpen, COUNTOF(mszOpen)); + DocPos const iLenClose = (DocPos)StringCchLenA(mszClose, COUNTOF(mszClose)); _ENTER_TARGET_TRANSACTION_; @@ -3042,7 +3042,7 @@ void EditToggleLineComments(HWND hwnd, LPCWSTR pwszComment, bool bInsertAtStart) if (StrIsNotEmpty(pwszComment)) { WideCharToMultiByte(Encoding_SciCP, 0, pwszComment, -1, mszComment, COUNTOF(mszComment), NULL, NULL); } - const DocPos cchComment = StringCchLenA(mszComment, COUNTOF(mszComment)); + DocPos const cchComment = (DocPos)StringCchLenA(mszComment, COUNTOF(mszComment)); if (cchComment == 0) { return; } @@ -3661,7 +3661,7 @@ void EditCompressBlanks(HWND hwnd) _LEAVE_TARGET_TRANSACTION_; - const DocPos iNewLen = StringCchLenA(pszOut, LocalSize(pszOut)); + DocPos const iNewLen = (DocPos)StringCchLenA(pszOut, LocalSize(pszOut)); if (iCurPos < iAnchorPos) { EditSelectEx(hwnd, iCurPos + iNewLen, iCurPos, -1, -1); @@ -4383,7 +4383,7 @@ void EditSortLines(HWND hwnd, int iSortFlags) } FreeMem(pLines); - DocPos const iResultLength = StringCchLenA(pmszResult, lenRes) + ((cEOLMode == SC_EOL_CRLF) ? 2 : 1); + DocPos const iResultLength = (DocPos)StringCchLenA(pmszResult, lenRes) + ((cEOLMode == SC_EOL_CRLF) ? 2 : 1); if (!bIsRectangular) { if (iAnchorPos > iCurPos) { iCurPos = iSelStart; @@ -6171,7 +6171,7 @@ bool EditReplace(HWND hwnd, LPCEDITFINDREPLACE lpefr) { DocPos _start = start; g_iReplacedOccurrences = 0; - const DocPos iPos = _FindInTarget(hwnd, lpefr->szFind, StringCchLenA(lpefr->szFind, FRMOD_NORM), + DocPos const iPos = _FindInTarget(hwnd, lpefr->szFind, (DocPos)StringCchLenA(lpefr->szFind, FRMOD_NORM), (int)(lpefr->fuFlags), &start, &end, false, false); // w/o selection, replacement string is put into current position @@ -6520,7 +6520,7 @@ void EditMarkAll(HWND hwnd, char* pszFind, int flags, DocPos rangeStart, DocPos flags |= (bMatchCase ? SCFIND_MATCHCASE : 0); } else { - iFindLength = StringCchLenA(pszFind, FNDRPL_BUFFER); + iFindLength = (DocPos)StringCchLenA(pszFind, FNDRPL_BUFFER); } if (iFindLength > 0) { @@ -6711,11 +6711,11 @@ void EditUpdateUrlHotspots(HWND hwnd, DocPos startPos, DocPos endPos, bool bActi "(?:\\([-A-Z0-9+&@#/%=~_|$?!:,.]*\\)|[-A-Z0-9+&@#/%=~_|$?!:,.])*" "(?:\\([-A-Z0-9+&@#/%=~_|$?!:,.]*\\)|[A-Z0-9+&@#/%=~_|$])"; - const int iRegExLen = (int)strlen(pszUrlRegEx); + int const iRegExLen = (int)StringCchLenA(pszUrlRegEx,0); if (startPos < 0) { // current line only - DocPos currPos = SciCall_GetCurrentPos(); - DocLn lineNo = SciCall_LineFromPosition(currPos); + DocPos const currPos = SciCall_GetCurrentPos(); + DocLn const lineNo = SciCall_LineFromPosition(currPos); startPos = SciCall_PositionFromLine(lineNo); endPos = SciCall_GetLineEndPosition(lineNo); } @@ -6726,11 +6726,11 @@ void EditUpdateUrlHotspots(HWND hwnd, DocPos startPos, DocPos endPos, bool bActi DocPos end = endPos; do { - DocPos iPos = _FindInTarget(hwnd, pszUrlRegEx, iRegExLen, SCFIND_NP3_REGEX, &start, &end, false, FRMOD_IGNORE); + DocPos const iPos = _FindInTarget(hwnd, pszUrlRegEx, iRegExLen, SCFIND_NP3_REGEX, &start, &end, false, FRMOD_IGNORE); - if (iPos < 0) + if (iPos < 0) { break; // not found - + } DocPos mlen = end - start; if ((mlen <= 0) || ((iPos + mlen) > endPos)) break; // wrong match @@ -7763,7 +7763,7 @@ void EditSetBookmarkList(HWND hwnd, LPCWSTR pszBookMarks) while (*p1) { const WCHAR* p2 = StrChr(p1, L';'); if (!p2) - p2 = StrEnd(p1); + p2 = StrEnd(p1,0); StringCchCopyNW(lnNum, COUNTOF(lnNum), p1, min((int)(p2 - p1), 16)); long long iLine = 0; if (swscanf_s(lnNum, L"%lld", &iLine) == 1) { diff --git a/src/Helpers.c b/src/Helpers.c index 5399be403..6e8cadac4 100644 --- a/src/Helpers.c +++ b/src/Helpers.c @@ -74,7 +74,7 @@ CHAR* StrCutIA(CHAR* s,const CHAR* pattern) do { p = StrStrIA(s,pattern); if (p) { - CHAR* q = p + strlen(pattern); + CHAR* q = p + StringCchLenA(pattern,0); while (*p != '\0') { *p++ = *q++; } } } while (p); @@ -87,7 +87,7 @@ WCHAR* StrCutIW(WCHAR* s,const WCHAR* pattern) do { p = StrStrIW(s,pattern); if (p) { - WCHAR* q = p + lstrlen(pattern); + WCHAR* q = p + StringCchLen(pattern,0); while (*p != L'\0') { *p++ = *q++; } } } while (p); @@ -114,7 +114,7 @@ bool StrDelChrA(LPSTR pszSource, LPCSTR pCharsToRemove) ++prem; } if (prem > pch) { - MoveMemory(pch, prem, sizeof(CHAR)*(strlen(prem) + 1)); + MoveMemory(pch, prem, sizeof(CHAR)*(StringCchLenA(prem,0) + 1)); } ++pch; } @@ -166,7 +166,7 @@ bool SetClipboardTextW(HWND hwnd, LPCWSTR pszTextW) return false; } - int cchTextW = lstrlen(pszTextW) + 1; + size_t cchTextW = StringCchLenW(pszTextW,0) + 1; HANDLE hData = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, sizeof(WCHAR) * cchTextW); WCHAR* pszNew = GlobalLock(hData); @@ -204,7 +204,7 @@ int IniSectionGetString( return((int)StringCchLen(lpReturnedString, cchReturnedString)); } else - p = StrEnd(p) + 1; + p = StrEnd(p,0) + 1; } } StringCchCopyN(lpReturnedString, cchReturnedString, lpDefault, cchReturnedString); @@ -230,7 +230,7 @@ int IniSectionGetInt(LPCWSTR lpCachedIniSection, LPCWSTR lpName, int iDefault) return(iDefault); } else - p = StrEnd(p) + 1; + p = StrEnd(p,0) + 1; } } return(iDefault); @@ -255,7 +255,7 @@ UINT IniSectionGetUInt(LPCWSTR lpCachedIniSection, LPCWSTR lpName, UINT uDefault return(uDefault); } else - p = StrEnd(p) + 1; + p = StrEnd(p,0) + 1; } } return(uDefault); @@ -279,7 +279,7 @@ DocPos IniSectionGetPos(LPCWSTR lpCachedIniSection, LPCWSTR lpName, DocPos posDe return (DocPos)posDefault; } else - p = StrEnd(p) + 1; + p = StrEnd(p,0) + 1; } } return (DocPos)posDefault; @@ -292,15 +292,15 @@ bool IniSectionSetString(LPWSTR lpCachedIniSection,LPCWSTR lpName,LPCWSTR lpStri WCHAR* p = lpCachedIniSection; if (p) { while (*p) { - p = StrEnd(p) + 1; + p = StrEnd(p,0) + 1; } StringCchPrintf(tch,COUNTOF(tch),L"%s=%s",lpName,lpString); StringCchCopy(p,COUNTOF(tch),tch); - p = StrEnd(p) + 1; - *p = 0; - return(true); + p = StrEnd(p,0) + 1; + *p = L'\0'; + return true; } - return(false); + return false; } @@ -330,7 +330,7 @@ DWORD GetLastErrorToMsgBox(LPWSTR lpszFunction, DWORD dwErrID) // Display the error message and exit the process LPVOID lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT, - (lstrlen((LPCWSTR)lpMsgBuf) + lstrlen((LPCWSTR)lpszFunction) + 80) * sizeof(WCHAR)); + (StringCchLenW((LPCWSTR)lpMsgBuf,0) + StringCchLenW((LPCWSTR)lpszFunction,0) + 80) * sizeof(WCHAR)); StringCchPrintf((LPWSTR)lpDisplayBuf, LocalSize(lpDisplayBuf) / sizeof(WCHAR), L"Error: '%s' failed with error id %d:\n%s.\n", lpszFunction, dwErrID, lpMsgBuf); @@ -1144,7 +1144,7 @@ bool StrLTrim(LPWSTR pszSource,LPCWSTR pszTrimChars) LPWSTR psz = pszSource; while (StrChrI(pszTrimChars, *psz)) { ++psz; } - MoveMemory(pszSource,psz,sizeof(WCHAR)*(lstrlen(psz) + 1)); + MoveMemory(pszSource,psz,sizeof(WCHAR)*(StringCchLenW(psz,0) + 1)); return true; } @@ -1164,10 +1164,10 @@ bool TrimStringA(LPSTR lpString) LPSTR psz = lpString; while (*psz == ' ') { psz = CharNextA(psz); } - MoveMemory(lpString, psz, sizeof(CHAR)*(strlen(psz) + 1)); + MoveMemory(lpString, psz, sizeof(CHAR)*(StringCchLenA(psz,0) + 1)); // Trim right - psz = StrEndA(lpString); + psz = StrEndA(lpString,0); while (*(psz = CharPrevA(lpString, psz)) == ' ') { *psz = '\0'; } return true; @@ -1187,10 +1187,10 @@ bool TrimStringW(LPWSTR lpString) LPWSTR psz = lpString; while (*psz == L' ') { psz = CharNextW(psz); } - MoveMemory(lpString,psz,sizeof(WCHAR)*(lstrlen(psz) + 1)); + MoveMemory(lpString,psz,sizeof(WCHAR)*(StringCchLenA(psz,0) + 1)); // Trim right - psz = StrEndW(lpString); + psz = StrEndW(lpString,0); while (*(psz = CharPrevW(lpString, psz)) == L' ') { *psz = L'\0'; } return true; @@ -1251,7 +1251,7 @@ bool ExtractFirstArgument(LPCWSTR lpArgs, LPWSTR lpArg1, LPWSTR lpArg2, int len) // void PrepareFilterStr(LPWSTR lpFilter) { - LPWSTR psz = StrEnd(lpFilter); + LPWSTR psz = StrEnd(lpFilter,0); while (psz != lpFilter) { if (*(psz = CharPrev(lpFilter,psz)) == L'|') @@ -1384,7 +1384,7 @@ DWORD_PTR SHGetFileInfo2(LPCWSTR pszPath,DWORD dwFileAttributes, // // FormatNumberStr() // -int FormatNumberStr(LPWSTR lpNumberStr) +size_t FormatNumberStr(LPWSTR lpNumberStr) { static WCHAR szSep[5] = { L'\0' }; static WCHAR szGrp[11] = { L'\0' }; @@ -1410,18 +1410,18 @@ int FormatNumberStr(LPWSTR lpNumberStr) swscanf_s(szGrp, L"%i;%i;%i;%i", &iPlace[0], &iPlace[1], &iPlace[2], &iPlace[3]); } if (iPlace[0] <= 0) { - return lstrlen(lpNumberStr); + return StringCchLen(lpNumberStr,0); } - if (lstrlen(lpNumberStr) > iPlace[0]) { + if (StringCchLen(lpNumberStr,0) > iPlace[0]) { - WCHAR* ch = StrEnd(lpNumberStr); + WCHAR* ch = StrEnd(lpNumberStr,0); int iCnt = 0; int i = 0; while ((ch = CharPrev(lpNumberStr, ch)) != lpNumberStr) { if (((++iCnt) % iPlace[i]) == 0) { - MoveMemory(ch + 1, ch, sizeof(WCHAR)*(lstrlen(ch) + 1)); + MoveMemory(ch + 1, ch, sizeof(WCHAR)*(StringCchLen(ch,0) + 1)); *ch = szSep[0]; i = (i < 3) ? (i + 1) : 3; if (iPlace[i] == 0) { --i; } else if (iPlace[i] < 0) { break; } @@ -1429,7 +1429,7 @@ int FormatNumberStr(LPWSTR lpNumberStr) } } } - return lstrlen(lpNumberStr); + return StringCchLen(lpNumberStr,0); } @@ -2226,7 +2226,7 @@ void UrlUnescapeEx(LPWSTR lpURL, LPWSTR lpUnescaped, DWORD* pcchUnescaped) int posIn = 0; WCHAR buf[5] = { L'\0' }; - int lastEsc = lstrlen(lpURL) - 2; + size_t lastEsc = StringCchLenW(lpURL,0) - 2; int code; while ((posIn < lastEsc) && (posOut < outLen)) @@ -2334,7 +2334,7 @@ int ReadVectorFromString(LPCWSTR wchStrg, int iVector[], int iCount, int iMin, i // ensure single spaces only WCHAR *p = StrStr(wchTmpBuff, L" "); while (p) { - MoveMemory((WCHAR*)p, (WCHAR*)p + 1, (lstrlen(p) + 1) * sizeof(WCHAR)); + MoveMemory((WCHAR*)p, (WCHAR*)p + 1, (StringCchLenW(p,0) + 1) * sizeof(WCHAR)); p = StrStr(wchTmpBuff, L" "); // next } // separate values @@ -2356,7 +2356,7 @@ int ReadVectorFromString(LPCWSTR wchStrg, int iVector[], int iCount, int iMin, i iVector[n++] = clampi(iValue, iMin, iMax); } } - p = StrEnd(p) + 1; + p = StrEnd(p,0) + 1; } return n; } diff --git a/src/Helpers.h b/src/Helpers.h index d57b8bd31..8e4433d46 100644 --- a/src/Helpers.h +++ b/src/Helpers.h @@ -62,46 +62,43 @@ void DbgLog(const char *fmt, ...); // ============================================================================ // swap -static inline void swapi(int* a, int* b) { int t = *a; *a = *b; *b = t; } -static inline void swapos(DocPos* a, DocPos* b) { DocPos t = *a; *a = *b; *b = t; } +inline void swapi(int* a, int* b) { int t = *a; *a = *b; *b = t; } +inline void swapos(DocPos* a, DocPos* b) { DocPos t = *a; *a = *b; *b = t; } // clamp -static inline int clampi(int x, int lower, int upper) { +inline int clampi(int x, int lower, int upper) { return (x < lower) ? lower : ((x > upper) ? upper : x); } -static inline unsigned clampu(unsigned x, unsigned lower, unsigned upper) { +inline unsigned clampu(unsigned x, unsigned lower, unsigned upper) { return (x < lower) ? lower : ((x > upper) ? upper : x); } // Is the character an octal digit? -static inline bool IsDigit(CHAR ch) { return ((ch >= '0') && (ch <= '9')); } -static inline bool IsDigitW(WCHAR wch) { return ((wch >= L'0') && (wch <= L'9')); } +inline bool IsDigitA(CHAR ch) { return ((ch >= '0') && (ch <= '9')); } +inline bool IsDigitW(WCHAR wch) { return ((wch >= L'0') && (wch <= L'9')); } // Is the character a white space char? -static inline bool IsBlankChar(CHAR ch) { return ((ch == ' ') || (ch == '\t')); } -static inline bool IsBlankCharW(WCHAR wch) { return ((wch == L' ') || (wch == L'\t')); } +inline bool IsBlankChar(CHAR ch) { return ((ch == ' ') || (ch == '\t')); } +inline bool IsBlankCharW(WCHAR wch) { return ((wch == L' ') || (wch == L'\t')); } -static inline int float2int(float f) { return (int)lroundf(f); } -static inline float Round10th(float f) { return (float)float2int(f * 10.0f) / 10; } -static inline bool HasNonZeroFraction(float f) { return ((float2int(f * 10.0f) % 10) != 0); } +inline int float2int(float f) { return (int)lroundf(f); } +inline float Round10th(float f) { return (float)float2int(f * 10.0f) / 10; } +inline bool HasNonZeroFraction(float f) { return ((float2int(f * 10.0f) % 10) != 0); } // direct heap allocation -static inline LPVOID AllocMem(size_t numBytes, DWORD dwFlags) -{ +inline LPVOID AllocMem(size_t numBytes, DWORD dwFlags) { return HeapAlloc(GetProcessHeap(), (dwFlags | HEAP_GENERATE_EXCEPTIONS), numBytes); } -static inline bool FreeMem(LPVOID lpMemory) -{ +inline bool FreeMem(LPVOID lpMemory) { return ((lpMemory != NULL) ? HeapFree(GetProcessHeap(), 0, lpMemory) : true); } -static inline size_t SizeOfMem(LPVOID lpMemory) -{ +inline size_t SizeOfMem(LPVOID lpMemory) { return ((lpMemory != NULL) ? HeapSize(GetProcessHeap(), 0, lpMemory) : 0); } @@ -113,7 +110,7 @@ static inline size_t SizeOfMem(LPVOID lpMemory) #define IniSetString(lpSection,lpName,lpString) WritePrivateProfileString(lpSection,lpName,(lpString),g_wchIniFile) #define IniDeleteSection(lpSection) WritePrivateProfileSection(lpSection,NULL,g_wchIniFile) -static inline bool IniSetInt(LPCWSTR lpSection, LPCWSTR lpName, int i) { +inline bool IniSetInt(LPCWSTR lpSection, LPCWSTR lpName, int i) { WCHAR tch[32] = { L'\0' }; StringCchPrintf(tch, COUNTOF(tch), L"%i", i); return IniSetString(lpSection, lpName, tch); } @@ -125,7 +122,7 @@ int IniSectionGetString(LPCWSTR, LPCWSTR, LPCWSTR, LPWSTR, int); int IniSectionGetInt(LPCWSTR, LPCWSTR, int); UINT IniSectionGetUInt(LPCWSTR, LPCWSTR, UINT); DocPos IniSectionGetPos(LPCWSTR, LPCWSTR, DocPos); -static inline bool IniSectionGetBool(LPCWSTR lpCachedIniSection, LPCWSTR lpName, bool bDefault) { +inline bool IniSectionGetBool(LPCWSTR lpCachedIniSection, LPCWSTR lpName, bool bDefault) { return (IniSectionGetInt(lpCachedIniSection, lpName, ((bDefault) ? 1 : 0)) ? true : false); } @@ -137,14 +134,13 @@ inline bool IniSectionSetInt(LPWSTR lpCachedIniSection,LPCWSTR lpName, int i) { inline bool IniSectionSetBool(LPWSTR lpCachedIniSection, LPCWSTR lpName, bool b) { return IniSectionSetInt(lpCachedIniSection, lpName, (b ? 1 : 0)); } -inline bool IniSectionSetPos(LPWSTR lpCachedIniSection, LPCWSTR lpName, DocPos pos) -{ +inline bool IniSectionSetPos(LPWSTR lpCachedIniSection, LPCWSTR lpName, DocPos pos){ WCHAR tch[64] = { L'\0' }; StringCchPrintf(tch, COUNTOF(tch), L"%td", (long long)pos); return IniSectionSetString(lpCachedIniSection, lpName, tch); } // ---------------------------------------------------------------------------- -static inline COLORREF GetBackgroundColor(HWND hwnd) { return GetBkColor(GetDC(hwnd)); } +inline COLORREF GetBackgroundColor(HWND hwnd) { return GetBkColor(GetDC(hwnd)); } DWORD GetLastErrorToMsgBox(LPWSTR lpszFunction, DWORD dwErrID); @@ -259,7 +255,7 @@ DWORD GetLongPathNameEx(LPWSTR,DWORD); DWORD NormalizePathEx(LPWSTR,int); DWORD_PTR SHGetFileInfo2(LPCWSTR,DWORD,SHFILEINFO*,UINT,UINT); -int FormatNumberStr(LPWSTR); +size_t FormatNumberStr(LPWSTR); bool SetDlgItemIntEx(HWND,int,UINT); @@ -342,23 +338,16 @@ WCHAR* StrNextTokW(WCHAR*, const WCHAR*); // ---------------------------------------------------------------------------- -#define StrEndW(pStart) (pStart + lstrlen(pStart)) -#define StrEndA(pStart) (pStart + strlen(pStart)) - -#if defined(UNICODE) || defined(_UNICODE) -#define StrEnd(s) StrEndW(s) -#else -#define StrEnd(s) StrEndA(s) -#endif - -// ---------------------------------------------------------------------------- - bool StrDelChrA(LPSTR pszSource, LPCSTR pCharsToRemove); //==== StrSafe lstrlen() ======================================================= -inline DocPos StringCchLenA(LPCSTR s,size_t m) { size_t len; return (DocPos)(!s ? 0 : (SUCCEEDED(StringCchLengthA(s, m, &len)) ? len : m)); } -inline DocPos StringCchLenW(LPCWSTR s,size_t m) { size_t len; return (DocPos)(!s ? 0 : (SUCCEEDED(StringCchLengthW(s, m, &len)) ? len : m)); } +inline size_t StringCchLenA(LPCSTR s, size_t n) { + size_t len; return (size_t)(!s ? 0 : (!n ? strlen(s) : (SUCCEEDED(StringCchLengthA(s, n, &len)) ? len : n))); +} +inline size_t StringCchLenW(LPCWSTR s, size_t n) { + size_t len; return (size_t)(!s ? 0 : (!n ? lstrlen(s) : (SUCCEEDED(StringCchLengthW(s, n, &len)) ? len : n))); +} #if defined(UNICODE) || defined(_UNICODE) #define StringCchLen(s,n) StringCchLenW((s),(n)) @@ -366,6 +355,23 @@ inline DocPos StringCchLenW(LPCWSTR s,size_t m) { size_t len; return (DocPos)(!s #define StringCchLen(s,n) StringCchLenA((s),(n)) #endif +// ---------------------------------------------------------------------------- + +inline char* StrEndA(const char* pStart, size_t siz) { + return (char*)(pStart + StringCchLenA(pStart, siz)); +} + +inline WCHAR* StrEndW(const WCHAR* pStart, size_t siz) { + return (WCHAR*)(pStart + StringCchLenW(pStart, siz)); +} + +#if defined(UNICODE) || defined(_UNICODE) +#define StrEnd(s,n) StrEndW((s),(n)) +#else +#define StrEnd(s,n) StrEndA((s),(n)) +#endif + + //==== StrSafe lstrcmp(),lstrcmpi() ============================================= inline int _StringCchCmpNA(PCNZCH s1, DocPos l1,PCNZCH s2, DocPos l2) { @@ -383,7 +389,7 @@ inline int _StringCchCmpINA(PCNZCH s1, DocPos l1,PCNZCH s2, DocPos l2) #define StringCchCompareINA(s1,l1,s2,l2) _StringCchCmpINA((s1),(l1),(s2),(l2)) #define StringCchCompareIXA(s1,s2) _StringCchCmpINA((s1),-1,(s2),-1) -inline int _StringCchCmpNW(PCNZWCH s1, DocPos l1,PCNZWCH s2, DocPos l2) { +inline int _StringCchCmpNW(PCNZWCH s1, DocPos l1, PCNZWCH s2, DocPos l2) { return (CompareStringW(LOCALE_INVARIANT,0,s1,(l1 >= 0 ? (int)StringCchLenW(s1,l1) : -1), s2,(l2 >= 0 ? (int)StringCchLenW(s2,l2) : -1)) - CSTR_EQUAL); } @@ -412,8 +418,8 @@ inline int _StringCchCmpINW(PCNZWCH s1, DocPos l1,PCNZWCH s2, DocPos l2) { //==== StrIs(Not)Empty() ============================================= -static inline bool StrIsEmptyA(LPCSTR s) { return ((s == NULL) || (*s == '\0')); } -static inline bool StrIsEmptyW(LPCWSTR s) { return ((s == NULL) || (*s == L'\0')); } +inline bool StrIsEmptyA(LPCSTR s) { return ((s == NULL) || (*s == '\0')); } +inline bool StrIsEmptyW(LPCWSTR s) { return ((s == NULL) || (*s == L'\0')); } #if defined(UNICODE) || defined(_UNICODE) #define StrIsEmpty(s) StrIsEmptyW(s) diff --git a/src/Notepad3.c b/src/Notepad3.c index 7c373b1ab..8537a34fd 100644 --- a/src/Notepad3.c +++ b/src/Notepad3.c @@ -302,8 +302,8 @@ int yFindReplaceDlg; int xCustomSchemesDlg; int yCustomSchemesDlg; - -LPWSTR lpFileList[32] = { NULL }; +#define FILE_LIST_SIZE 32 +LPWSTR lpFileList[FILE_LIST_SIZE] = { NULL }; int cFileList = 0; int cchiFileList = 0; LPWSTR lpFileArg = NULL; @@ -2506,7 +2506,7 @@ LRESULT MsgCopyData(HWND hwnd, WPARAM wParam, LPARAM lParam) if (params->flagLexerSpecified) { if (params->iInitialLexer < 0) { WCHAR wchExt[32] = L"."; - StringCchCopyN(CharNext(wchExt), 32, StrEnd(¶ms->wchData) + 1, 31); + StringCchCopyN(CharNext(wchExt), 32, StrEnd(¶ms->wchData,0) + 1, 31); Style_SetLexerFromName(g_hwndEdit, ¶ms->wchData, wchExt); } else if (params->iInitialLexer >= 0 && params->iInitialLexer < NUMLEXERS) @@ -2514,7 +2514,7 @@ LRESULT MsgCopyData(HWND hwnd, WPARAM wParam, LPARAM lParam) } if (params->flagTitleExcerpt) { - StringCchCopyN(szTitleExcerpt, COUNTOF(szTitleExcerpt), StrEnd(¶ms->wchData) + 1, COUNTOF(szTitleExcerpt)); + StringCchCopyN(szTitleExcerpt, COUNTOF(szTitleExcerpt), StrEnd(¶ms->wchData,0) + 1, COUNTOF(szTitleExcerpt)); } } // reset @@ -3042,7 +3042,7 @@ LRESULT MsgInitMenu(HWND hwnd, WPARAM wParam, LPARAM lParam) } EnableCmd(hmenu, CMD_OPEN_HYPERLINK, bIsHLink); - i = StringCchLenW(g_tchAdministrationExe, COUNTOF(g_tchAdministrationExe)); + i = (int)StringCchLenW(g_tchAdministrationExe, COUNTOF(g_tchAdministrationExe)); EnableCmd(hmenu, IDM_HELP_ADMINEXE, i); return 0LL; @@ -5940,14 +5940,14 @@ void OpenHotSpotURL(DocPos position, bool bForceBrowser) MultiByteToWideCharStrg(Encoding_SciCP, chURL, wchURL); const WCHAR* chkPreFix = L"file://"; - const int len = lstrlen(chkPreFix); + size_t const len = StringCchLenW(chkPreFix,0); if (!bForceBrowser && (StrStrIW(wchURL, chkPreFix) == wchURL)) { WCHAR* szFileName = &(wchURL[len]); StrTrimW(szFileName, L"/"); - PathCanonicalizeEx(szFileName, COUNTOF(wchURL) - len); + PathCanonicalizeEx(szFileName, COUNTOF(wchURL) - (int)len); if (PathIsDirectory(szFileName)) { @@ -6505,11 +6505,11 @@ LRESULT MsgNotify(HWND hwnd, WPARAM wParam, LPARAM lParam) char chBuf[80]; if (g_iExprError == 0) { StringCchPrintfA(chBuf, COUNTOF(chBuf), "%.6G", g_dExpression); - SciCall_CopyText((DocPos)strlen(chBuf), chBuf); + SciCall_CopyText((DocPos)StringCchLenA(chBuf,80), chBuf); } else if (g_iExprError > 0) { StringCchPrintfA(chBuf, COUNTOF(chBuf), "^[%i]", g_iExprError); - SciCall_CopyText((DocPos)strlen(chBuf), chBuf); + SciCall_CopyText((DocPos)StringCchLenA(chBuf,80), chBuf); } else SciCall_CopyText(0, ""); @@ -7227,15 +7227,15 @@ void ParseCommandLine() // Good old console can also send args separated by Tabs StrTab2Space(lpCmdLine); - int len = lstrlen(lpCmdLine) + 2; + DocPos const len = (DocPos)(StringCchLenW(lpCmdLine,0) + 2UL); lp1 = LocalAlloc(LPTR,sizeof(WCHAR)*len); lp2 = LocalAlloc(LPTR,sizeof(WCHAR)*len); lp3 = LocalAlloc(LPTR,sizeof(WCHAR)*len); // Start with 2nd argument - ExtractFirstArgument(lpCmdLine,lp1,lp3,len); + ExtractFirstArgument(lpCmdLine,lp1,lp3,(int)len); - while (bContinue && ExtractFirstArgument(lp3,lp1,lp2,len)) + while (bContinue && ExtractFirstArgument(lp3,lp1,lp2,(int)len)) { // options if (!bIsFileArg && (StringCchCompareN(lp1,len,L"+",-1) == 0)) { @@ -7329,7 +7329,7 @@ void ParseCommandLine() case L'F': if (*(lp1+1) == L'0' || *CharUpper(lp1+1) == L'O') StringCchCopy(g_wchIniFile,COUNTOF(g_wchIniFile),L"*?"); - else if (ExtractFirstArgument(lp2,lp1,lp2,len)) { + else if (ExtractFirstArgument(lp2,lp1,lp2,(int)len)) { StringCchCopyN(g_wchIniFile,COUNTOF(g_wchIniFile),lp1,len); TrimStringW(g_wchIniFile); PathUnquoteSpaces(g_wchIniFile); @@ -7359,7 +7359,7 @@ void ParseCommandLine() lp += 1; else if (bIsNotepadReplacement) { if (*(lp1+1) == L'T') - ExtractFirstArgument(lp2,lp1,lp2,len); + ExtractFirstArgument(lp2,lp1,lp2,(int)len); break; } if (*(lp+1) == L'0' || *CharUpper(lp+1) == L'O') { @@ -7405,7 +7405,7 @@ void ParseCommandLine() p = CharNext(p); } } - else if (ExtractFirstArgument(lp2,lp1,lp2,len)) { + else if (ExtractFirstArgument(lp2,lp1,lp2,(int)len)) { int itok = swscanf_s(lp1,L"%i,%i,%i,%i,%i",&g_WinInfo.x,&g_WinInfo.y,&g_WinInfo.cx,&g_WinInfo.cy,&g_WinInfo.max); if (itok == 4 || itok == 5) { // scan successful @@ -7422,7 +7422,7 @@ void ParseCommandLine() break; case L'T': - if (ExtractFirstArgument(lp2,lp1,lp2,len)) { + if (ExtractFirstArgument(lp2,lp1,lp2,(int)len)) { StringCchCopyN(szTitleExcerpt,COUNTOF(szTitleExcerpt),lp1,len); fKeepTitleExcerpt = 1; } @@ -7437,7 +7437,7 @@ void ParseCommandLine() break; case L'E': - if (ExtractFirstArgument(lp2,lp1,lp2,len)) { + if (ExtractFirstArgument(lp2,lp1,lp2,(int)len)) { if (lpEncodingArg) LocalFree(lpEncodingArg); lpEncodingArg = StrDup(lp1); @@ -7445,7 +7445,7 @@ void ParseCommandLine() break; case L'G': - if (ExtractFirstArgument(lp2,lp1,lp2,len)) { + if (ExtractFirstArgument(lp2,lp1,lp2,(int)len)) { int itok = swscanf_s(lp1,L"%i,%i",&iInitialLine,&iInitialColumn); if (itok == 1 || itok == 2) { // scan successful @@ -7467,7 +7467,7 @@ void ParseCommandLine() if (StrChr(lp1,L'B')) bTransBS = true; - if (ExtractFirstArgument(lp2,lp1,lp2,len)) { + if (ExtractFirstArgument(lp2,lp1,lp2,(int)len)) { if (lpMatchArg) LocalFree(lpMatchArg); lpMatchArg = StrDup(lp1); @@ -7501,7 +7501,7 @@ void ParseCommandLine() break; case L'S': - if (ExtractFirstArgument(lp2,lp1,lp2,len)) { + if (ExtractFirstArgument(lp2,lp1,lp2,(int)len)) { if (lpSchemeArg) LocalFree(lpSchemeArg); lpSchemeArg = StrDup(lp1); @@ -7541,7 +7541,7 @@ void ParseCommandLine() break; case L'Z': - ExtractFirstArgument(lp2,lp1,lp2,len); + ExtractFirstArgument(lp2,lp1,lp2,(int)len); g_flagMultiFileArg = 1; bIsNotepadReplacement = true; break; @@ -7568,7 +7568,7 @@ void ParseCommandLine() { LPWSTR lpFileBuf = LocalAlloc(LPTR,sizeof(WCHAR)*len); - cchiFileList = lstrlen(lpCmdLine) - lstrlen(lp3); + cchiFileList = (int)(StringCchLenW(lpCmdLine, len-2) - StringCchLenW(lp3,len)); if (lpFileArg) { FreeMem(lpFileArg); @@ -7591,7 +7591,7 @@ void ParseCommandLine() StrTrim(lpFileArg,L" \""); - while (cFileList < 32 && ExtractFirstArgument(lp3,lpFileBuf,lp3,len)) { + while ((cFileList < FILE_LIST_SIZE) && ExtractFirstArgument(lp3,lpFileBuf,lp3,(int)len)) { PathQuoteSpaces(lpFileBuf); lpFileList[cFileList++] = StrDup(lpFileBuf); } @@ -7819,7 +7819,7 @@ int TestIniFile() { return(0); } - if (PathIsDirectory(g_wchIniFile) || *CharPrev(g_wchIniFile,StrEnd(g_wchIniFile)) == L'\\') { + if (PathIsDirectory(g_wchIniFile) || *CharPrev(g_wchIniFile,StrEnd(g_wchIniFile, COUNTOF(g_wchIniFile))) == L'\\') { WCHAR wchModule[MAX_PATH] = { L'\0' }; GetModuleFileName(NULL,wchModule,COUNTOF(wchModule)); PathCchAppend(g_wchIniFile,COUNTOF(g_wchIniFile),PathFindFileName(wchModule)); @@ -7981,7 +7981,7 @@ static void __fastcall _UpdateToolbarDelayed() EnableTool(IDT_EDIT_FIND, b2); //EnableTool(IDT_EDIT_FINDNEXT,b2); - //EnableTool(IDT_EDIT_FINDPREV,b2 && strlen(g_efrData.szFind)); + //EnableTool(IDT_EDIT_FINDPREV,b2 && StringCchLenA(g_efrData.szFind,0)); EnableTool(IDT_EDIT_REPLACE, b2 && !ro); EnableTool(IDT_EDIT_CUT, !b1 && !ro); @@ -8008,7 +8008,7 @@ static LONG __fastcall _StatusCalcPaneWidth(HWND hwnd, LPCWSTR lpsz) int const mmode = SetMapMode(hdc, MM_TEXT); SIZE size = { 0L, 0L }; - GetTextExtentPoint32(hdc, lpsz, lstrlen(lpsz), &size); + GetTextExtentPoint32(hdc, lpsz, (int)StringCchLenW(lpsz,0), &size); SetMapMode(hdc, mmode); SelectObject(hdc, hfold); @@ -8177,10 +8177,10 @@ static double __fastcall _InterpRectSelTinyExpr(int* piExprError) if (!StrIsEmptyA(tmpRectSelN)) { - if (IsDigit(tmpRectSelN[0]) && bLastCharWasDigit) { + if (IsDigitA(tmpRectSelN[0]) && bLastCharWasDigit) { StringCchCatA(g_pTempLineBufferMain, tmpLineBufSize, "+"); // default: add numbers } - bLastCharWasDigit = IsDigit(tmpRectSelN[strlen(tmpRectSelN) - 1]); + bLastCharWasDigit = IsDigitA(tmpRectSelN[StringCchLenA(tmpRectSelN,COUNTOF(tmpRectSelN)) - 1]); StringCchCatA(g_pTempLineBufferMain, tmpLineBufSize, tmpRectSelN); } } @@ -9527,10 +9527,10 @@ bool FileSave(bool bSaveAlways,bool bAsk,bool bSaveAs,bool bSaveCopy) //~Encoding_Current(fileEncoding); // save should not change encoding WCHAR szArguments[2048] = { L'\0' }; LPWSTR lpCmdLine = GetCommandLine(); - int wlen = lstrlen(lpCmdLine) + 2; + size_t const wlen = StringCchLenW(lpCmdLine,0) + 2; LPWSTR lpExe = LocalAlloc(LPTR,sizeof(WCHAR)*wlen); LPWSTR lpArgs = LocalAlloc(LPTR,sizeof(WCHAR)*wlen); - ExtractFirstArgument(lpCmdLine,lpExe,lpArgs,wlen); + ExtractFirstArgument(lpCmdLine,lpExe,lpArgs,(int)wlen); // remove relaunch elevated, we are doing this here already lpArgs = StrCutI(lpArgs,L"/u "); lpArgs = StrCutI(lpArgs,L"-u "); @@ -9796,17 +9796,17 @@ bool ActivatePrevInst() SetForegroundWindow(hwnd); - DWORD cb = sizeof(np3params); - if (lpSchemeArg) - cb += (lstrlen(lpSchemeArg) + 1) * sizeof(WCHAR); - + size_t cb = sizeof(np3params); + if (lpSchemeArg) { + cb += ((StringCchLen(lpSchemeArg, 0) + 1) * sizeof(WCHAR)); + } LPnp3params params = AllocMem(cb, HEAP_ZERO_MEMORY); params->flagFileSpecified = false; params->flagChangeNotify = 0; params->flagQuietCreate = false; params->flagLexerSpecified = g_flagLexerSpecified; if (g_flagLexerSpecified && lpSchemeArg) { - StringCchCopy(StrEnd(¶ms->wchData)+1,(lstrlen(lpSchemeArg)+1),lpSchemeArg); + StringCchCopy(StrEnd(¶ms->wchData,0)+1,(StringCchLen(lpSchemeArg,0)+1),lpSchemeArg); params->iInitialLexer = -1; } else @@ -9890,24 +9890,24 @@ bool ActivatePrevInst() StringCchCopy(lpFileArg, FILE_ARG_BUF, tchTmp); } - DWORD cb = sizeof(np3params); - cb += (lstrlen(lpFileArg) + 1) * sizeof(WCHAR); + size_t cb = sizeof(np3params); + cb += (StringCchLenW(lpFileArg,0) + 1) * sizeof(WCHAR); if (lpSchemeArg) - cb += (lstrlen(lpSchemeArg) + 1) * sizeof(WCHAR); + cb += (StringCchLenW(lpSchemeArg,0) + 1) * sizeof(WCHAR); - int cchTitleExcerpt = (int)StringCchLenW(szTitleExcerpt,COUNTOF(szTitleExcerpt)); + size_t cchTitleExcerpt = StringCchLenW(szTitleExcerpt,COUNTOF(szTitleExcerpt)); if (cchTitleExcerpt) { cb += (cchTitleExcerpt + 1) * sizeof(WCHAR); } LPnp3params params = AllocMem(cb, HEAP_ZERO_MEMORY); params->flagFileSpecified = true; - StringCchCopy(¶ms->wchData,lstrlen(lpFileArg)+1,lpFileArg); + StringCchCopy(¶ms->wchData, StringCchLenW(lpFileArg,0)+1,lpFileArg); params->flagChangeNotify = g_flagChangeNotify; params->flagQuietCreate = g_flagQuietCreate; params->flagLexerSpecified = g_flagLexerSpecified; if (g_flagLexerSpecified && lpSchemeArg) { - StringCchCopy(StrEnd(¶ms->wchData)+1,lstrlen(lpSchemeArg)+1,lpSchemeArg); + StringCchCopy(StrEnd(¶ms->wchData,0)+1, StringCchLen(lpSchemeArg,0)+1,lpSchemeArg); params->iInitialLexer = -1; } else { @@ -9922,7 +9922,7 @@ bool ActivatePrevInst() params->flagSetEOLMode = g_flagSetEOLMode; if (cchTitleExcerpt) { - StringCchCopy(StrEnd(¶ms->wchData)+1,cchTitleExcerpt+1,szTitleExcerpt); + StringCchCopy(StrEnd(¶ms->wchData,0)+1,cchTitleExcerpt+1,szTitleExcerpt); params->flagTitleExcerpt = 1; } else { @@ -9964,14 +9964,14 @@ bool RelaunchMultiInst() { PROCESS_INFORMATION pi; LPWSTR lpCmdLineNew = StrDup(GetCommandLine()); - int len = lstrlen(lpCmdLineNew) + 1; + size_t len = StringCchLen(lpCmdLineNew,0) + 1UL; LPWSTR lp1 = LocalAlloc(LPTR,sizeof(WCHAR)*len); LPWSTR lp2 = LocalAlloc(LPTR,sizeof(WCHAR)*len); StrTab2Space(lpCmdLineNew); StringCchCopy(lpCmdLineNew + cchiFileList,2,L""); - pwch = CharPrev(lpCmdLineNew,StrEnd(lpCmdLineNew)); + pwch = CharPrev(lpCmdLineNew,StrEnd(lpCmdLineNew,len)); while (*pwch == L' ' || *pwch == L'-' || *pwch == L'+') { *pwch = L' '; pwch = CharPrev(lpCmdLineNew,pwch); @@ -10027,13 +10027,13 @@ bool RelaunchElevated(LPWSTR lpArgs) { GetStartupInfo(&si); LPWSTR lpCmdLine = GetCommandLine(); - int wlen = lstrlen(lpCmdLine) + 2; + size_t wlen = StringCchLenW(lpCmdLine,0) + 2UL; WCHAR lpExe[MAX_PATH + 2] = { L'\0' }; WCHAR szArgs[2032] = { L'\0' }; WCHAR szArguments[2032] = { L'\0' }; - ExtractFirstArgument(lpCmdLine,lpExe,szArgs,wlen); + ExtractFirstArgument(lpCmdLine,lpExe,szArgs,(int)wlen); if (lpArgs) { StringCchCopy(szArgs,COUNTOF(szArgs),lpArgs); // override diff --git a/src/Print.cpp b/src/Print.cpp index 5ba50e131..d824c8e19 100644 --- a/src/Print.cpp +++ b/src/Print.cpp @@ -377,7 +377,7 @@ extern "C" bool EditPrint(HWND hwnd,LPCWSTR pszDocTitle,LPCWSTR pszPageFormat) { ExtTextOut(hdc, frPrint.rc.left + 5, frPrint.rc.top - headerLineHeight / 2, /*ETO_OPAQUE*/0, &rcw, pszDocTitle, - lstrlen(pszDocTitle), nullptr); + (UINT)StringCchLenW(pszDocTitle,0), nullptr); } // Print date in header diff --git a/src/Styles.c b/src/Styles.c index 2bd580c53..db45eddd4 100644 --- a/src/Styles.c +++ b/src/Styles.c @@ -4319,7 +4319,7 @@ PEDITLEXER __fastcall Style_MatchLexer(LPCWSTR lpszMatch,bool bCheckNames) { if (p2) *p2 = L'\0'; else - p2 = StrEnd(p1); + p2 = StrEnd(p1,0); StrTrim(p1,L" ."); if (StringCchCompareIX(p1,lpszMatch) == 0) return(g_pLexArray[i]); @@ -4328,7 +4328,7 @@ PEDITLEXER __fastcall Style_MatchLexer(LPCWSTR lpszMatch,bool bCheckNames) { } } else { - int cch = lstrlen(lpszMatch); + int cch = (int)StringCchLenW(lpszMatch,0); if (cch >= 3) { for (i = 0; i < COUNTOF(g_pLexArray); i++) { if (StrCmpNI(g_pLexArray[i]->pszName,lpszMatch,cch) == 0) @@ -4947,7 +4947,7 @@ bool Style_StrGetColor(bool bFore, LPCWSTR lpszStyle, COLORREF* rgb) WCHAR *p = StrStrI(lpszStyle, pItem); if (p) { - StringCchCopy(tch, COUNTOF(tch), p + lstrlen(pItem)); + StringCchCopy(tch, COUNTOF(tch), p + StringCchLenW(pItem,0)); if (tch[0] == L'#') tch[0] = L' '; p = StrChr(tch, L';'); @@ -4977,7 +4977,7 @@ bool Style_StrGetAlpha(LPCWSTR lpszStyle, int* i, bool bAlpha1st) WCHAR* p = StrStrI(lpszStyle, strAlpha); if (p) { WCHAR tch[BUFSIZE_STYLE_VALUE] = { L'\0' }; - StringCchCopy(tch, COUNTOF(tch), p + lstrlen(strAlpha)); + StringCchCopy(tch, COUNTOF(tch), p + StringCchLenW(strAlpha,0)); p = StrChr(tch, L';'); if (p) *p = L'\0'; @@ -5002,7 +5002,7 @@ bool Style_StrGetAlpha(LPCWSTR lpszStyle, int* i, bool bAlpha1st) // WCHAR tch[BUFSIZE_STYLE_VALUE] = { L'\0' }; // WCHAR *p = StrStrI(lpszStyle, lpszProperty); // if (p) { -// StringCchCopy(tch, COUNTOF(tch), (p + lstrlen(lpszProperty))); +// StringCchCopy(tch, COUNTOF(tch), (p + StringCchLenW(lpszProperty,0))); // p = StrChr(tch, L';'); // if (p) // *p = L'\0';