Code enhancement: use conformant code

Fix #12818, close #12819
pull/12838/head
ozone10 2 years ago committed by Don Ho
parent f8593916a9
commit 8add866460

@ -37,6 +37,12 @@ const bool dirDown = false;
#define BCKGRD_COLOR (RGB(255,102,102))
#define TXT_COLOR (RGB(255,255,255))
#ifndef __MINGW32__
#define WCSTOK wcstok
#else
#define WCSTOK wcstok_s
#endif
#define generic_atoi _wtoi
#define generic_itoa _itow
#define generic_fprintf fwprintf

@ -664,8 +664,9 @@ void PluginsManager::runPluginCommand(size_t i)
}
catch (...)
{
TCHAR funcInfo[128];
generic_sprintf(funcInfo, TEXT("runPluginCommand(size_t i : %zd)"), i);
constexpr size_t bufSize = 128;
TCHAR funcInfo[bufSize] = { '\0' };
generic_sprintf(funcInfo, bufSize, TEXT("runPluginCommand(size_t i : %zd)"), i);
pluginCrashAlert(_pluginsCommands[i]._pluginName.c_str(), funcInfo);
}
}
@ -691,8 +692,9 @@ void PluginsManager::runPluginCommand(const TCHAR *pluginName, int commandID)
}
catch (...)
{
TCHAR funcInfo[128];
generic_sprintf(funcInfo, TEXT("runPluginCommand(const TCHAR *pluginName : %s, int commandID : %d)"), pluginName, commandID);
constexpr size_t bufSize = 128;
TCHAR funcInfo[bufSize] = { '\0' };
generic_sprintf(funcInfo, bufSize, TEXT("runPluginCommand(const TCHAR *pluginName : %s, int commandID : %d)"), pluginName, commandID);
pluginCrashAlert(_pluginsCommands[i]._pluginName.c_str(), funcInfo);
}
}
@ -721,8 +723,9 @@ void PluginsManager::notify(size_t indexPluginInfo, const SCNotification *notifi
}
catch (...)
{
TCHAR funcInfo[256];
generic_sprintf(funcInfo, TEXT("notify(SCNotification *notification) : \r notification->nmhdr.code == %d\r notification->nmhdr.hwndFrom == %p\r notification->nmhdr.idFrom == %" PRIuPTR), \
constexpr size_t bufSize = 256;
TCHAR funcInfo[bufSize] = { '\0' };
generic_sprintf(funcInfo, bufSize, TEXT("notify(SCNotification *notification) : \r notification->nmhdr.code == %d\r notification->nmhdr.hwndFrom == %p\r notification->nmhdr.idFrom == %" PRIuPTR), \
scNotif.nmhdr.code, scNotif.nmhdr.hwndFrom, scNotif.nmhdr.idFrom);
pluginCrashAlert(_pluginInfos[indexPluginInfo]->_moduleName.c_str(), funcInfo);
}
@ -759,8 +762,9 @@ void PluginsManager::relayNppMessages(UINT Message, WPARAM wParam, LPARAM lParam
}
catch (...)
{
TCHAR funcInfo[128];
generic_sprintf(funcInfo, TEXT("relayNppMessages(UINT Message : %u, WPARAM wParam : %" PRIuPTR ", LPARAM lParam : %" PRIiPTR ")"), Message, wParam, lParam);
constexpr size_t bufSize = 128;
TCHAR funcInfo[bufSize] = { '\0' };
generic_sprintf(funcInfo, bufSize, TEXT("relayNppMessages(UINT Message : %u, WPARAM wParam : %" PRIuPTR ", LPARAM lParam : %" PRIiPTR ")"), Message, wParam, lParam);
pluginCrashAlert(_pluginInfos[i]->_moduleName.c_str(), funcInfo);
}
}
@ -790,8 +794,9 @@ bool PluginsManager::relayPluginMessages(UINT Message, WPARAM wParam, LPARAM lPa
}
catch (...)
{
TCHAR funcInfo[128];
generic_sprintf(funcInfo, TEXT("relayPluginMessages(UINT Message : %u, WPARAM wParam : %" PRIuPTR ", LPARAM lParam : %" PRIiPTR ")"), Message, wParam, lParam);
constexpr size_t bufSize = 128;
TCHAR funcInfo[bufSize] = { '\0' };
generic_sprintf(funcInfo, bufSize, TEXT("relayPluginMessages(UINT Message : %u, WPARAM wParam : %" PRIuPTR ", LPARAM lParam : %" PRIiPTR ")"), Message, wParam, lParam);
pluginCrashAlert(_pluginInfos[i]->_moduleName.c_str(), funcInfo);
}
return true;

