Skip to content

Commit e04c15c

Browse files
authored
WaveFrontReader updated to fail on non-text data files (#227)
1 parent a44475c commit e04c15c

File tree

2 files changed

+39
-8
lines changed

2 files changed

+39
-8
lines changed

Utilities/WaveFrontReader.h

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#endif
4646

4747
#include <algorithm>
48+
#include <cctype>
4849
#include <cstdint>
4950
#include <fstream>
5051
#include <locale>
@@ -122,7 +123,11 @@ namespace DX
122123
if (!InFile)
123124
break;
124125

125-
if (*strCommand.c_str() == L'#')
126+
if (strCommand.empty() || *strCommand.c_str() == 0)
127+
{
128+
continue;
129+
}
130+
else if (*strCommand.c_str() == L'#')
126131
{
127132
// Comment
128133
}
@@ -372,6 +377,11 @@ namespace DX
372377
materials.emplace_back(mat);
373378
}
374379
}
380+
else if (!std::isprint(*strCommand.c_str()))
381+
{
382+
// non-printable characters outside of comments mean this is not a text file
383+
return E_FAIL;
384+
}
375385
else
376386
{
377387
#ifdef _DEBUG
@@ -437,6 +447,7 @@ namespace DX
437447
InFile.imbue(std::locale::classic());
438448

439449
auto curMaterial = materials.end();
450+
bool foundmat = false;
440451

441452
for (;; )
442453
{
@@ -445,8 +456,19 @@ namespace DX
445456
if (!InFile)
446457
break;
447458

448-
if (0 == wcscmp(strCommand.c_str(), L"newmtl"))
459+
if (strCommand.empty() || *strCommand.c_str() == 0)
460+
continue;
461+
462+
if (*strCommand.c_str() == L'#')
463+
{
464+
// Comment
465+
InFile.ignore(1000, L'\n');
466+
continue;
467+
}
468+
else if (0 == wcscmp(strCommand.c_str(), L"newmtl"))
449469
{
470+
foundmat = true;
471+
450472
// Switching active materials
451473
wchar_t strName[MAX_PATH] = {};
452474
InFile.width(MAX_PATH);
@@ -462,16 +484,17 @@ namespace DX
462484
}
463485
}
464486
}
487+
else if (!std::isprint(*strCommand.c_str()))
488+
{
489+
// non-printable characters outside of comments mean this is not a text file
490+
return E_FAIL;
491+
}
465492

466493
// The rest of the commands rely on an active material
467494
if (curMaterial == materials.end())
468495
continue;
469496

470-
if (0 == wcscmp(strCommand.c_str(), L"#"))
471-
{
472-
// Comment
473-
}
474-
else if (0 == wcscmp(strCommand.c_str(), L"Ka"))
497+
if (0 == wcscmp(strCommand.c_str(), L"Ka"))
475498
{
476499
// Ambient color
477500
float r, g, b;
@@ -570,7 +593,7 @@ namespace DX
570593

571594
InFile.close();
572595

573-
return S_OK;
596+
return (foundmat) ? S_OK : E_FAIL;
574597
}
575598

576599
void Clear()

build/CompilerAndLinker.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang|IntelLLVM")
119119
if(WINDOWS_STORE)
120120
list(APPEND COMPILER_DEFINES _SILENCE_CLANG_COROUTINE_MESSAGE)
121121
endif()
122+
123+
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 10.0)
124+
list(APPEND COMPILER_SWITCHES -Wc++20-compat)
125+
endif()
126+
127+
if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 19.0)
128+
list(APPEND COMPILER_SWITCHES -Wc++23-compat)
129+
endif()
122130
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Intel")
123131
list(APPEND COMPILER_SWITCHES /Zc:__cplusplus /Zc:inline /fp:fast /Qdiag-disable:161)
124132
elseif(CMAKE_CXX_COMPILER_ID MATCHES "MSVC")

0 commit comments

Comments
 (0)