Skip to content

Commit

Permalink
🐛 hopefully fixing the crashes on Linux (#365)
Browse files Browse the repository at this point in the history
  • Loading branch information
nlohmann committed Nov 22, 2016
1 parent f620d74 commit 6cc2d58
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 22 deletions.
17 changes: 6 additions & 11 deletions src/json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8733,10 +8733,7 @@ class basic_json
if (m_start != reinterpret_cast<const lexer_char_t*>(m_line_buffer.data()))
{
// copy unprocessed characters to line buffer
m_line_buffer.clear();
m_line_buffer.append(
reinterpret_cast<const typename string_t::value_type*>(m_start),
static_cast<size_t>(m_limit - m_start));
m_line_buffer.assign(m_start, m_limit);
m_cursor = m_limit;
}

Expand Down Expand Up @@ -8842,18 +8839,16 @@ class basic_json
// iterate the result between the quotes
for (const lexer_char_t* i = m_start + 1; i < m_cursor - 1; ++i)
{
// number of non-escaped characters
const size_t n = static_cast<size_t>(std::find(i, m_cursor - 1, '\\') - i);

if (n != 0)
// find next escape character
auto e = std::find(i, m_cursor - 1, '\\');
if (e != i)
{
result.append(reinterpret_cast<const typename string_t::value_type*>(i), n);
i += n - 1; // -1 because will ++i
result.append(i, e);
i = e - 1; // -1 because of ++i
}
else
{
// processing escaped character

// read next character
++i;

Expand Down
17 changes: 6 additions & 11 deletions src/json.hpp.re2c
Original file line number Diff line number Diff line change
Expand Up @@ -7882,10 +7882,7 @@ class basic_json
if (m_start != reinterpret_cast<const lexer_char_t*>(m_line_buffer.data()))
{
// copy unprocessed characters to line buffer
m_line_buffer.clear();
m_line_buffer.append(
reinterpret_cast<const typename string_t::value_type*>(m_start),
static_cast<size_t>(m_limit - m_start));
m_line_buffer.assign(m_start, m_limit);
m_cursor = m_limit;
}

Expand Down Expand Up @@ -7991,18 +7988,16 @@ class basic_json
// iterate the result between the quotes
for (const lexer_char_t* i = m_start + 1; i < m_cursor - 1; ++i)
{
// number of non-escaped characters
const size_t n = static_cast<size_t>(std::find(i, m_cursor - 1, '\\') - i);

if (n != 0)
// find next escape character
auto e = std::find(i, m_cursor - 1, '\\');
if (e != i)
{
result.append(reinterpret_cast<const typename string_t::value_type*>(i), n);
i += n - 1; // -1 because will ++i
result.append(i, e);
i = e - 1; // -1 because of ++i
}
else
{
// processing escaped character

// read next character
++i;

Expand Down

0 comments on commit 6cc2d58

Please sign in to comment.