Strange behaviour when using std::sort on std::vector<json> #3080
Labels
solution: invalid
the issue is not related to the library
solution: proposed fix
a fix for the issue has been proposed and waits for confirmation
Hi, I'm having a hard time finding the root cause of the behaviour specified below.
What is the issue you have?
When trying to sort
std::vector<nlohmann::json>
via custom comparator, parameters of the comparator are not elements of the saidstd::vector
. The values of thej1
andj2
from the comparatorshould be objects, but the exception thrown during the
std::sort
in the working example says something else:The strange thing is when I change the variable
jsons_count
to16
or variablevalue
toi
in the working example, the code runs successfully.I ran the code with valgrind and ended up with:
which looks like some of the comparator's parameters could have uninitialized
m_type
(https://github.com/nlohmann/json/blob/v3.9.1/include/nlohmann/json.hpp#L6924) and possibly might not be initialized at all.Could you please look into it? Thank you in advance.
Please describe the steps to reproduce the issue.
Compile and run the working code example below.
Can you provide a small but working code example?
What is the expected behavior?
The code should run successfully without any exception thrown.
And what is the actual behavior instead?
The code throws exception during
std::sort
.Which compiler and operating system are you using?
Which version of the library did you use?
develop
branchIf you experience a compilation error: can you compile and run the unit tests?
The text was updated successfully, but these errors were encountered: