Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using uninitialized memory 'buf' in line 11173 v2.1.1? #613

Closed
mireiner opened this issue Jun 10, 2017 · 5 comments
Closed

Using uninitialized memory 'buf' in line 11173 v2.1.1? #613

mireiner opened this issue Jun 10, 2017 · 5 comments
Labels
solution: invalid the issue is not related to the library

Comments

@mireiner
Copy link

json.hpp v2.1.1

Using uninitialized memory 'buf'?

Lines

11149 std::array<char, 64> buf;


11173 if ((len + 1) < buf.size())
11174 {
11175 std::copy(m_start, m_end, buf.begin());
11176 buf[len] = 0;
11177 buf[ds_pos] = decimal_point_char;
11178 data = buf.data();
11179 }

@nlohmann
Copy link
Owner

No, this is fine. We checked the code with Valgrind and clang's sanitizers.

Wenn you look at https://github.com/nlohmann/json/blob/v2.1.1/src/json.hpp#L11153 you see that

  • len = m_end - m_start
  • len > 0
  • (len + 1) < buf.size()
  • std::copy(m_start, m_end, buf.begin()) copies len bytes to buf
  • buf[len] = 0 terminates buf
  • buf[ds_pos] = decimal_point_char replaces the decimal point
  • data = buf.data() reads buf
  • buf is not read at any other location

@mireiner
Copy link
Author

mireiner commented Jun 10, 2017

Visual Studio 2017 Code Analyser shows C6001 warning message at line 11173:
"json.hpp(11173): warning C6001: Using uninitialized memory 'buf'."

Warning C6001 means:
https://msdn.microsoft.com/en-us/library/3fb5eatz.aspx

'buf' isn't initialized at line 11173. So I wondered what the if statement will check in line 11173, because 'buf.size()' will most likely be always 0 at that point. Isn't it?

@nlohmann
Copy link
Owner

std::array::size() returns the size of the array (i.e., the template parameter) which is 64 in this case. It seems as if the warning is a false positive.

@mireiner
Copy link
Author

Sorry for the false report. Feel free to delete this entry.

@nlohmann nlohmann added the solution: invalid the issue is not related to the library label Jun 10, 2017
@nlohmann
Copy link
Owner

No problem! Thanks for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
solution: invalid the issue is not related to the library
Projects
None yet
Development

No branches or pull requests

2 participants