Fix scanf buffer size
This was SVN commit r7242.
This commit is contained in:
parent
b0dcf49893
commit
33ab686128
@ -55,4 +55,12 @@ public:
|
|||||||
TS_ASSERT_WSTR_EQUALS(t4.Pathname().string(), L"example two.txt");
|
TS_ASSERT_WSTR_EQUALS(t4.Pathname().string(), L"example two.txt");
|
||||||
TS_ASSERT_EQUALS(t4.Size(), (size_t)16777216);
|
TS_ASSERT_EQUALS(t4.Size(), (size_t)16777216);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_maxpath()
|
||||||
|
{
|
||||||
|
std::wstring path1 = std::wstring(PATH_MAX, L'x');
|
||||||
|
std::wstring buf1 = L"0: L \"" + path1 + L"\" 0\n";
|
||||||
|
TraceEntry t1(buf1);
|
||||||
|
TS_ASSERT_WSTR_EQUALS(t1.Pathname().string(), path1);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
@ -49,14 +49,14 @@ TraceEntry::TraceEntry(EAction action, const fs::wpath& pathname, size_t size)
|
|||||||
|
|
||||||
TraceEntry::TraceEntry(const std::wstring& text)
|
TraceEntry::TraceEntry(const std::wstring& text)
|
||||||
{
|
{
|
||||||
wchar_t pathname[PATH_MAX] = L"";
|
wchar_t pathname[PATH_MAX+1] = L""; // includes space for terminator
|
||||||
wchar_t action;
|
wchar_t action;
|
||||||
#if EMULATE_SECURE_CRT
|
#if EMULATE_SECURE_CRT
|
||||||
#define TRACE_FORMAT L"%f: %lc \"%" STRINGIZE(PATH_MAX) "l[^\"]\" %zd\n" /* use a macro to allow compile-time type-checking */
|
#define TRACE_FORMAT L"%f: %lc \"%" STRINGIZE(PATH_MAX) "l[^\"]\" %zd\n" /* use a macro to allow compile-time type-checking */
|
||||||
const int fieldsRead = swscanf(text.c_str(), TRACE_FORMAT, &m_timestamp, &action, pathname, &m_size);
|
const int fieldsRead = swscanf(text.c_str(), TRACE_FORMAT, &m_timestamp, &action, pathname, &m_size);
|
||||||
#else
|
#else
|
||||||
#define TRACE_FORMAT L"%f: %lc \"%l[^\"]\" %d\n"
|
#define TRACE_FORMAT L"%f: %lc \"%l[^\"]\" %d\n"
|
||||||
const int fieldsRead = swscanf_s(text.c_str(), TRACE_FORMAT, &m_timestamp, &action, 1, pathname, PATH_MAX, &m_size);
|
const int fieldsRead = swscanf_s(text.c_str(), TRACE_FORMAT, &m_timestamp, &action, 1, pathname, ARRAY_SIZE(pathname), &m_size);
|
||||||
#endif
|
#endif
|
||||||
debug_assert(fieldsRead == 4);
|
debug_assert(fieldsRead == 4);
|
||||||
debug_assert(action == 'L' || action == 'S');
|
debug_assert(action == 'L' || action == 'S');
|
||||||
|
Loading…
Reference in New Issue
Block a user