@ -3165,7 +3165,8 @@ bool ScintillaEditView::expandWordSelection()
TCHAR * int2str(TCHAR *str, int strLen, int number, int base, int nbChiffre, bool isZeroLeading)
{
if (nbChiffre >= strLen) return NULL;
TCHAR f[64];
constexpr size_t bufSize = 64;
TCHAR f[bufSize] = { '\0' };
TCHAR fStr[2] = TEXT("d");
if (base == 16)
fStr[0] = 'X';
@ -3200,8 +3201,8 @@ TCHAR * int2str(TCHAR *str, int strLen, int number, int base, int nbChiffre, boo
{
// use sprintf or swprintf instead of wsprintf
// to make octal format work
generic_sprintf(f, TEXT("%%%s"), fStr);
generic_sprintf(str, f, number);
generic_sprintf(f, bufSize, TEXT("%%%s"), fStr);
generic_sprintf(str, strLen, f, number);
}
int i = lstrlen(str);
for ( ; i < nbChiffre ; ++i)
@ -3214,8 +3215,8 @@ TCHAR * int2str(TCHAR *str, int strLen, int number, int base, int nbChiffre, boo
{
// use sprintf or swprintf instead of wsprintf
// to make octal format work
generic_sprintf(f, TEXT("%%.%d%s"), nbChiffre, fStr);
generic_sprintf(str, f, number);
generic_sprintf(f, bufSize, TEXT("%%.%d%s"), nbChiffre, fStr);
generic_sprintf(str, strLen, f, number);
}
// else already done.
}

@ -210,11 +210,14 @@ intptr_t CALLBACK DebugInfoDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
HKEY hKey;
DWORD dataSize = 0;
TCHAR szProductName[96] = {'\0'};
TCHAR szCurrentBuildNumber[32] = {'\0'};
constexpr size_t bufSize = 96;
TCHAR szProductName[bufSize] = {'\0'};
constexpr size_t bufSizeBuildNumber = 32;
TCHAR szCurrentBuildNumber[bufSizeBuildNumber] = {'\0'};
TCHAR szReleaseId[32] = {'\0'};
DWORD dwUBR = 0;
TCHAR szUBR[12] = TEXT("0");
constexpr size_t bufSizeUBR = 12;
TCHAR szUBR[bufSizeUBR] = TEXT("0");
// NOTE: RegQueryValueExW is not guaranteed to return null-terminated strings
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"), 0, KEY_READ, &hKey) == ERROR_SUCCESS)
@ -238,7 +241,7 @@ intptr_t CALLBACK DebugInfoDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
dataSize = sizeof(DWORD);
if (RegQueryValueExW(hKey, TEXT("UBR"), NULL, NULL, reinterpret_cast<LPBYTE>(&dwUBR), &dataSize) == ERROR_SUCCESS)
{
generic_sprintf(szUBR, TEXT("%u"), dwUBR);
generic_sprintf(szUBR, bufSizeUBR, TEXT("%u"), dwUBR);
}
RegCloseKey(hKey);
@ -247,19 +250,19 @@ intptr_t CALLBACK DebugInfoDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
// Get alternative OS information
if (szProductName[0] == '\0')
{
generic_sprintf(szProductName, TEXT("%s"), (NppParameters::getInstance()).getWinVersionStr().c_str());
generic_sprintf(szProductName, bufSize, TEXT("%s"), (NppParameters::getInstance()).getWinVersionStr().c_str());
}
// Override ProductName if it's Windows 11
if (NppDarkMode::isWindows11())
generic_sprintf(szProductName, TEXT("%s"), TEXT("Windows 11"));
generic_sprintf(szProductName, bufSize, TEXT("%s"), TEXT("Windows 11"));
if (szCurrentBuildNumber[0] == '\0')
{
DWORD dwVersion = GetVersion();
if (dwVersion < 0x80000000)
{
generic_sprintf(szCurrentBuildNumber, TEXT("%u"), HIWORD(dwVersion));
generic_sprintf(szCurrentBuildNumber, bufSizeBuildNumber, TEXT("%u"), HIWORD(dwVersion));
}
}
@ -287,8 +290,9 @@ intptr_t CALLBACK DebugInfoDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
}
{
TCHAR szACP[32];
generic_sprintf(szACP, TEXT("%u"), ::GetACP());
constexpr size_t bufSizeACP = 32;
TCHAR szACP[bufSizeACP] = { '\0' };
generic_sprintf(szACP, bufSizeACP, TEXT("%u"), ::GetACP());
_debugInfoStr += TEXT("Current ANSI codepage : ");
_debugInfoStr += szACP;
_debugInfoStr += TEXT("\r\n");
@ -304,8 +308,9 @@ intptr_t CALLBACK DebugInfoDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
if (pWGV != nullptr)
{
TCHAR szWINEVersion[32];
generic_sprintf(szWINEVersion, TEXT("%hs"), pWGV());
constexpr size_t bufSizeWineVer = 32;
TCHAR szWINEVersion[bufSizeWineVer] = { '\0' };
generic_sprintf(szWINEVersion, bufSizeWineVer, TEXT("%hs"), pWGV());
_debugInfoStr += TEXT("WINE : ");
_debugInfoStr += szWINEVersion;

@ -389,30 +389,31 @@ void AsciiListView::setValues(int codepage)
for (int i = 0 ; i < 256 ; ++i)
{
TCHAR dec[8];
TCHAR hex[8];
TCHAR htmlNumber[8];
constexpr size_t bufSize = 8;
TCHAR dec[bufSize];
TCHAR hex[bufSize];
TCHAR htmlNumber[bufSize];
generic_string htmlName;
generic_sprintf(dec, TEXT("%d"), i);
generic_sprintf(hex, TEXT("%02X"), i);
generic_sprintf(dec, bufSize, TEXT("%d"), i);
generic_sprintf(hex, bufSize, TEXT("%02X"), i);
generic_string s = getAscii(static_cast<unsigned char>(i));
if (codepage == 0 || codepage == 1252)
{
if ((i >= 32 && i <= 126) || (i >= 160 && i <= 255))
{
generic_sprintf(htmlNumber, TEXT("&#%d"), i);
generic_sprintf(htmlNumber, bufSize, TEXT("&#%d"), i);
}
else
{
int n = getHtmlNumber(static_cast<unsigned char>(i));
if (n > -1)
{
generic_sprintf(htmlNumber, TEXT("&#%d"), n);
generic_sprintf(htmlNumber, bufSize, TEXT("&#%d"), n);
}
else
{
generic_sprintf(htmlNumber, TEXT(""));
generic_sprintf(htmlNumber, bufSize, TEXT(""));
}
}
@ -420,7 +421,7 @@ void AsciiListView::setValues(int codepage)
}
else
{
generic_sprintf(htmlNumber, TEXT(""));
generic_sprintf(htmlNumber, bufSize, TEXT(""));
htmlName = TEXT("");
}

@ -1309,21 +1309,19 @@ void SizeGrid(HWND hWnd,int /*SI*/)
int FindLongestLine(HDC hdc, wchar_t* text, SIZE* size)
{
int longest = 0;
wchar_t temptext[1000];
wchar_t *p;
int longest = 0;
wchar_t* buffer = nullptr;
wchar_t* token = WCSTOK(text, TEXT("\n"), &buffer);;
wcscpy_s(temptext, text);
p = wcstok(temptext, TEXT("\n"));
while (p)
while (token)
{
GetTextExtentPoint32(hdc, p, lstrlen(p), size);
::GetTextExtentPoint32(hdc, token, lstrlen(token), size);
if (size->cx > longest)
{
longest=size->cx;
}
wchar_t temptext2[2] = {'\0'};
p = wcstok(temptext2, TEXT("\n"));
token = WCSTOK(nullptr, TEXT("\n"), &buffer);
}
return longest;
}

@ -12,7 +12,7 @@
<ItemDefinitionGroup Label="Globals">
<ClCompile>
<AdditionalIncludeDirectories>..\src\WinControls\AboutDlg;..\..\scintilla\include;..\..\lexilla\include;..\include;..\src\WinControls;..\src\WinControls\ImageListSet;..\src\WinControls\OpenSaveFileDialog;..\src\WinControls\SplitterContainer;..\src\WinControls\StaticDialog;..\src\WinControls\TabBar;..\src\WinControls\ToolBar;..\src\MISC\Process;..\src\ScintillaComponent;..\src\MISC;..\src\MISC\SysMsg;..\src\WinControls\StatusBar;..\src;..\src\WinControls\StaticDialog\RunDlg;..\src\tinyxml;..\src\WinControls\ColourPicker;..\src\Win32Explr;..\src\MISC\RegExt;..\src\WinControls\TrayIcon;..\src\WinControls\shortcut;..\src\WinControls\Grid;..\src\WinControls\ContextMenu;..\src\MISC\PluginsManager;..\src\WinControls\Preference;..\src\WinControls\WindowsDlg;..\src\WinControls\TaskList;..\src\WinControls\DockingWnd;..\src\WinControls\TreeView;..\src\WinControls\ToolTip;..\src\MISC\Exception;..\src\MISC\Common;..\src\tinyxml\tinyXmlA;..\src\WinControls\AnsiCharPanel;..\src\WinControls\ClipboardHistory;..\src\WinControls\FindCharsInRange;..\src\WinControls\VerticalFileSwitcher;..\src\WinControls\ProjectPanel;..\src\WinControls\DocumentMap;..\src\WinControls\FunctionList;..\src\uchardet;..\src\WinControls\FileBrowser;..\src\WinControls\ReadDirectoryChanges;..\src\MISC\md5;..\src\WinControls\PluginsAdmin;..\src\json;..\src\MISC\sha2;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_WIN32_WINNT=_WIN32_WINNT_VISTA;_WINDOWS;OEMRESOURCE;NOMINMAX;_USE_64BIT_TIME_T;TIXML_USE_STL;TIXMLA_USE_STL;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;_CRT_NON_CONFORMING_SWPRINTFS;_CRT_NON_CONFORMING_WCSTOK;_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PreprocessorDefinitions>WIN32;_WIN32_WINNT=_WIN32_WINNT_VISTA;_WINDOWS;OEMRESOURCE;NOMINMAX;_USE_64BIT_TIME_T;TIXML_USE_STL;TIXMLA_USE_STL;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ExceptionHandling>Async</ExceptionHandling>
<WarningLevel>Level4</WarningLevel>
<TreatWarningAsError>true</TreatWarningAsError>

Loading…
Cancel
Save