hyperrealm / libconfig

C/C++ library for processing configuration files
https://hyperrealm.github.io/libconfig/
GNU Lesser General Public License v2.1
1.1k stars 359 forks source link

Regression on config_lookup() in 1.7.3 #196

Closed yrutschle closed 3 years ago

yrutschle commented 3 years ago

Hi, I used to be able to call config_lookup on the root of a configuration (config_lookup(c,"/");). This works in 1.7.2, and older versions, but returns NULL on 1.7.3.

Here's a minimal test case:

#include <libconfig.h>

const char* filename = "test.cfg";

int main(void)
{
    config_t c;
    config_setting_t* s;

    config_init(&c);
    if (config_read_file(&c, filename) == CONFIG_FALSE) {
        if (config_error_line(&c) != 0) {
           printf( "%s:%d:%s", 
                    filename,
                    config_error_line(&c),
                    config_error_text(&c));
           return 0;
        }
        printf( "%s:%s", filename, config_error_text(&c));
        return 0;
    }

    s = config_lookup(&c, "/");
    printf("%p\n", s);
    return 0;
}

I can't see a change in the documentation: do we need to adapt the call?

hyperrealm commented 3 years ago

I think you were relying on a bug which was fixed in 1.7.3. "/" isn't really a valid path, and there is a dedicated method to get the root setting so this kind of usage shouldn't be necessary.

yrutschle commented 3 years ago

a bug that's been around for a decade and is relied upon by projects is a feature :-)

Fair enough. For others who would get the same issue, the correct API is:

    s = config_root_setting(&c);