diff options
author | Rozhuk Ivan <rozhuk.im@gmail.com> | 2014-12-02 03:47:27 +0000 |
---|---|---|
committer | Rozhuk Ivan <rozhuk.im@gmail.com> | 2014-12-02 03:47:27 +0000 |
commit | 6e2b6b31bae6d69bff5271451e73eb08637b8118 (patch) | |
tree | ca636f1497e4cc6980736d56a7ff61e3a6f88079 /plugins | |
parent | d83beb598f0944dcb944524b1d27525dc320cf18 (diff) |
mir_sntprintf(..., _T("%s"), ...) -> _tcsncpy_s(..., ..., _TRUNCATE)
fix some x64 ptr truncations
git-svn-id: http://svn.miranda-ng.org/main/trunk@11211 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins')
49 files changed, 178 insertions, 172 deletions
diff --git a/plugins/AdvaImg/src/main.cpp b/plugins/AdvaImg/src/main.cpp index 9c7bdb698a..f522f8b499 100644 --- a/plugins/AdvaImg/src/main.cpp +++ b/plugins/AdvaImg/src/main.cpp @@ -294,7 +294,7 @@ static INT_PTR serviceBmpFilterResizeBitmap(WPARAM wParam,LPARAM lParam) && width > bminfo.bmWidth && height > bminfo.bmHeight))
{
// Do nothing
- return (int) info->hBmp;
+ return (INT_PTR)info->hBmp;
}
else
{
@@ -847,18 +847,18 @@ static INT_PTR serviceLoad(WPARAM wParam, LPARAM lParam) // ok, let's load the file
FIBITMAP *dib;
- if(lParam & IMGL_WCHAR)
+ if (lParam & IMGL_WCHAR)
dib = FreeImage_LoadU(fif, (wchar_t *)lpszFilename, 0);
else
dib = FreeImage_Load(fif, lpszFilename, 0);
if(dib == NULL || (lParam & IMGL_RETURNDIB))
- return (int)dib;
+ return (INT_PTR)dib;
HBITMAP hbm = FreeImage_CreateHBITMAPFromDIB(dib);
FreeImage_Unload(dib);
FI_CorrectBitmap32Alpha(hbm, FALSE);
- return((INT_PTR)hbm);
+ return ((INT_PTR)hbm);
}
return NULL;
}
diff --git a/plugins/Alarms/src/alarms.cpp b/plugins/Alarms/src/alarms.cpp index c3d3a8e1f7..cf8050f8ec 100644 --- a/plugins/Alarms/src/alarms.cpp +++ b/plugins/Alarms/src/alarms.cpp @@ -107,16 +107,16 @@ static int PluginMessageReceived(WPARAM wParam,LPARAM lParam) TCHAR *savedMsg = ppre->tszMessage;
if (!_tcscmp(msg, _T(" ffw"))) {
- mir_sntprintf(buff, SIZEOF(buff), _T("%s"), _T("Fast forward!"));
+ _tcsncpy_s(buff, _T("Fast forward!"), _TRUNCATE);
HWND hWnd = FindWindow(0, _T("Windows Media Player"));
PostMessage(hWnd, WM_COMMAND, WMP_NEXT, 0);
- }
- else mir_sntprintf(buff, SIZEOF(buff), TranslateT("Unknown command issued: \"%s\""), msg);
+ } else
+ mir_sntprintf(buff, SIZEOF(buff), TranslateT("Unknown command issued: \"%s\""), msg);
ShowPopup(pccsd->hContact, buff);
- _tcsncpy(response, buff,SIZEOF(response));
+ _tcsncpy(response, buff, SIZEOF(response));
PluginSendMessage((WPARAM)pccsd->hContact, (LPARAM)response);
return 0;
diff --git a/plugins/BossKeyPlus/src/BossKey.cpp b/plugins/BossKeyPlus/src/BossKey.cpp index 309713140c..572a1c364c 100644 --- a/plugins/BossKeyPlus/src/BossKey.cpp +++ b/plugins/BossKeyPlus/src/BossKey.cpp @@ -264,13 +264,11 @@ static void CreateTrayIcon(bool create) {
NOTIFYICONDATA nim;
DBVARIANT dbVar;
- if (!db_get_ts(NULL,MOD_NAME,"ToolTipText",&dbVar))
- {
- mir_sntprintf(nim.szTip, 64, _T("%s"), dbVar.ptszVal);
+ if (!db_get_ts(NULL,MOD_NAME,"ToolTipText",&dbVar)) {
+ _tcsncpy_s(nim.szTip, dbVar.ptszVal, _TRUNCATE);
db_free(&dbVar);
- }
- else
- mir_tstrcpy(nim.szTip, _T("Miranda NG"));
+ } else
+ _tcsncpy_s(nim.szTip, _T("Miranda NG"), _TRUNCATE);
nim.cbSize = sizeof(nim);
nim.hWnd = g_hListenWindow;
diff --git a/plugins/ChangeKeyboardLayout/src/hook_events.cpp b/plugins/ChangeKeyboardLayout/src/hook_events.cpp index 8253c9c7ab..9b8d53e7c9 100644 --- a/plugins/ChangeKeyboardLayout/src/hook_events.cpp +++ b/plugins/ChangeKeyboardLayout/src/hook_events.cpp @@ -9,7 +9,7 @@ INT_PTR APIChangeLayout(WPARAM wParam, LPARAM lParam) INT_PTR APIGetLayoutOfText(WPARAM wParam, LPARAM lParam)
{
LPTSTR ptszInText = (TCHAR*)lParam;
- return (int) GetLayoutOfText(ptszInText);
+ return (INT_PTR)GetLayoutOfText(ptszInText);
}
INT_PTR APIChangeTextLayout(WPARAM wParam, LPARAM lParam)
diff --git a/plugins/Clist_modern/src/modern_cachefuncs.cpp b/plugins/Clist_modern/src/modern_cachefuncs.cpp index a45d9a02dd..1b6fa8b40a 100644 --- a/plugins/Clist_modern/src/modern_cachefuncs.cpp +++ b/plugins/Clist_modern/src/modern_cachefuncs.cpp @@ -465,8 +465,8 @@ int Cache_GetLineText( DBVARIANT dbv = {0}; // Try to get XStatusName if (!db_get_ts(pdnce->hContact, pdnce->m_cache_cszProto, "XStatusName", &dbv)) { - if (dbv.pszVal != NULL && dbv.pszVal[0] != 0) - mir_sntprintf(text, text_size, _T("%s"), dbv.pszVal); + if (dbv.ptszVal != NULL && dbv.ptszVal[0] != 0) + _tcsncpy_s(text, text_size, dbv.ptszVal, _TRUNCATE); CopySkipUnprintableChars(text, text, text_size-1); db_free(&dbv); } diff --git a/plugins/Clist_modern/src/modern_clc.cpp b/plugins/Clist_modern/src/modern_clc.cpp index c234b7d400..873020a36c 100644 --- a/plugins/Clist_modern/src/modern_clc.cpp +++ b/plugins/Clist_modern/src/modern_clc.cpp @@ -1365,7 +1365,7 @@ static LRESULT clcOnLButtonUp(ClcData *dat, HWND hwnd, UINT msg, WPARAM wParam, if (sourceGrName) mir_sntprintf(newName, SIZEOF(newName), _T("%s\\%s"), sourceGrName, shortGroup); else - mir_sntprintf(newName, SIZEOF(newName), _T("%s"), shortGroup); + _tcsncpy_s(newName, shortGroup, _TRUNCATE); } mir_free(groupName); mir_free(sourceGrName); diff --git a/plugins/Clist_modern/src/modern_rowtemplateopt.cpp b/plugins/Clist_modern/src/modern_rowtemplateopt.cpp index 97be36e25a..66581b5271 100644 --- a/plugins/Clist_modern/src/modern_rowtemplateopt.cpp +++ b/plugins/Clist_modern/src/modern_rowtemplateopt.cpp @@ -315,14 +315,14 @@ void RefreshTree(HWND hwndDlg,HTREEITEM hti) if (!cell->child)
{
if (cell->type == 0)
- mir_sntprintf(buf, SIZEOF(buf), TranslateT("Empty %s cell"), cell->cont == TC_COL?TranslateT("column"):TranslateT("line"));
+ mir_sntprintf(buf, SIZEOF(buf), TranslateT("Empty %s cell"), cell->cont == TC_COL ? TranslateT("column") : TranslateT("line"));
else
- mir_sntprintf(buf, SIZEOF(buf), _T("%s"), TranslateTS(types[cell->type]));
+ _tcsncpy_s(buf, TranslateTS(types[cell->type]), _TRUNCATE);
}
else
{
if (cell->type == 0)
- mir_sntprintf(buf, SIZEOF(buf), _T("%s"), cell->cont != TC_COL?TranslateT("columns"):TranslateT("lines"));
+ _tcsncpy_s(buf, (cell->cont != TC_COL ? TranslateT("columns") : TranslateT("lines")), _TRUNCATE);
else
mir_sntprintf(buf, SIZEOF(buf), TranslateT("%s, contain %s"), TranslateTS(types[cell->type]),cell->cont != TC_COL?TranslateT("columns"):TranslateT("lines"));
}
diff --git a/plugins/Clist_nicer/src/CLUIFrames/cluiframes.cpp b/plugins/Clist_nicer/src/CLUIFrames/cluiframes.cpp index 3a18f1ba92..2a3d4829ee 100644 --- a/plugins/Clist_nicer/src/CLUIFrames/cluiframes.cpp +++ b/plugins/Clist_nicer/src/CLUIFrames/cluiframes.cpp @@ -918,7 +918,7 @@ INT_PTR CLUIFramesGetFrameOptions(WPARAM wParam, LPARAM lParam) return (INT_PTR)Frames[pos].align; case FO_FLOATING: - return (int)Frames[pos].floating; + return (INT_PTR)Frames[pos].floating; case FO_FLAGS: INT_PTR dwFlags = 0; diff --git a/plugins/Clist_nicer/src/clcutils.cpp b/plugins/Clist_nicer/src/clcutils.cpp index 3b0019626c..c700c5607c 100644 --- a/plugins/Clist_nicer/src/clcutils.cpp +++ b/plugins/Clist_nicer/src/clcutils.cpp @@ -48,38 +48,52 @@ static int MY_pathIsAbsolute(const TCHAR *path) size_t MY_pathToRelative(const TCHAR *pSrc, TCHAR *pOut)
{
- if ( !pSrc || !mir_tstrlen(pSrc) || mir_tstrlen(pSrc) > MAX_PATH)
- return 0;
+ size_t dwSrcLen, dwProfilePathLen;
- if ( !MY_pathIsAbsolute(pSrc)) {
- mir_sntprintf(pOut, MAX_PATH, _T("%s"), pSrc);
- return mir_tstrlen(pOut);
- }
+ if (!pSrc || !pOut)
+ return 0;
+ dwSrcLen = mir_tstrlen(pSrc);
+ if (!dwSrcLen || dwSrcLen > (MAX_PATH - 1))
+ return 0;
+ if (!MY_pathIsAbsolute(pSrc))
+ goto path_not_abs;
TCHAR szTmp[MAX_PATH];
- mir_sntprintf(szTmp, SIZEOF(szTmp), _T("%s"), pSrc);
+ memcpy(szTmp, pSrc, (dwSrcLen * sizeof(TCHAR)));
+ szTmp[dwSrcLen] = 0;
_tcslwr(szTmp);
- if ( _tcsstr(szTmp, cfg::dat.tszProfilePath)) {
- mir_sntprintf(pOut, MAX_PATH, _T("%s"), pSrc + mir_tstrlen(cfg::dat.tszProfilePath) - 1);
- pOut[0]='.';
- return mir_tstrlen(pOut);
- }
-
- mir_sntprintf(pOut, MAX_PATH, _T("%s"), pSrc);
- return mir_tstrlen(pOut);
+ if (_tcsstr(szTmp, cfg::dat.tszProfilePath)) {
+ dwProfilePathLen = mir_tstrlen(cfg::dat.tszProfilePath);
+ memcpy(pOut, (pSrc + (dwProfilePathLen - 1)), ((dwSrcLen - (dwProfilePathLen - 1)) * sizeof(TCHAR)));
+ pOut[0] = '.';
+ pOut[dwSrcLen] = 0;
+ return (dwSrcLen - (dwProfilePathLen - 1));
+ }
+
+path_not_abs:
+ memcpy(pOut, pSrc, (dwSrcLen * sizeof(TCHAR)));
+ pOut[dwSrcLen] = 0;
+ return dwSrcLen;
}
size_t MY_pathToAbsolute(const TCHAR *pSrc, TCHAR *pOut)
{
- if ( !pSrc || !mir_tstrlen(pSrc) || mir_tstrlen(pSrc) > MAX_PATH)
+ size_t dwSrcLen;
+
+ if (!pSrc || !pOut)
+ return 0;
+ dwSrcLen = mir_tstrlen(pSrc);
+ if (!dwSrcLen || dwSrcLen > (MAX_PATH - 1))
return 0;
- if (MY_pathIsAbsolute(pSrc)&&pSrc[0]!='.')
- mir_sntprintf(pOut, MAX_PATH, _T("%s"), pSrc);
- else if (pSrc[0]=='.')
- mir_sntprintf(pOut, MAX_PATH, _T("%s\\%s"), cfg::dat.tszProfilePath, pSrc);
+ if (MY_pathIsAbsolute(pSrc) && pSrc[0] != '.') {
+ memcpy(pOut, pSrc, (dwSrcLen * sizeof(TCHAR)));
+ pOut[dwSrcLen] = 0;
+ return dwSrcLen;
+ if (pSrc[0] == '.')
+ return (mir_sntprintf(pOut, MAX_PATH, _T("%s\\%s"), cfg::dat.tszProfilePath, pSrc));
- return mir_tstrlen(pOut);
+ return 0;
}
/*
diff --git a/plugins/ConnectionNotify/src/ConnectionNotify.cpp b/plugins/ConnectionNotify/src/ConnectionNotify.cpp index 0513ea98a6..1a42fb6794 100644 --- a/plugins/ConnectionNotify/src/ConnectionNotify.cpp +++ b/plugins/ConnectionNotify/src/ConnectionNotify.cpp @@ -639,7 +639,7 @@ INT_PTR TMLoadIcon(WPARAM wParam,LPARAM lParam) case PLI_OFFLINE: id=IDI_ICON2; break;
default: return 0;
}
- return (int)LoadImage(hInst, MAKEINTRESOURCE(id), IMAGE_ICON, GetSystemMetrics(wParam&PLIF_SMALL?SM_CXSMICON:SM_CXICON), GetSystemMetrics(wParam&PLIF_SMALL?SM_CYSMICON:SM_CYICON), 0);
+ return (INT_PTR)LoadImage(hInst, MAKEINTRESOURCE(id), IMAGE_ICON, GetSystemMetrics(wParam&PLIF_SMALL?SM_CXSMICON:SM_CXICON), GetSystemMetrics(wParam&PLIF_SMALL?SM_CYSMICON:SM_CYICON), 0);
}
//=======================================================
//SetStatus
@@ -816,11 +816,11 @@ void showMsg(TCHAR *pName, DWORD pid,TCHAR *intIp,TCHAR *extIp,int intPort,int e }
ppd.PluginWindowProc = PopupDlgProc;
- ppd.iSeconds=settingInterval1;
+ ppd.iSeconds = settingInterval1;
//Now the "additional" data.
- mir_sntprintf(mpd->strIntIp,_countof(mpd->strIntIp),_T("%s"),intIp);
- mir_sntprintf(mpd->strExtIp,_countof(mpd->strExtIp),_T("%s"),extIp);
- mir_sntprintf(mpd->PName,_countof(mpd->PName),_T("%s"),pName);
+ _tcsncpy_s(mpd->strIntIp, intIp, _TRUNCATE);
+ _tcsncpy_s(mpd->strExtIp, extIp, _TRUNCATE);
+ _tcsncpy_s(mpd->PName, pName, _TRUNCATE);
mpd->intIntPort = intPort;
mpd->intExtPort = extPort;
mpd->Pid = pid;
diff --git a/plugins/CrashDumper/src/crshdmp.cpp b/plugins/CrashDumper/src/crshdmp.cpp index ccc560205a..b00edd0437 100644 --- a/plugins/CrashDumper/src/crshdmp.cpp +++ b/plugins/CrashDumper/src/crshdmp.cpp @@ -375,7 +375,7 @@ extern "C" int __declspec(dllexport) Load(void) profpath = Utils_ReplaceVarsT(_T("%miranda_userdata%"));
if (catchcrashes && !needrestart)
mir_sntprintf(CrashLogFolder, MAX_PATH, TEXT("%s\\CrashLog"), profpath);
- mir_sntprintf(VersionInfoFolder, MAX_PATH, TEXT("%s"), profpath);
+ _tcsncpy_s(VersionInfoFolder, profpath, _TRUNCATE);
HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoaded);
diff --git a/plugins/ExternalAPI/m_folders.h b/plugins/ExternalAPI/m_folders.h index e2fc98626a..c54f7c3d18 100644 --- a/plugins/ExternalAPI/m_folders.h +++ b/plugins/ExternalAPI/m_folders.h @@ -189,7 +189,7 @@ __inline static INT_PTR FoldersGetCustomPathW(HANDLE hFolderEntry, wchar_t *path if (res) {
wchar_t buffer[MAX_PATH];
PathToAbsoluteW(notFoundW, buffer);
- mir_sntprintf(pathW, size, _T("%s"), buffer);
+ _tcsncpy_s(pathW, size, buffer, _TRUNCATE);
}
return res;
@@ -228,7 +228,7 @@ __inline static INT_PTR FoldersGetCustomPathExW(HANDLE hFolderEntry, wchar_t *pa if (res) {
wchar_t buffer[MAX_PATH];
PathToAbsoluteW(notFoundW, buffer);
- mir_sntprintf(pathW, size, _T("%s"), buffer);
+ wcsncpy_s(pathW, size, buffer, _TRUNCATE);
}
if (pathW[0] != '\0')
diff --git a/plugins/FingerprintNG/src/fingerprint.cpp b/plugins/FingerprintNG/src/fingerprint.cpp index 650ca060c2..d095f6e8a5 100644 --- a/plugins/FingerprintNG/src/fingerprint.cpp +++ b/plugins/FingerprintNG/src/fingerprint.cpp @@ -67,7 +67,7 @@ void __fastcall Prepare(KN_FP_MASK* mask, bool bEnable) if (mask->iIconIndex == IDI_NOTFOUND || mask->iIconIndex == IDI_UNKNOWN || mask->iIconIndex == IDI_UNDETECTED) GetModuleFileName(g_hInst, destfile, MAX_PATH); else { - mir_sntprintf(destfile, SIZEOF(destfile), _T("%s"), g_szSkinLib); + _tcsncpy_s(destfile, g_szSkinLib, _TRUNCATE); struct _stat64i32 stFileInfo; if ( _tstat(destfile, &stFileInfo) == -1) @@ -256,7 +256,7 @@ static void MatchMasks(TCHAR* szMirVer, short *base, short *overlay, short *over if (p.iIconIndex != IDI_NOTFOUND && p.iIconIndex != IDI_UNKNOWN && p.iIconIndex != IDI_UNDETECTED) { TCHAR destfile[MAX_PATH]; - mir_sntprintf(destfile, SIZEOF(destfile), _T("%s"), g_szSkinLib); + _tcsncpy_s(destfile, g_szSkinLib, _TRUNCATE); struct _stat64i32 stFileInfo; if ( _tstat(destfile, &stFileInfo) == -1) diff --git a/plugins/Folders/src/utils.cpp b/plugins/Folders/src/utils.cpp index e21a820325..a2ba6668d7 100644 --- a/plugins/Folders/src/utils.cpp +++ b/plugins/Folders/src/utils.cpp @@ -127,7 +127,7 @@ wchar_t *StrReplace(wchar_t *source, const wchar_t *what, const wchar_t *withWha char *StrTrim(char *szText, const char *szTrimChars)
{
- int i = (int)strlen(szText) - 1;
+ size_t i = strlen(szText) - 1;
while (i >= 0 && strchr(szTrimChars, szText[i]))
szText[i--] = '\0';
@@ -143,7 +143,7 @@ char *StrTrim(char *szText, const char *szTrimChars) wchar_t *StrTrim(wchar_t *szText, const wchar_t *szTrimChars)
{
- int i = (int)wcslen(szText) - 1;
+ size_t i = wcslen(szText) - 1;
while (i >= 0 && wcschr(szTrimChars, szText[i]))
szText[i--] = '\0';
diff --git a/plugins/IEView/src/TemplateHTMLBuilder.cpp b/plugins/IEView/src/TemplateHTMLBuilder.cpp index df42325586..c45ac7e528 100644 --- a/plugins/IEView/src/TemplateHTMLBuilder.cpp +++ b/plugins/IEView/src/TemplateHTMLBuilder.cpp @@ -195,7 +195,7 @@ void TemplateHTMLBuilder::buildHeadTemplate(IEView *view, IEVIEWEVENT *event, Pr }
mir_snprintf(tempStr, SIZEOF(tempStr), "%snoavatar.png", tempBase);
TCHAR szNoAvatarPath[MAX_PATH];
- mir_sntprintf(szNoAvatarPath, SIZEOF(szNoAvatarPath), _T("%s"), _A2T(protoSettings->getSRMMTemplateFilename()));
+ _tcsncpy_s(szNoAvatarPath, _A2T(protoSettings->getSRMMTemplateFilename()), _TRUNCATE);
TCHAR *szNoAvatarPathTmp = _tcsrchr(szNoAvatarPath, '\\');
if (szNoAvatarPathTmp != NULL)
*szNoAvatarPathTmp = 0;
@@ -370,7 +370,7 @@ void TemplateHTMLBuilder::appendEventTemplate(IEView *view, IEVIEWEVENT *event, }
TCHAR szNoAvatarPath[MAX_PATH];
- mir_sntprintf(szNoAvatarPath, SIZEOF(szNoAvatarPath), _T("%s"), _A2T(protoSettings->getSRMMTemplateFilename()));
+ _tcsncpy_s(szNoAvatarPath, _A2T(protoSettings->getSRMMTemplateFilename()), _TRUNCATE);
TCHAR *szNoAvatarPathTmp = _tcsrchr(szNoAvatarPath, '\\');
if (szNoAvatarPathTmp != NULL)
*szNoAvatarPathTmp = 0;
diff --git a/plugins/IEView/src/ieview_services.cpp b/plugins/IEView/src/ieview_services.cpp index fb0545bebc..8c5f3f0d4b 100644 --- a/plugins/IEView/src/ieview_services.cpp +++ b/plugins/IEView/src/ieview_services.cpp @@ -84,7 +84,7 @@ INT_PTR HandleIEEvent(WPARAM, LPARAM lParam) else if (event->iType == IEE_CLEAR_LOG)
view->clear(event);
else if (event->iType == IEE_GET_SELECTION)
- return (int)view->getSelection(event);
+ return (INT_PTR)view->getSelection(event);
else if (event->iType == IEE_SAVE_DOCUMENT)
view->saveDocument();
else if (event->iType == IEE_LOG_MEM_EVENTS)
diff --git a/plugins/KeyboardNotify/src/main.cpp b/plugins/KeyboardNotify/src/main.cpp index 1d959950df..cbcdc60627 100644 --- a/plugins/KeyboardNotify/src/main.cpp +++ b/plugins/KeyboardNotify/src/main.cpp @@ -495,12 +495,12 @@ static INT_PTR IsFlashingActiveService(WPARAM, LPARAM) INT_PTR NormalizeSequenceService(WPARAM wParam, LPARAM lParam) { - TCHAR strAux[MAX_PATH+1], *strIn = (TCHAR *)lParam; + TCHAR strAux[MAX_PATH + 1], *strIn = (TCHAR*)lParam; - mir_sntprintf(strAux, MAX_PATH, _T("%s"), strIn); - mir_sntprintf(strIn, MAX_PATH, _T("%s"), normalizeCustomString(strAux)); + _tcsncpy_s(strAux, strIn, _TRUNCATE); + _tcsncpy_s(strIn, MAX_PATH, normalizeCustomString(strAux), _TRUNCATE); - return (int)strIn; + return (INT_PTR)strIn; } @@ -698,10 +698,10 @@ void createEventPrefix(TCHAR *prefixName, size_t maxLen) while (str = _tcschr(profileName, _T('\\'))) *str = _T('/'); if ((len = _tcslen(profileName)) <= maxLen) - _tcscpy(prefixName, profileName); + _tcsncpy_s(prefixName, maxLen, profileName, _TRUNCATE); else { str = profileName + len - maxLen / 2; - mir_sntprintf(prefixName, maxLen / 2, _T("%s"), profileName); + _tcsncpy_s(prefixName, (maxLen / 2), profileName, _TRUNCATE); _tcscat(prefixName, str); } } diff --git a/plugins/NewAwaySysMod/src/Services.cpp b/plugins/NewAwaySysMod/src/Services.cpp index a1f2c42840..dfe711c77f 100644 --- a/plugins/NewAwaySysMod/src/Services.cpp +++ b/plugins/NewAwaySysMod/src/Services.cpp @@ -172,7 +172,7 @@ INT_PTR InvokeStatusWindow(WPARAM wParam, LPARAM) if (g_SetAwayMsgPage.GetWnd()) { // already setting something
SetForegroundWindow(g_SetAwayMsgPage.GetWnd());
- return (int)g_SetAwayMsgPage.GetWnd();
+ return (INT_PTR)g_SetAwayMsgPage.GetWnd();
}
SetAwayMsgData *dat = new SetAwayMsgData;
memset(dat, 0, sizeof(SetAwayMsgData));
diff --git a/plugins/New_GPG/src/main.cpp b/plugins/New_GPG/src/main.cpp index ae5785ea2b..9d09305217 100755 --- a/plugins/New_GPG/src/main.cpp +++ b/plugins/New_GPG/src/main.cpp @@ -154,19 +154,18 @@ static INT_PTR CALLBACK DlgProcFirstRun(HWND hwndDlg,UINT msg,WPARAM wParam,LPAR { boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); TCHAR buf[5]; - mir_sntprintf(buf, 5, _T("%s"), expire_date); + _tcsncpy_s(buf, expire_date, _TRUNCATE); int year = _ttoi(buf); if(year < now.date().year()) expired = true; else if(year == now.date().year()) { - mir_sntprintf(buf, 3, _T("%s"), expire_date+5); + _tcsncpy_s(buf, (expire_date + 5), _TRUNCATE); int month = _ttoi(buf); if(month < now.date().month()) expired = true; - else if(month == now.date().month()) - { - mir_sntprintf(buf, 3, _T("%s"), expire_date+8); + else if(month == now.date().month()) { + _tcsncpy_s(buf, (expire_date + 8), _TRUNCATE); unsigned day = _ttoi(buf); if(day <= now.date().day_number()) expired = true; @@ -2125,19 +2124,19 @@ void InitCheck() { boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); TCHAR buf[5]; - mir_sntprintf(buf, 5, _T("%s"), expire_date); + _tcsncpy_s(buf, expire_date, _TRUNCATE); int year = _ttoi(buf); if(year < now.date().year()) expired = true; else if(year == now.date().year()) { - mir_sntprintf(buf, 3, _T("%s"), expire_date+5); + _tcsncpy_s(buf, (expire_date + 5), _TRUNCATE); int month = _ttoi(buf); if(month < now.date().month()) expired = true; else if(month == now.date().month()) { - mir_sntprintf(buf, 3, _T("%s"), expire_date+8); + _tcsncpy_s(buf, (expire_date + 8), _TRUNCATE); unsigned day = _ttoi(buf); if(day <= now.date().day_number()) expired = true; @@ -2192,19 +2191,19 @@ void InitCheck() { boost::posix_time::ptime now = boost::posix_time::second_clock::local_time(); TCHAR buf[5]; - mir_sntprintf(buf, 5, _T("%s"), expire_date); + _tcsncpy_s(buf, expire_date, _TRUNCATE); int year = _ttoi(buf); if(year < now.date().year()) expired = true; else if(year == now.date().year()) { - mir_sntprintf(buf, 3, _T("%s"), expire_date+5); + _tcsncpy_s(buf, (expire_date + 5), _TRUNCATE); int month = _ttoi(buf); if(month < now.date().month()) expired = true; else if(month == now.date().month()) { - mir_sntprintf(buf, 3, _T("%s"), expire_date+8); + _tcsncpy_s(buf, (expire_date + 8), _TRUNCATE); unsigned day = _ttoi(buf); if(day <= now.date().day_number()) expired = true; diff --git a/plugins/NotesAndReminders/src/reminders.cpp b/plugins/NotesAndReminders/src/reminders.cpp index 06f9ec8396..e6e2b35639 100644 --- a/plugins/NotesAndReminders/src/reminders.cpp +++ b/plugins/NotesAndReminders/src/reminders.cpp @@ -1017,7 +1017,7 @@ static BOOL ParseTime(LPCSTR s, int *hout, int *mout, BOOL bTimeOffset, BOOL bAl // returns TRUE if combo box list displays time offsets ("23:34 (5 Minutes)" etc.)
__inline static BOOL IsRelativeCombo(HWND Dialog, UINT nIDTime)
{
- return (int)SendDlgItemMessage(Dialog,nIDTime,CB_GETITEMDATA,0,0) >= 0;
+ return (((int)SendDlgItemMessage(Dialog,nIDTime,CB_GETITEMDATA,0,0)) >= 0);
}
static void PopulateTimeCombo(HWND Dialog, UINT nIDTime, BOOL bRelative, const SYSTEMTIME *tmUtc)
diff --git a/plugins/Scriver/src/infobar.cpp b/plugins/Scriver/src/infobar.cpp index 8917bb1d78..c2e53271c8 100644 --- a/plugins/Scriver/src/infobar.cpp +++ b/plugins/Scriver/src/infobar.cpp @@ -79,9 +79,9 @@ void RefreshInfobar(InfobarWindowData* idat) TCHAR szText[2048];
SETTEXTEX st;
if ( szXStatusMsg && *szXStatusMsg )
- mir_sntprintf(szText, 2047, _T("%s (%s)"), TranslateTS(szXStatusName), szXStatusMsg);
+ mir_sntprintf(szText, SIZEOF(szText), _T("%s (%s)"), TranslateTS(szXStatusName), szXStatusMsg);
else
- mir_sntprintf(szText, 2047, _T("%s"), TranslateTS(szXStatusName));
+ _tcsncpy_s(szText, TranslateTS(szXStatusName), _TRUNCATE);
st.flags = ST_DEFAULT;
st.codepage = 1200;
SendDlgItemMessage(hwnd, IDC_INFOBAR_NAME, EM_SETTEXTEX, (WPARAM) &st, (LPARAM)szContactName);
diff --git a/plugins/Scriver/src/msgoptions.cpp b/plugins/Scriver/src/msgoptions.cpp index 0f0a8d85a4..682bf76cbe 100644 --- a/plugins/Scriver/src/msgoptions.cpp +++ b/plugins/Scriver/src/msgoptions.cpp @@ -112,8 +112,8 @@ void RegisterFontServiceFonts() {
int i;
FontIDT fid = { sizeof(fid) };
- mir_sntprintf(fid.group, SIZEOF(fid.group), _T("%s"), LPGENT("Messaging"));
- mir_sntprintf(fid.backgroundGroup, SIZEOF(fid.backgroundGroup), _T("%s"), LPGENT("Messaging"));
+ _tcsncpy_s(fid.group, LPGENT("Messaging"), _TRUNCATE);
+ _tcsncpy_s(fid.backgroundGroup, LPGENT("Messaging"), _TRUNCATE);
strncpy(fid.dbSettingsGroup, SRMMMOD, SIZEOF(fid.dbSettingsGroup));
fid.flags = FIDF_DEFAULTVALID | FIDF_DEFAULTVALID;
for (i = 0; i < SIZEOF(fontOptionsList); i++) {
@@ -133,7 +133,7 @@ void RegisterFontServiceFonts() }
ColourIDT cid = { sizeof(cid) };
- mir_sntprintf(cid.group, SIZEOF(cid.group), _T("%s"), LPGENT("Messaging"));
+ _tcsncpy_s(cid.group, LPGENT("Messaging"), _TRUNCATE);
strncpy(cid.dbSettingsGroup, SRMMMOD, SIZEOF(fid.dbSettingsGroup));
cid.flags = 0;
for (i = 0; i < SIZEOF(colourOptionsList); i++) {
diff --git a/plugins/Scriver/src/msgtimedout.cpp b/plugins/Scriver/src/msgtimedout.cpp index 317d8b6ef4..6a7bc06f49 100644 --- a/plugins/Scriver/src/msgtimedout.cpp +++ b/plugins/Scriver/src/msgtimedout.cpp @@ -52,7 +52,7 @@ INT_PTR CALLBACK ErrorDlgProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lPar if (ewd->szName)
mir_sntprintf(szText, SIZEOF(szText), _T("%s - %s"), TranslateT("Send Error"), ewd->szName);
else
- mir_sntprintf(szText, SIZEOF(szText), _T("%s"), TranslateT("Send Error"));
+ _tcsncpy_s(szText, TranslateT("Send Error"), _TRUNCATE);
SetWindowText(hwndDlg, szText);
GetWindowRect(hwndDlg, &rc);
diff --git a/plugins/SimpleStatusMsg/src/awaymsg.cpp b/plugins/SimpleStatusMsg/src/awaymsg.cpp index 84a8acda74..3f7c677730 100644 --- a/plugins/SimpleStatusMsg/src/awaymsg.cpp +++ b/plugins/SimpleStatusMsg/src/awaymsg.cpp @@ -266,7 +266,7 @@ static INT_PTR CALLBACK CopyAwayMsgDlgProc(HWND hwndDlg, UINT message, WPARAM wP if (EmptyClipboard()) {
TCHAR msg[1024];
TCHAR *tszMsg = StrNormNewline((TCHAR *)ack->lParam);
- mir_sntprintf(msg, SIZEOF(msg), _T("%s"), tszMsg);
+ _tcsncpy_s(msg, tszMsg, _TRUNCATE);
mir_free(tszMsg);
size_t len = mir_tstrlen(msg);
if (len) {
diff --git a/plugins/Spamotron/src/popups.cpp b/plugins/Spamotron/src/popups.cpp index 43a5ee5655..3635aa33bc 100644 --- a/plugins/Spamotron/src/popups.cpp +++ b/plugins/Spamotron/src/popups.cpp @@ -184,10 +184,10 @@ int ShowPopupPreview(HWND optDlg, BYTE popupType, TCHAR *line1, TCHAR *line2) if (SendDlgItemMessage(optDlg, IDC_OPT_POPUPS_DEFAULT_TIMEOUT, BM_GETCHECK, 0, 0) || popupType == POPUP_DEFAULT)
ppdp.iSeconds = 0;
- ppdp.lchContact = NULL;
- mir_sntprintf(ppdp.lptzContactName, MAX_CONTACTNAME, _T("%s"), (line1)?line1:_T(PLUGIN_NAME));
+ ppdp.lchContact = NULL;
+ _tcsncpy_s(ppdp.lptzContactName, (line1 ? line1 : _T(PLUGIN_NAME)), _TRUNCATE);
if (line2)
- mir_sntprintf(ppdp.lptzText, MAX_SECONDLINE, _T("%s"), line2);
+ _tcsncpy_s(ppdp.lptzText, line2, _TRUNCATE);
return PUAddPopupT(&ppdp);
}
@@ -233,9 +233,9 @@ int ShowPopup(MCONTACT hContact, BYTE popupType, TCHAR *line1, TCHAR *line2) if (_getOptB("PopupDefaultTimeout", defaultPopupDefaultTimeout) || popupType == POPUP_DEFAULT)
ppdp.iSeconds = 0;
- ppdp.lchContact = hContact;
- mir_sntprintf(ppdp.lptzContactName, MAX_CONTACTNAME, _T("%s"), (line1)?line1:_T(PLUGIN_NAME));
+ ppdp.lchContact = hContact;
+ _tcsncpy_s(ppdp.lptzContactName, (line1 ? line1 : _T(PLUGIN_NAME)), _TRUNCATE);
if (line2)
- mir_sntprintf(ppdp.lptzText, MAX_SECONDLINE, _T("%s"), line2);
+ _tcsncpy_s(ppdp.lptzText, line2, _TRUNCATE);
return PUAddPopupT(&ppdp);
}
\ No newline at end of file diff --git a/plugins/TabSRMM/src/chat/log.cpp b/plugins/TabSRMM/src/chat/log.cpp index 7129dc6361..cee377f6ca 100644 --- a/plugins/TabSRMM/src/chat/log.cpp +++ b/plugins/TabSRMM/src/chat/log.cpp @@ -629,7 +629,7 @@ static void AddEventToBuffer(char **buffer, int *bufferEnd, int *bufferAlloced, if (streamData->lin->ptszUserInfo && streamData->lin->iType != GC_EVENT_TOPIC)
mir_sntprintf(szTemp, SIZEOF(szTemp), _T("%s (%s)"), szTemp2, streamData->lin->ptszUserInfo);
else
- mir_sntprintf(szTemp, SIZEOF(szTemp), _T("%s"), szTemp2);
+ _tcsncpy_s(szTemp, szTemp2, _TRUNCATE);
pszNick = szTemp;
}
diff --git a/plugins/TabSRMM/src/chat/main.cpp b/plugins/TabSRMM/src/chat/main.cpp index 9efe0eb1c4..994a7feabe 100644 --- a/plugins/TabSRMM/src/chat/main.cpp +++ b/plugins/TabSRMM/src/chat/main.cpp @@ -47,7 +47,7 @@ static void OnGetLogName(SESSION_INFO *si, LPCTSTR ptszParsedName) if (!PathIsAbsoluteT(ptszParsedName))
mir_sntprintf(si->pszLogFileName, MAX_PATH, _T("%s%s"), M.getChatLogPath(), ptszParsedName);
else
- mir_sntprintf(si->pszLogFileName, MAX_PATH, _T("%s"), ptszParsedName);
+ _tcsncpy_s(si->pszLogFileName, ptszParsedName, _TRUNCATE);
}
static void OnCreateSession(SESSION_INFO *si, MODULEINFO *mi)
diff --git a/plugins/TabSRMM/src/chat/options.cpp b/plugins/TabSRMM/src/chat/options.cpp index dc89da275f..d4fb1228dc 100644 --- a/plugins/TabSRMM/src/chat/options.cpp +++ b/plugins/TabSRMM/src/chat/options.cpp @@ -831,7 +831,7 @@ INT_PTR CALLBACK DlgProcOptions2(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM case IDC_MUC_OPENLOGBASEDIR:
{
TCHAR tszTemp[MAX_PATH + 20];
- mir_sntprintf(tszTemp, MAX_PATH + 20, _T("%s"), g_Settings.pszLogDir);
+ _tcsncpy_s(tszTemp, g_Settings.pszLogDir, _TRUNCATE);
TCHAR *p = tszTemp;
while(*p && (*p == '\\' || *p == '.'))
@@ -841,10 +841,10 @@ INT_PTR CALLBACK DlgProcOptions2(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM if (TCHAR *p1 = _tcschr(p, '\\'))
*p1 = 0;
- TCHAR tszInitialDir[_MAX_DRIVE + _MAX_PATH + 10];
- mir_sntprintf(tszInitialDir, MAX_PATH, _T("%s%s"), M.getChatLogPath(), p);
+ TCHAR tszInitialDir[_MAX_DRIVE + _MAX_PATH + 10];
+ mir_sntprintf(tszInitialDir, SIZEOF(tszInitialDir), _T("%s%s"), M.getChatLogPath(), p);
if (!PathFileExists(tszInitialDir))
- mir_sntprintf(tszInitialDir, MAX_PATH, _T("%s"), M.getChatLogPath());
+ _tcsncpy_s(tszInitialDir, M.getChatLogPath(), _TRUNCATE);
TCHAR tszReturnName[MAX_PATH]; tszReturnName[0] = 0;
mir_sntprintf(tszTemp, SIZEOF(tszTemp), _T("%s%c*.*%c%c"), TranslateT("All Files"), 0, 0, 0);
diff --git a/plugins/TabSRMM/src/contactcache.cpp b/plugins/TabSRMM/src/contactcache.cpp index 3272c5610c..650f3ceb7b 100644 --- a/plugins/TabSRMM/src/contactcache.cpp +++ b/plugins/TabSRMM/src/contactcache.cpp @@ -122,7 +122,7 @@ bool CContactCache::updateNick() TCHAR *tszNick = pcli->pfnGetContactDisplayName(getActiveContact(), 0); if (tszNick) fChanged = (_tcscmp(m_szNick, tszNick) ? true : false); - mir_sntprintf(m_szNick, 80, _T("%s"), tszNick ? tszNick : _T("<undef>")); + _tcsncpy_s(m_szNick, (tszNick ? tszNick : _T("<undef>")), _TRUNCATE); } return fChanged; } @@ -187,8 +187,8 @@ bool CContactCache::updateUIN() if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) { switch (ci.type) { case CNFT_ASCIIZ: - mir_sntprintf(m_szUIN, SIZEOF(m_szUIN), _T("%s"), reinterpret_cast<TCHAR *>(ci.pszVal)); - mir_free((void*)ci.pszVal); + _tcsncpy_s(m_szUIN, ci.pszVal, _TRUNCATE); + mir_free(ci.pszVal); break; case CNFT_DWORD: mir_sntprintf(m_szUIN, SIZEOF(m_szUIN), _T("%u"), ci.dVal); diff --git a/plugins/TabSRMM/src/container.cpp b/plugins/TabSRMM/src/container.cpp index 7239a16651..45ddd99900 100644 --- a/plugins/TabSRMM/src/container.cpp +++ b/plugins/TabSRMM/src/container.cpp @@ -1464,7 +1464,7 @@ panel_found: if (szThemeName != NULL) { PathToAbsoluteT(szThemeName, pContainer->szAbsThemeFile, M.getDataPath()); - mir_sntprintf(pContainer->szRelThemeFile, MAX_PATH, _T("%s"), szThemeName); + _tcsncpy_s(pContainer->szRelThemeFile, szThemeName, _TRUNCATE); db_free(&dbv); } else pContainer->szAbsThemeFile[0] = pContainer->szRelThemeFile[0] = 0; diff --git a/plugins/TabSRMM/src/containeroptions.cpp b/plugins/TabSRMM/src/containeroptions.cpp index 8c43d1b53e..5cd8f77982 100644 --- a/plugins/TabSRMM/src/containeroptions.cpp +++ b/plugins/TabSRMM/src/containeroptions.cpp @@ -349,7 +349,7 @@ INT_PTR CALLBACK DlgProcContainerOptions(HWND hwndDlg, UINT msg, WPARAM wParam, pContainer->fPrivateThemeChanged = TRUE;
if (PathFileExists(szFinalThemeFile))
- mir_sntprintf(pContainer->szRelThemeFile, MAX_PATH, _T("%s"), szFilename);
+ _tcsncpy_s(pContainer->szRelThemeFile, szFilename, _TRUNCATE);
else
pContainer->szRelThemeFile[0] = 0;
}
diff --git a/plugins/TabSRMM/src/controls.cpp b/plugins/TabSRMM/src/controls.cpp index 96250381fa..db00db12b9 100644 --- a/plugins/TabSRMM/src/controls.cpp +++ b/plugins/TabSRMM/src/controls.cpp @@ -981,7 +981,7 @@ LONG_PTR CALLBACK StatusBarSubclassProc(HWND hWnd, UINT msg, WPARAM wParam, LPAR mtnStatus ? TranslateT("enabled") : TranslateT("disabled")); } else if (sid->dwId == MSG_ICON_SESSION) - mir_sntprintf(wBuf, SIZEOF(wBuf), _T("%s"), TranslateT("Session list.\nClick left for a list of open sessions.\nClick right to access favorites and quickly configure message window behavior")); + _tcsncpy_s(wBuf, TranslateT("Session list.\nClick left for a list of open sessions.\nClick right to access favorites and quickly configure message window behavior"), _TRUNCATE); } else if (sid->tszTooltip) _tcsncpy(wBuf, sid->tszTooltip, SIZEOF(wBuf)); diff --git a/plugins/TabSRMM/src/eventpopups.cpp b/plugins/TabSRMM/src/eventpopups.cpp index 3ba4c3e360..d3d6953c78 100644 --- a/plugins/TabSRMM/src/eventpopups.cpp +++ b/plugins/TabSRMM/src/eventpopups.cpp @@ -678,13 +678,13 @@ static int PopupShowT(NEN_OPTIONS *pluginOptions, MCONTACT hContact, HANDLE hEve pud.PluginData = pdata;
if (hContact)
- mir_sntprintf(pud.lptzContactName, MAX_CONTACTNAME, _T("%s"), pcli->pfnGetContactDisplayName(hContact, 0));
+ _tcsncpy_s(pud.lptzContactName, pcli->pfnGetContactDisplayName(hContact, 0), _TRUNCATE);
else
_tcsncpy_s(pud.lptzContactName, _A2T(dbe.szModule), _TRUNCATE);
TCHAR *szPreview = GetPreviewT((WORD)eventType, &dbe);
if (szPreview) {
- mir_sntprintf(pud.lptzText, MAX_SECONDLINE, _T("%s"), szPreview);
+ _tcsncpy_s(pud.lptzText, szPreview, _TRUNCATE);
mir_free(szPreview);
}
else _tcsncpy(pud.lptzText, _T(" "), MAX_SECONDLINE);
diff --git a/plugins/TabSRMM/src/generic_msghandlers.cpp b/plugins/TabSRMM/src/generic_msghandlers.cpp index 698704de1b..61c2429ce2 100644 --- a/plugins/TabSRMM/src/generic_msghandlers.cpp +++ b/plugins/TabSRMM/src/generic_msghandlers.cpp @@ -1771,9 +1771,9 @@ void TSAPI DM_UpdateTitle(TWindowData *dat, WPARAM wParam, LPARAM lParam) if (PluginConfig.m_StatusOnTabs) mir_sntprintf(newtitle, 127, _T("%s (%s)"), newcontactname, dat->szStatus); else - mir_sntprintf(newtitle, 127, _T("%s"), newcontactname); - } - else mir_sntprintf(newtitle, 127, _T("%s"), _T("Forward")); + _tcsncpy_s(newtitle, newcontactname, _TRUNCATE); + } else + _tcsncpy_s(newtitle, _T("Forward"), _TRUNCATE); item.mask |= TCIF_TEXT; } diff --git a/plugins/TabSRMM/src/infopanel.cpp b/plugins/TabSRMM/src/infopanel.cpp index 9c7e6aed81..0922b715de 100644 --- a/plugins/TabSRMM/src/infopanel.cpp +++ b/plugins/TabSRMM/src/infopanel.cpp @@ -660,8 +660,9 @@ void CInfoPanel::Chat_RenderIPNickname(const HDC hdc, RECT& rcItem) TCHAR *pTmp = _tcschr(si->ptszStatusbarText, ']');
pTmp += 2;
TCHAR tszTemp[30];
- if (si->ptszStatusbarText[0] == '[' && pTmp > si->ptszStatusbarText && ((pTmp - si->ptszStatusbarText) < (size_t)30)) {
- mir_sntprintf(tszTemp, pTmp - si->ptszStatusbarText, _T("%s"), si->ptszStatusbarText);
+ if (si->ptszStatusbarText[0] == '[' && pTmp > si->ptszStatusbarText && ((pTmp - si->ptszStatusbarText) < SIZEOF(tszTemp))) {
+ memcpy(tszTemp, si->ptszStatusbarText, ((pTmp - si->ptszStatusbarText) * sizeof(TCHAR)));
+ tszTemp[(pTmp - si->ptszStatusbarText)] = 0;
CSkin::RenderText(hdc, m_dat->hThemeIP, tszTemp, &rcItem, DT_SINGLELINE | DT_END_ELLIPSIS | DT_NOPREFIX | DT_VCENTER,
CSkin::m_glowSize, m_ipConfig.clrs[IPFONTID_STATUS]);
}
diff --git a/plugins/TabSRMM/src/mim.cpp b/plugins/TabSRMM/src/mim.cpp index 90ee544ba8..8cdd44efa3 100644 --- a/plugins/TabSRMM/src/mim.cpp +++ b/plugins/TabSRMM/src/mim.cpp @@ -101,21 +101,25 @@ void CMimAPI::configureCustomFolders() INT_PTR CMimAPI::foldersPathChanged() { - TCHAR szTemp[MAX_PATH + 2] = {'\0'}; + TCHAR szTemp[MAX_PATH + 2]; if (m_hDataPath) { + szTemp[0] = 0; FoldersGetCustomPathT(m_hDataPath, szTemp, MAX_PATH, const_cast<TCHAR *>(getDataPath())); - mir_sntprintf(m_szProfilePath, MAX_PATH, _T("%s"), szTemp); + _tcsncpy_s(m_szProfilePath, szTemp, _TRUNCATE); + szTemp[0] = 0; FoldersGetCustomPathT(m_hSkinsPath, szTemp, MAX_PATH, const_cast<TCHAR *>(getSkinPath())); - mir_sntprintf(m_szSkinsPath, MAX_PATH - 1, _T("%s"), szTemp); + _tcsncpy_s(m_szSkinsPath, (MAX_PATH - 1), szTemp, _TRUNCATE); Utils::ensureTralingBackslash(m_szSkinsPath); + szTemp[0] = 0; FoldersGetCustomPathT(m_hAvatarsPath, szTemp, MAX_PATH, const_cast<TCHAR *>(getSavedAvatarPath())); - mir_sntprintf(m_szSavedAvatarsPath, MAX_PATH, _T("%s"), szTemp); + _tcsncpy_s(m_szSavedAvatarsPath, szTemp, _TRUNCATE); + szTemp[0] = 0; FoldersGetCustomPathT(m_hChatLogsPath, szTemp, MAX_PATH, const_cast<TCHAR *>(getChatLogPath())); - mir_sntprintf(m_szChatLogsPath, MAX_PATH, _T("%s"), szTemp); + _tcsncpy_s(m_szChatLogsPath, (MAX_PATH - 1), szTemp, _TRUNCATE); Utils::ensureTralingBackslash(m_szChatLogsPath); } diff --git a/plugins/TabSRMM/src/msgdlgutils.cpp b/plugins/TabSRMM/src/msgdlgutils.cpp index 1be3b96482..fe567a05fc 100644 --- a/plugins/TabSRMM/src/msgdlgutils.cpp +++ b/plugins/TabSRMM/src/msgdlgutils.cpp @@ -1098,7 +1098,7 @@ void TSAPI GetMYUIN(TWindowData *dat) if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) {
switch (ci.type) {
case CNFT_ASCIIZ:
- mir_sntprintf(dat->myUin, SIZEOF(dat->myUin), _T("%s"), reinterpret_cast<TCHAR *>(ci.pszVal));
+ _tcsncpy_s(dat->myUin, ci.pszVal, _TRUNCATE);
mir_free((void*)ci.pszVal);
break;
case CNFT_DWORD:
@@ -1823,33 +1823,26 @@ void TSAPI GetMyNick(TWindowData *dat) ci.dwFlag = CNF_TCHAR | CNF_NICK;
if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) {
- if (ci.type == CNFT_ASCIIZ) {
- if (mir_tstrlen(reinterpret_cast<TCHAR *>(ci.pszVal)) < 1 || !_tcscmp(reinterpret_cast<TCHAR *>(ci.pszVal),
- TranslateT("'(Unknown Contact)'"))) {
- mir_sntprintf(dat->szMyNickname, SIZEOF(dat->szMyNickname), _T("%s"), dat->myUin[0] ? dat->myUin : TranslateT("'(Unknown Contact)'"));
- if (ci.pszVal) {
- mir_free(ci.pszVal);
- ci.pszVal = NULL;
- }
- }
- else {
- _tcsncpy(dat->szMyNickname, reinterpret_cast<TCHAR *>(ci.pszVal), 110);
- dat->szMyNickname[109] = 0;
- if (ci.pszVal) {
- mir_free(ci.pszVal);
- ci.pszVal = NULL;
- }
+ switch (ci.type) {
+ case CNFT_ASCIIZ:
+ if (mir_tstrlen((TCHAR*)ci.pszVal) == 0 ||
+ !_tcscmp((TCHAR*)ci.pszVal, TranslateT("'(Unknown Contact)'"))) {
+ _tcsncpy_s(dat->szMyNickname, (dat->myUin[0] ? dat->myUin : TranslateT("'(Unknown Contact)'")), _TRUNCATE);
+ } else {
+ _tcsncpy_s(dat->szMyNickname, (TCHAR*)ci.pszVal, _TRUNCATE);
}
- }
- else if (ci.type == CNFT_DWORD)
+ break;
+ case CNFT_DWORD:
_ltot(ci.dVal, dat->szMyNickname, 10);
- else
- _tcsncpy(dat->szMyNickname, _T("<undef>"), 110); // that really should *never* happen
- }
- else
- _tcsncpy(dat->szMyNickname, _T("<undef>"), 110); // same here
- if (ci.pszVal)
+ break;
+ default:
+ _tcsncpy_s(dat->szMyNickname, _T("<undef>"), _TRUNCATE); // that really should *never* happen
+ break;
+ }
mir_free(ci.pszVal);
+ } else {
+ _tcsncpy_s(dat->szMyNickname, _T("<undef>"), _TRUNCATE); // same here
+ }
}
HICON TSAPI MY_GetContactIcon(const TWindowData *dat, LPCSTR szSetting)
diff --git a/plugins/TabSRMM/src/msgoptions.cpp b/plugins/TabSRMM/src/msgoptions.cpp index dff328cb2c..dba48a37d0 100644 --- a/plugins/TabSRMM/src/msgoptions.cpp +++ b/plugins/TabSRMM/src/msgoptions.cpp @@ -128,7 +128,7 @@ static int TSAPI ScanSkinDir(const TCHAR* tszFolder, HWND hwndCombobox) GetPrivateProfileString(_T("Global"), _T("Name"), _T("None"), szBuf, 500, tszFinalName);
if (!_tcscmp(szBuf, _T("None"))) {
fd.cFileName[mir_tstrlen(fd.cFileName) - 4] = 0;
- mir_sntprintf(szBuf, 255, _T("%s"), fd.cFileName);
+ _tcsncpy_s(szBuf, fd.cFileName, _TRUNCATE);
}
PathToRelativeT(tszFinalName, tszRel, M.getSkinPath());
@@ -156,7 +156,7 @@ static int TSAPI RescanSkins(HWND hwndCombobox) DBVARIANT dbv = { 0 };
TCHAR tszSkinRoot[MAX_PATH], tszFindMask[MAX_PATH];
- mir_sntprintf(tszSkinRoot, MAX_PATH, _T("%s"), M.getSkinPath());
+ _tcsncpy_s(tszSkinRoot, M.getSkinPath(), _TRUNCATE);
SetDlgItemText(GetParent(hwndCombobox), IDC_SKINROOTFOLDER, tszSkinRoot);
mir_sntprintf(tszFindMask, MAX_PATH, _T("%s*.*"), tszSkinRoot);
diff --git a/plugins/TabSRMM/src/sendlater.cpp b/plugins/TabSRMM/src/sendlater.cpp index 57554d9e8a..fc800e8194 100644 --- a/plugins/TabSRMM/src/sendlater.cpp +++ b/plugins/TabSRMM/src/sendlater.cpp @@ -127,7 +127,7 @@ CSendLaterJob::~CSendLaterJob() POPUPDATAT ppd = {0};
ppd.lchContact = hContact;
- mir_sntprintf(ppd.lptzContactName, MAX_CONTACTNAME, _T("%s"), tszName ? tszName : TranslateT("'(Unknown Contact)'"));
+ _tcsncpy_s(ppd.lptzContactName, (tszName ? tszName : TranslateT("'(Unknown Contact)'")), _TRUNCATE);
TCHAR *msgPreview = Utils::GetPreviewWithEllipsis(reinterpret_cast<TCHAR *>(&pBuf[mir_strlen((char *)pBuf) + 1]), 100);
if (fSuccess) {
mir_sntprintf(ppd.lptzText, MAX_SECONDLINE, TranslateT("A send later job completed successfully.\nThe original message: %s"),
@@ -603,7 +603,7 @@ void CSendLater::qMgrFillList(bool fClear) ::SendMessage(m_hwndList, LVM_SETITEM, 0, LPARAM(&lvItem));
if (p->lastSent == 0)
- mir_sntprintf(tszTimestamp, 30, _T("%s"), _T("Never"));
+ _tcsncpy_s(tszTimestamp, _T("Never"), _TRUNCATE);
else {
_tcsftime(tszTimestamp, 30, formatTime, _localtime32((__time32_t *)&p->lastSent));
tszTimestamp[29] = 0;
diff --git a/plugins/TabSRMM/src/sendqueue.cpp b/plugins/TabSRMM/src/sendqueue.cpp index 310d7717af..6cc6dd33e4 100644 --- a/plugins/TabSRMM/src/sendqueue.cpp +++ b/plugins/TabSRMM/src/sendqueue.cpp @@ -52,7 +52,7 @@ void SendQueue::handleError(TWindowData *dat, const int iEntry) const TCHAR szErrorMsg[500]; dat->iCurrentQueueError = iEntry; - mir_sntprintf(szErrorMsg, 500, _T("%s"), m_jobs[iEntry].szErrorMsg); + _tcsncpy_s(szErrorMsg, m_jobs[iEntry].szErrorMsg, _TRUNCATE); logError(dat, iEntry, szErrorMsg); recallFailed(dat, iEntry); showErrorControls(dat, TRUE); diff --git a/plugins/TabSRMM/src/sidebar.cpp b/plugins/TabSRMM/src/sidebar.cpp index 572292194b..9c42674cf6 100644 --- a/plugins/TabSRMM/src/sidebar.cpp +++ b/plugins/TabSRMM/src/sidebar.cpp @@ -146,7 +146,7 @@ const SIZE& CSideBarButton::measureItem() HFONT oldFont = reinterpret_cast<HFONT>(::SelectObject(dc, ::GetStockObject(DEFAULT_GUI_FONT)));
- mir_sntprintf(tszLabel, 255, _T("%s"), m_dat->newtitle);
+ _tcsncpy_s(tszLabel, m_dat->newtitle, _TRUNCATE);
::GetTextExtentPoint32(dc, tszLabel, (int)mir_tstrlen(tszLabel), &sz);
sz.cx += 28;
diff --git a/plugins/TabSRMM/src/templates.cpp b/plugins/TabSRMM/src/templates.cpp index fe20910d98..34595e958e 100644 --- a/plugins/TabSRMM/src/templates.cpp +++ b/plugins/TabSRMM/src/templates.cpp @@ -86,7 +86,7 @@ static void LoadTemplatesFrom(TTemplateSet *tSet, MCONTACT hContact, int rtl) if (db_get_ts(hContact, rtl ? RTLTEMPLATES_MODULE : TEMPLATES_MODULE, TemplateNames[i], &dbv)) continue; if (dbv.type == DBVT_ASCIIZ || dbv.type == DBVT_WCHAR) - mir_sntprintf(tSet->szTemplates[i], TEMPLATE_LENGTH, _T("%s"), dbv.ptszVal); + _tcsncpy_s(tSet->szTemplates[i], dbv.ptszVal, _TRUNCATE); db_free(&dbv); } } diff --git a/plugins/TabSRMM/src/themeio.cpp b/plugins/TabSRMM/src/themeio.cpp index de900af22d..35b2c36e2d 100644 --- a/plugins/TabSRMM/src/themeio.cpp +++ b/plugins/TabSRMM/src/themeio.cpp @@ -400,9 +400,9 @@ void TSAPI ReadThemeFromINI(const TCHAR *szIniFilenameT, TContainerData *dat, in db_set_utf(NULL, TEMPLATES_MODULE, TemplateNames[i], szTemplateBuffer);
decoded = mir_utf8decodeW(szTemplateBuffer);
if (dat == 0)
- mir_sntprintf(LTR_Active.szTemplates[i], TEMPLATE_LENGTH, L"%s", decoded);
+ _tcsncpy_s(LTR_Active.szTemplates[i], decoded, _TRUNCATE);
else
- mir_sntprintf(dat->ltr_templates->szTemplates[i], TEMPLATE_LENGTH, L"%s", decoded);
+ _tcsncpy_s(dat->ltr_templates->szTemplates[i], decoded, _TRUNCATE);
mir_free(decoded);
}
@@ -413,9 +413,9 @@ void TSAPI ReadThemeFromINI(const TCHAR *szIniFilenameT, TContainerData *dat, in db_set_utf(NULL, RTLTEMPLATES_MODULE, TemplateNames[i], szTemplateBuffer);
decoded = mir_utf8decodeW(szTemplateBuffer);
if (dat == 0)
- mir_sntprintf(RTL_Active.szTemplates[i], TEMPLATE_LENGTH, L"%s", decoded);
+ _tcsncpy_s(RTL_Active.szTemplates[i], decoded, _TRUNCATE);
else
- mir_sntprintf(dat->rtl_templates->szTemplates[i], TEMPLATE_LENGTH, L"%s", decoded);
+ _tcsncpy_s(dat->rtl_templates->szTemplates[i], decoded, _TRUNCATE);
mir_free(decoded);
}
}
@@ -435,7 +435,7 @@ const TCHAR* TSAPI GetThemeFileName(int iMode) OPENFILENAME ofn = {0};
TCHAR szInitialDir[MAX_PATH];
- mir_sntprintf(szInitialDir, MAX_PATH, _T("%s"), M.getSkinPath());
+ _tcsncpy_s(szInitialDir, M.getSkinPath(), _TRUNCATE);
szFilename[0] = 0;
diff --git a/plugins/TabSRMM/src/themes.cpp b/plugins/TabSRMM/src/themes.cpp index 48877e878e..e7cde034cd 100644 --- a/plugins/TabSRMM/src/themes.cpp +++ b/plugins/TabSRMM/src/themes.cpp @@ -2441,7 +2441,7 @@ void CSkin::setAeroEffect(LRESULT effect) void CSkin::extractSkinsAndLogo(bool fForceOverwrite) const
{
TCHAR tszBasePath[MAX_PATH];
- mir_sntprintf(tszBasePath, MAX_PATH, _T("%s"), M.getDataPath());
+ _tcsncpy_s(tszBasePath, M.getDataPath(), _TRUNCATE);
if (tszBasePath[mir_tstrlen(tszBasePath) - 1] != '\\')
_tcscat(tszBasePath, _T("\\"));
diff --git a/plugins/TabSRMM/src/trayicon.cpp b/plugins/TabSRMM/src/trayicon.cpp index 0e792c6617..5a75484758 100644 --- a/plugins/TabSRMM/src/trayicon.cpp +++ b/plugins/TabSRMM/src/trayicon.cpp @@ -141,7 +141,7 @@ void TSAPI CreateSystrayIcon(int create) nim.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
nim.hIcon = PluginConfig.g_iconContainer;
nim.uCallbackMessage = DM_TRAYICONNOTIFY;
- mir_sntprintf(nim.szTip, 64, _T("%s"), _T("tabSRMM"));
+ _tcsncpy_s(nim.szTip, _T("tabSRMM"), _TRUNCATE);
if (create && !nen_options.bTrayExist) {
Shell_NotifyIcon(NIM_ADD, &nim);
nen_options.bTrayExist = TRUE;
@@ -230,11 +230,9 @@ void TSAPI AddContactToFavorites(MCONTACT hContact, const TCHAR *szNickname, con TCHAR szFinalNick[100];
if (szNickname == NULL)
- mir_sntprintf(szFinalNick, SIZEOF(szFinalNick), _T("%s"), pcli->pfnGetContactDisplayName(hContact, 0));
- else {
- _tcsncpy(szFinalNick, szNickname, 100);
- szFinalNick[99] = 0;
- }
+ _tcsncpy_s(szFinalNick, pcli->pfnGetContactDisplayName(hContact, 0), _TRUNCATE);
+ else
+ _tcsncpy_s(szFinalNick, szNickname, _TRUNCATE);
if (szProto == NULL)
szProto = GetContactProto(hContact);
diff --git a/plugins/TabSRMM/src/utils.cpp b/plugins/TabSRMM/src/utils.cpp index fb7541e440..6fe641661b 100644 --- a/plugins/TabSRMM/src/utils.cpp +++ b/plugins/TabSRMM/src/utils.cpp @@ -487,8 +487,8 @@ TCHAR* Utils::GetPreviewWithEllipsis(TCHAR *szText, size_t iMaxLen) *p = 0;
uRequired = (p - szText) + 6;
}
- TCHAR *szResult = reinterpret_cast<TCHAR *>(mir_alloc(uRequired * sizeof(TCHAR)));
- mir_sntprintf(szResult, uRequired, fEllipsis ? _T("%s...") : _T("%s"), szText);
+ TCHAR *szResult = reinterpret_cast<TCHAR *>(mir_alloc((uRequired + 1) * sizeof(TCHAR)));
+ mir_sntprintf(szResult, (uRequired + 1), fEllipsis ? _T("%s...") : _T("%s"), szText);
if (p)
*p = cSaved;
diff --git a/plugins/Utils/mir_options.cpp b/plugins/Utils/mir_options.cpp index 7d7e9fdbc3..ea8844b93b 100644 --- a/plugins/Utils/mir_options.cpp +++ b/plugins/Utils/mir_options.cpp @@ -76,10 +76,9 @@ static void PathToRelative(TCHAR *pOut, size_t outSize, const TCHAR *pSrc) }
size_t len = mir_tstrlen(dbPath);
- if (_tcsnicmp(pSrc, dbPath, len))
- mir_sntprintf(pOut, outSize, _T("%s"), pSrc + len);
- else
- mir_tstrncpy(pOut, pSrc, (int)outSize);
+ if (!_tcsnicmp(pSrc, dbPath, len))
+ len = 0;
+ _tcsncpy_s(pOut, outSize, (pSrc + len), _TRUNCATE);
}
}
diff --git a/plugins/Weather/src/weather_conv.cpp b/plugins/Weather/src/weather_conv.cpp index c375c9d95f..4a0a734392 100644 --- a/plugins/Weather/src/weather_conv.cpp +++ b/plugins/Weather/src/weather_conv.cpp @@ -109,7 +109,7 @@ void GetTemp(TCHAR *tempchar, TCHAR *unit, TCHAR* str) // rounding
numToStr((temp-32)/9*5, tstr, SIZEOF(tstr));
if (opt.DoNotAppendUnit)
- mir_sntprintf(str, MAX_DATA_LEN, _T("%s"), tstr);
+ _tcsncpy_s(str, MAX_DATA_LEN, tstr, _TRUNCATE);
else
mir_sntprintf(str, MAX_DATA_LEN, _T("%s%sC"), tstr, opt.DegreeSign);
break;
@@ -117,7 +117,7 @@ void GetTemp(TCHAR *tempchar, TCHAR *unit, TCHAR* str) case 2:
numToStr(temp, tstr, SIZEOF(tstr));
if (opt.DoNotAppendUnit)
- mir_sntprintf(str, MAX_DATA_LEN, _T("%s"), tstr);
+ _tcsncpy_s(str, MAX_DATA_LEN, tstr, _TRUNCATE);
else
mir_sntprintf(str, MAX_DATA_LEN, _T("%s%sF"), tstr, opt.DegreeSign);
break;
@@ -394,8 +394,8 @@ WORD GetIcon(const TCHAR* cond, WIDATA *Data) j++;
// using the format _T("# Weather <condition name> <counter> #"
mir_sntprintf(LangPackStr, SIZEOF(LangPackStr), _T("# Weather %s %i #"), statusStr[i], j);
- mir_sntprintf(LangPackStr1, SIZEOF(LangPackStr1), _T("%s"), TranslateTS(LangPackStr));
- CharLowerBuff(LangPackStr1, (DWORD)_tcslen(LangPackStr1));
+ _tcsncpy_s(LangPackStr1, TranslateTS(LangPackStr), _TRUNCATE);
+ CharLowerBuff(LangPackStr1, _tcslen(LangPackStr1));
if (_tcsstr(cond, LangPackStr1) != NULL)
return statusValue[i];
// loop until the translation string exists (ie, the translated string is differ from original)
diff --git a/plugins/YAMN/src/browser/mailbrowser.cpp b/plugins/YAMN/src/browser/mailbrowser.cpp index 125365ec54..6b0cd74b25 100644 --- a/plugins/YAMN/src/browser/mailbrowser.cpp +++ b/plugins/YAMN/src/browser/mailbrowser.cpp @@ -1479,14 +1479,14 @@ INT_PTR CALLBACK DlgProcYAMNShowMessage(HWND hDlg,UINT msg,WPARAM wParam,LPARAM WCHAR *title=0; size_t size = (From ? wcslen(From) : 0) + (Subj ? wcslen(Subj) : 0) + 4; title = new WCHAR[size]; - if (From&&Subj) + if (From && Subj) mir_sntprintf(title, size, L"%s (%s)", Subj, From); else if (From) - mir_sntprintf(title, size, L"%s", From); + _tcsncpy_s(title, size, From, _TRUNCATE); else if (Subj) - mir_sntprintf(title, size, L"%s", Subj); + _tcsncpy_s(title, size, Subj, _TRUNCATE); else - mir_sntprintf(title, size, L"none"); + _tcsncpy_s(title, size, L"none", _TRUNCATE); if (Subj) delete[] Subj; if (From) delete[] From; SendMessageW(hDlg,WM_SETTEXT,0,(LPARAM)title); |