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

Serializing pointer segfaults #1355

Closed
SimonEbner opened this issue Nov 14, 2018 · 4 comments
Closed

Serializing pointer segfaults #1355

SimonEbner opened this issue Nov 14, 2018 · 4 comments

Comments

@SimonEbner
Copy link

  • What is the issue you have?
    Serializing a vector/map/.. of pointers segfaults

  • Please describe the steps to reproduce the issue. Can you provide a small but working code example?

int main() {
    int i = 1;
    std::vector<int*> values{&i};
    nlohmann::json data = values;
}
  • What is the expected behavior?
    Not sure - I guess compiler error ?

  • And what is the actual behavior instead?
    Segfault - Stack overflow from recursive call to

nlohmann::detail::json_ref<nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer> >::json_ref<int* const&>
  • Which compiler and operating system are you using? Is it a supported compiler?
    g++ (Ubuntu 8.1.0-5ubuntu1~16.04) 8.1.0

  • Did you use a released version of the library or the version from the develop branch?
    3.3.0

  • If you experience a compilation error: can you compile and run the unit tests?

Not sure what should be the expected behaviour. But I guess segfault is not the desired behaviour.

@pratikpc
Copy link
Contributor

pratikpc commented Dec 13, 2018

@SimonEbner could you please test against the develop branch or update to Version 3.4.0?
I get a compile time error in GCC and MSVC with Develop as well as 3.4.0

GCC says

 error: conversion from 'std::vector<int*>' to non-scalar type 'nlohmann::json' {aka 'nlohmann::basic_json<>'} requested
    nlohmann::json data = values;

While MSVC says

error C2440: 'initializing': cannot convert from 'std::vector<int *,std::allocator<_Ty>>' to 'nlohmann::basic_json<std::map,std::vector,std::string,bool,int64_t,uint64_t,double,std::allocator,nlohmann::adl_serializer>'
          with
          [
              _Ty=int *
          ]
 : note: No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

@theodelrieu
Copy link
Contributor

Version 3.4.0 fixed a lot of SFINAE-related issues, I strongly recommend upgrading.

@nlohmann
Copy link
Owner

I cannot reproduce the issue with the latest develop version. @SimonEbner could you please try the latest version?

@SimonEbner
Copy link
Author

Perfect, doesn't compile for me anymore either. Keep up the great work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants