Fix nullptr access
parent
d12b1e8d70
commit
5a6498af92
|
@ -60,19 +60,32 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
using namespace Assimp;
|
using namespace Assimp;
|
||||||
|
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
|
||||||
|
const std::wstring wdummy;
|
||||||
|
|
||||||
static std::wstring Utf8ToWide(const char *in) {
|
static std::wstring Utf8ToWide(const char *in) {
|
||||||
|
if (nullptr == in) {
|
||||||
|
return wdummy;
|
||||||
|
}
|
||||||
int size = MultiByteToWideChar(CP_UTF8, 0, in, -1, nullptr, 0);
|
int size = MultiByteToWideChar(CP_UTF8, 0, in, -1, nullptr, 0);
|
||||||
// size includes terminating null; std::wstring adds null automatically
|
// size includes terminating null; std::wstring adds null automatically
|
||||||
std::wstring out(static_cast<size_t>(size) - 1, L'\0');
|
std::wstring out(static_cast<size_t>(size) - 1, L'\0');
|
||||||
MultiByteToWideChar(CP_UTF8, 0, in, -1, &out[0], size);
|
MultiByteToWideChar(CP_UTF8, 0, in, -1, &out[0], size);
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::wstring dummy;
|
||||||
|
|
||||||
static std::string WideToUtf8(const wchar_t *in) {
|
static std::string WideToUtf8(const wchar_t *in) {
|
||||||
|
if (nullptr == in) {
|
||||||
|
return dummy;
|
||||||
|
}
|
||||||
int size = WideCharToMultiByte(CP_UTF8, 0, in, -1, nullptr, 0, nullptr, nullptr);
|
int size = WideCharToMultiByte(CP_UTF8, 0, in, -1, nullptr, 0, nullptr, nullptr);
|
||||||
// size includes terminating null; std::string adds null automatically
|
// size includes terminating null; std::string adds null automatically
|
||||||
std::string out(static_cast<size_t>(size) - 1, '\0');
|
std::string out(static_cast<size_t>(size) - 1, '\0');
|
||||||
WideCharToMultiByte(CP_UTF8, 0, in, -1, &out[0], size, nullptr, nullptr);
|
WideCharToMultiByte(CP_UTF8, 0, in, -1, &out[0], size, nullptr, nullptr);
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -104,7 +117,12 @@ IOStream *DefaultIOSystem::Open(const char *strFile, const char *strMode) {
|
||||||
ai_assert(strMode != nullptr);
|
ai_assert(strMode != nullptr);
|
||||||
FILE *file;
|
FILE *file;
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
file = ::_wfopen(Utf8ToWide(strFile).c_str(), Utf8ToWide(strMode).c_str());
|
std::string name = Utf8ToWide(strFile).c_str();
|
||||||
|
if (name.empty()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
file = ::_wfopen(, Utf8ToWide(strMode).c_str());
|
||||||
#else
|
#else
|
||||||
file = ::fopen(strFile, strMode);
|
file = ::fopen(strFile, strMode);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue