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

How do you deal with json* ? #1829

Closed
michael-a-green opened this issue Nov 6, 2019 · 3 comments
Closed

How do you deal with json* ? #1829

michael-a-green opened this issue Nov 6, 2019 · 3 comments

Comments

@michael-a-green
Copy link

michael-a-green commented Nov 6, 2019

  • Describe what you want to achieve.

I want to do the following:

json* my_jptr;

(*my_jptr) = json({});

But when I attempt this I get this error:

Program received signal SIGSEGV, Segmentation fault.
0x0000000000408eb9 in std::enable_if<std::__and_<std::__not_<std::__is_tuple_like<nlohmann::detail::value_t> >, std::is_move_constructible<nlohmann::detail::value_t>, std::is_move_assignable<nlohmann::detail::value_t> >::value, void>::type std::swap<nlohmann::detail::value_t>(nlohmann::detail::value_t&, nlohmann::detail::value_t&) ()
  • Describe what you tried.

I tried this:

json* my_jptr;

(*my_jptr) = json({});

  • Describe which system (OS, compiler) you are using.

Version of g++

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib64/gcc/x86_64-suse-linux/9/lto-wrapper
OFFLOAD_TARGET_NAMES=hsa:nvptx-none
Target: x86_64-suse-linux
Configured with: ../configure --prefix=/usr --infodir=/usr/share/info --mandir=/usr/share/man --libdir=/usr/lib64 --libexecdir=/usr/lib64 --enable-languages=c,c++,objc,fortran,obj-c++,ada,go,d --enable-offload-targets=hsa,nvptx-none=/usr/nvptx-none, --without-cuda-driver --disable-werror --with-gxx-include-dir=/usr/include/c++/9 --enable-ssp --disable-libssp --disable-libvtv --disable-cet --disable-libcc1 --enable-plugin --with-bugurl=https://bugs.opensuse.org/ --with-pkgversion='SUSE Linux' --with-slibdir=/lib64 --with-system-zlib --enable-libstdcxx-allocator=new --disable-libstdcxx-pch --enable-libphobos --enable-version-specific-runtime-libs --with-gcc-major-version-only --enable-linker-build-id --enable-linux-futex --enable-gnu-indirect-function --program-suffix=-9 --without-system-libunwind --enable-multilib --with-arch-32=x86-64 --with-tune=generic --with-build-config=bootstrap-lto-lean --enable-link-mutex --build=x86_64-suse-linux --host=x86_64-suse-linux
Thread model: posix
gcc version 9.2.1 20190820 [gcc-9-branch revision 274748] (SUSE Linux) 

openSUSE Tumbleweed.

  • Describe which version of the library you are using (release version, develop branch).

I am using 3.7.0 of this library.

@gregmarr
Copy link
Contributor

gregmarr commented Nov 7, 2019

This problem really has nothing to do with this library. You'd get similar results with this code:

int *my_iptr;
(*my_iptr) = 0;

In short, you're dereferencing an uninitialized pointer, which is a coding error.

@michael-a-green
Copy link
Author

Thanks. I found a way around it:

json coverage_data_j;
json* coverage_data_jptr;
coverage_data_j["ip"]="simple_alu";
coverage_data_jptr = &(coverage_data_j);

@nlohmann
Copy link
Owner

nlohmann commented Nov 8, 2019

Please be aware the pointer will become invalid once the JSON object is changed.

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

No branches or pull requests

3 participants