Skip to content

Segmentation fault toml::json_formatter for empty document. #96

@proydakov

Description

@proydakov

Hi, Mark Gillard.

Many thx for hight quality C++ TOML parser library. It looks I found a corner case. See description below.

Environment

master

Compiler:
AppleClang12 BigSur 11.3

C++ standard mode (e.g. 17, 20, 'latest'):
20

Target arch (e.g. x64):
x64

Library configuration overrides:
Default.

Relevant compilation flags:
-fno-exceptions

Describe the bug

Process 18945 stopped

  • thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x41)
    frame #0: 0x0000000100035bbf toml_demo`toml::v2::json_formatter::print(this=0x00007ffeefbff530) at toml_json_formatter.h:91:47
    88
    89 void print()
    90 {
    -> 91 switch (auto source_type = base::source().type())
    92 {
    93 case node_type::table:
    94 print(reinterpret_cast<const table>(&base::source()));
    Target 0: (toml_demo) stopped.

Steps to reproduce (or a small repro code sample)

Compile code:

auto config = toml::parse_file( FNAME ); <-- no real TOML file here.
std::cout << toml::json_formatter{ config } << "\n";

Additional information

I think it is better to print empty json in this case: {}
What do you think about it?

Best regards, Proydakov Evgeny.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions