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

Coverity issue (FORWARD_NULL) in lexer(std::istream& s) #368

Closed
darklukee opened this issue Nov 24, 2016 · 5 comments
Closed

Coverity issue (FORWARD_NULL) in lexer(std::istream& s) #368

darklukee opened this issue Nov 24, 2016 · 5 comments
Assignees
Labels
confirmed solution: invalid the issue is not related to the library

Comments

@darklukee
Copy link

Coverity found an issue in lexer(std::istream& s):

  1. assign_zero: Assigning: this->m_start = NULL.
7618        explicit lexer(std::istream& s)
7619            : m_stream(&s), m_line_buffer()
7620        {
7621            // fill buffer

CID 1077412 (#1 of 3): Explicit null dereferenced (FORWARD_NULL)
2. var_deref_model: fill_line_buffer dereferences null this->m_start.

7622 fill_line_buffer();

@nlohmann
Copy link
Owner

I'll have a look at this. By the way, how did you get Coverity to run? I currently have a problem with this, see #299.

@darklukee
Copy link
Author

It was run locally on build server. I didn't set it up and I don't have access to configuration so I can't help you here. Coverity version used: 8.0.0.

But you are doing some weird steps in COVERITY_SCAN_BUILD_COMMAND_PREPEND. I would look into it.

@nlohmann
Copy link
Owner

Issue #299 seems to be fixed. I could run a Coverity analysis and I found the same error:

** CID 154530:  Null pointer dereferences  (FORWARD_NULL)
/src/json.hpp: 9124 in nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long, unsigned long, double, std::__1::allocator>::lexer::lexer(std::__1::basic_istream<char, std::__1::char_traits<char>> &)()

________________________________________________________________________________________________________
*** CID 154530:  Null pointer dereferences  (FORWARD_NULL)
/src/json.hpp: 9124 in nlohmann::basic_json<std::__1::map, std::__1::vector, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, bool, long, unsigned long, double, std::__1::allocator>::lexer::lexer(std::__1::basic_istream<char, std::__1::char_traits<char>> &)()
9118             std::istream* m_stream = nullptr;
9119             /// line buffer buffer for m_stream
9120             string_t m_line_buffer {};
9121             /// the buffer pointer
9122             const lexer_char_t* m_content = nullptr;
9123             /// pointer to the beginning of the current symbol
   CID 154530:  Null pointer dereferences  (FORWARD_NULL)
   Assigning: "this->m_start" = "NULL".
9124             const lexer_char_t* m_start = nullptr;
9125             /// pointer for backtracking information
9126             const lexer_char_t* m_marker = nullptr;
9127             /// pointer to the current symbol
9128             const lexer_char_t* m_cursor = nullptr;
9129             /// pointer to the end of the buffer

However, I have yet to understand the error.

@nlohmann
Copy link
Owner

More details:

error

@nlohmann
Copy link
Owner

This is a false positive:

  • When lexer(std::istream& s) is called, a pointer to s is stored in m_stream. m_stream cannot be nullptr when fill_line_buffer is called from lexer(std::istream& s).
  • m_stream == NULL is the precondition (1.) of Coverity.

Nevertheless, I shall add an assertion before the append call.

@nlohmann nlohmann added the solution: invalid the issue is not related to the library label Nov 24, 2016
@nlohmann nlohmann self-assigned this Nov 24, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed solution: invalid the issue is not related to the library
Projects
None yet
Development

No branches or pull requests

2 participants