[FRAG] Fix usage of non-conforming swprintf

This commit is contained in:
Timo Kreuzer
2026-05-07 06:27:58 +00:00
parent 81b230dc80
commit 3b7960e2f8
4 changed files with 15 additions and 4 deletions
@@ -1,4 +1,6 @@
remove_definitions(-D_CRT_NON_CONFORMING_SWPRINTFS)
list(APPEND SOURCE
Fraginator.cpp
MainDialog.cpp
@@ -6,7 +6,7 @@
// and fits it to a given length. If it has to truncate it will first truncate from the path,
// substituting in periods. So you might end up with something like:
// C:\Program Files\Micro...\Register.exe
int FitName (wchar_t *destination, const wchar_t *path, const wchar_t *filename, uint32 totalWidth)
int FitName (wchar_t *destination, size_t destsize, const wchar_t *path, const wchar_t *filename, uint32 totalWidth)
{
uint32 pathLen=0;
uint32 fnLen=0;
@@ -73,7 +73,7 @@ int FitName (wchar_t *destination, const wchar_t *path, const wchar_t *filename,
wcscpy (fmtString, fmtStrPath);
wcscat (fmtString, fmtStrFile);
/*swprintf (fmtString, L"%s%s", fmtStrPath, fmtStrFile);*/
swprintf (destination, fmtString, path,filename);
swprintf(destination, destsize, fmtString, path,filename);
return (1);
}
@@ -316,7 +316,7 @@ void Defragment::Start (void)
SetStatusString (Volume.GetDBDir (Info.DirIndice) + Info.Name);
else
{
FitName (PrintName, Volume.GetDBDir (Info.DirIndice).c_str(), Info.Name.c_str(), Width);
FitName (PrintName, _countof(PrintName), Volume.GetDBDir (Info.DirIndice).c_str(), Info.Name.c_str(), Width);
SetStatusString (PrintName);
}
@@ -14,7 +14,7 @@
#include "Mutex.h"
extern int FitName (wchar_t *destination, const wchar_t *path, const wchar_t *filename, uint32 totalWidth);
extern int FitName (wchar_t *destination, size_t destsize, const wchar_t *path, const wchar_t *filename, uint32 totalWidth);
typedef struct DefragReport
@@ -82,5 +82,14 @@ extern Defragment *StartDefragThread (wstring Drive, DefragType Method, HANDLE &
extern wchar_t *AddCommas (wchar_t *Result, uint64 Number);
template <size_t _Size>
inline
_Success_(return >= 0) int __CRTDECL swprintf(wchar_t (&_Buffer)[_Size], wchar_t const* _Format, ...)
{
va_list _ArgList;
va_start(_ArgList, _Format);
return vswprintf(_Buffer, _Size, _Format, _ArgList);
}
#endif // UNFRAG_H