Hi list,

If you use CFG_SIMPLE_INT and point the option to an int variable, you will get undefined behaviour on x86_64 / amd64 architectures (and probably on other 64 bit systems too).

This has been reported to the list by at least Priyank in Nov 2006, and more recently by Konstantin Sobolev in Aug 2007.

The issue is that libconfuse uses long ints internally to represent integers. So if you use CFG_SIMPLE_INT, be sure to point it to a long, not an int, or you will get undefined behaviour.

This is wrong:

    int a;
    cfg_opt_t opts[] = {
        CFG_SIMPLE_INT("a", &a),
        CFG_END()
    };

This is correct:

    long a;
    cfg_opt_t opts[] = {
        CFG_SIMPLE_INT("a", &a),
        CFG_END()
    };


If you use the regular options, ie CFG_INT, this is not an issue as the return value from cfg_getint will be implicitly cast.

However, if you use cfg_getint in a variadic function you should explicitly cast the return value, or va_args will not be able to tell the size of your variable.

Mvh
Martin Hedenfalk
bzero Consulting
Tel.070-622 35 05



_______________________________________________
Confuse-devel mailing list
Confuse-devel@nongnu.org
http://lists.nongnu.org/mailman/listinfo/confuse-devel

Reply via email to