Returns true, returns false? magic

I have a problem in my C ++ program to extract audio from VoIP packets.

This works well on Linux and OpenBSD on amd64 and x86, but when I run the program on OpenBSD on ARM it really does magical things.

I call return true on LoadConfigFile and on ProcessConfiguration the result is false.

Can anyone help me? Maybe I'm just blind. I did a lot of test prints in the code.

This is the main function of the program that calls the ProcessConfiguration function.

int main ( int argc, char **argv ) {

    if ( ! config.ProcessConfiguration( argc, argv ) ) {
        std::cout << "process configuration failed" << std::endl;
        std::cout << "exiting whole program with EXIT_FAILURE" << std::endl;
        return EXIT_FAILURE;
    }

    std::cout << "process configuration is true" << std::endl;

    // User want to only print configuration
    if ( config.m_printconfig == true ) {
        config.PrintConfig();
        return EXIT_SUCCESS;
    }
    .
    . // Long uninteresting code
    .
    return EXIT_SUCCESS;
}

      

This is the ProcessConfoguration function that calls LoadConfigFile.

bool TConfig::ProcessConfiguration ( int & argc, char ** & argv ) {

    // Scan options from command line
    int c;
    while (( c = getopt ( argc, argv, "c:dhn" )) != EOF ) {
        switch (c) {
        case 'c':
            m_configfile = optarg;
            break;
        case 'd':
            m_daemon = false;
            break;
        case 'h':
            m_printusage = true;
            return true;
        case 'n':
            m_printconfig = true;
            break;
        default:
            return false;
        }
    }
    argc -= optind;
    argv += optind;

    if ( LoadConfigFile() == false ) {
        std::cout << "LoadConfigFile was false" << std::endl;
        return false;
    }
    std::cout << "LoadConfigFile was true" << std::endl;
    return true;
}

      

And this function loads the configuration file, parses all directives.

bool TConfig::LoadConfigFile ( void ) {

    std::string line;
    std::string directive;
    std::ifstream data;

    if ( m_configfile.empty() ) {
        m_configfile = DEFAULT_CONFIGFILE;
    }

    std::cout << "opening file " << m_configfile << std::endl;

    data.open( m_configfile.c_str() );

    if ( ! data.is_open() ) {
        std::cerr << "Couldn't open config " << m_configfile << std::endl;
        return false;
    }
    std::cout << "configfile is open" << std::endl;
    std::cout << "before getline" << std::endl;
    while ( getline( data, line ) ) {
        std::cout << "after getline" << std::endl;
        trim_whitespaces( line );
        .
        . // Long uninteresting code
        .
    }
    std::cout << "before data.close" << std::endl;
    data.close();
    std::cout << "before return true in LoadConfigFile" << std::endl;
    return true;
}

      

And this is outputted to the terminal.

$ ./call-extract -c call-extract.conf -d -n 
opening file call-extract.conf
configfile is open
before getline
before data.close
before return true in LoadConfigFile
LoadConfigFile was false
process configuration failed
exiting whole program with EXIT_FAILURE
$ echo $?
1
$ 

      

I call return true on LoadConfigFile and on ProcessConfiguration the result is false.

+3


source to share


1 answer


The return value is true.

Output for me:

before return true in LoadConfigFile
LoadConfigFile was true

      



Code without uninteresting parts:

struct TConfig
{
    bool ProcessConfiguration()
    {
        bool rv = true;
        if( !LoadConfigFile() ) { rv = false; }
        printf("LoadConfigFile was %s\n", rv?"true":"false" );
        return rv;
    }

    bool LoadConfigFile ( void )
    {
        printf("before return true in LoadConfigFile\n");
        return true;
    }
};
void fv()
{
    TConfig config; config.ProcessConfiguration();
}

      

0


source







All Articles