c-ridgway / cpp-feather-ini-parser

Header only, simple, fast, templated - portable INI parser for ANSI C++.
MIT License
47 stars 14 forks source link

wrong results / crashes without sections #6

Closed tstenner closed 5 years ago

tstenner commented 6 years ago

I found three bugs, two related to sections:

#include "INI.h"
#include <iostream>

void test(std::string str) {
    INI<> ini((void*) str.c_str(), str.length(), true);
    std::cout << ini.get("exists", "foo", 0) << std::endl;
    std::cout << ini.get("doesntexist", "foo", 0) << std::endl;
    ini.select("exists");
    std::cout << ini.get("foo", 0) << std::endl;
    ini.select("doesntexist");
    std::cout << ini.get("foo", 0) << std::endl;
}

int main(int argc, char** argv) {
    // Prints "1 0 1 1", should be "1 0 1 0"
    test("[exists]\nfoo=1");
    // Prints "0 0 Segmentation fault"
    test("");
    // segfaults immediately in the constructor
    test("foo=1");
    return 0;
}
Turbine1991 commented 5 years ago

I've finally re-written this parser. Everything has been addressed.

There are no line length limits.

The following is now parsed without errors: -Comments (// and #) -Semi-colons at the end of a key value pair -Indentation

The following may be applied when saving: -Pruning empty sections/keys value pairs -Padding between section blocks -Spaces around section value -Spaces inside key value pairs -Indented key value pairs -Semicolons appended to key value pairs