Skip to content

Commit

Permalink
fix(windows): unhandled exception thrown in std::_Xlen_string()
Browse files Browse the repository at this point in the history
An exception is thrown when built with Visual Studio 16.9:

```
Error Message:
  Unhandled C++ Exception
Stack Trace:
  at std::_Xlen_string() in C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.28.29910\include\xstring:line 2276
  at std::basic_string<char,std::char_traits<char>,std::allocator<char> >::_Reallocate_grow_by<<lambda_9013ee9e23efe4882b67eff5b0ecf103> >() in C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.28.29910\include\xstring:line 4337
  at std::basic_string<char,std::char_traits<char>,std::allocator<char> >::reserve() in C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Tools\MSVC\14.28.29910\include\xstring:line 3833
  at ReactTestApp::GetManifest() in D:\a\react-native-test-app\react-native-test-app\example\node_modules\react-native-test-app\windows\ReactTestApp\Manifest.cpp:line 126
  at ReactTestAppTests::ManifestTests::ParseManifestWithComplexInitialProperties() in D:\a\react-native-test-app\react-native-test-app\example\windows\ReactTestAppTests\ManifestTests.cpp:line 70
```
  • Loading branch information
tido64 committed Mar 15, 2021
1 parent 903e7fa commit 009fb0c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ jobs:
steps:
- name: Set up MSBuild
uses: microsoft/[email protected]
- name: Setup VSTest.console.exe
- name: Set up VSTest.console.exe
uses: darenm/Setup-VSTest@v1
- name: Set up Node.js
uses: actions/setup-node@v1
Expand Down
21 changes: 11 additions & 10 deletions windows/ReactTestApp/Manifest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

#include "Manifest.h"

#include <fstream>
#include <iostream>
#include <cstdio>

#include <nlohmann/json.hpp>
#include <winrt/Windows.Security.Cryptography.Core.h>
Expand Down Expand Up @@ -116,16 +115,18 @@ namespace ReactTestApp

std::optional<std::pair<Manifest, std::string>> GetManifest(std::string const &filename)
{
std::string json;
{
std::ifstream stream(filename);
std::FILE *stream = nullptr;
if (std::fopen_s(&stream, filename.c_str(), "rb") != 0) {
return std::nullopt;
}

stream.seekg(0, std::ios::end);
json.reserve(static_cast<size_t>(stream.tellg()));
std::string json;
std::fseek(stream, 0, SEEK_END);
json.resize(std::ftell(stream));

stream.seekg(0, std::ios::beg);
json.assign(std::istreambuf_iterator<char>(stream), {});
}
std::rewind(stream);
std::fread(json.data(), 1, json.size(), stream);
std::fclose(stream);

auto j = nlohmann::json::parse(json, nullptr, false);
if (j.is_discarded()) {
Expand Down

0 comments on commit 009fb0c

Please sign in to comment.