confuse-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Confuse-devel] CFG_SIMPLE_INT and x86_64 archs


From: Martin Hedenfalk
Subject: [Confuse-devel] CFG_SIMPLE_INT and x86_64 archs
Date: Wed, 10 Oct 2007 17:43:30 +0200

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





reply via email to

[Prev in Thread] Current Thread [Next in Thread]