Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Successfully built it but can't run it (core dumped) #16

Open
ProgrammingLife opened this issue Jan 5, 2024 · 1 comment
Open

Successfully built it but can't run it (core dumped) #16

ProgrammingLife opened this issue Jan 5, 2024 · 1 comment

Comments

@ProgrammingLife
Copy link

$ ./easy-gestured 

[1]    81560 segmentation fault (core dumped)  ./easy-gestured

What can I check?

OS: Arch Linux

@tanshoku
Copy link

Same problem here. Running a trace with gdb reveals the problem:

#0  __strlen_avx2 () at ../sysdeps/x86_64/multiarch/strlen-avx2.S:76
#1  0x00005555555e4ae3 in std::char_traits<char>::length (__s=0x0) at /usr/include/c++/14/bits/char_traits.h:391
#2  0x0000555555619886 in std::operator==<char, std::char_traits<char>, std::allocator<char> > (__lhs=all, __rhs=0x0) at /usr/include/c++/14/bits/basic_string.h:3775
#3  0x0000555555619817 in __static_initialization_and_destruction_0 () at /mnt/_______/_______/easy-gesture/service/log.cpp:6
#4  0x0000555555619858 in _GLOBAL__sub_I__ZN9log_utils9isEnabledE14GLogLevelFlags () at /mnt/_______/_______/easy-gesture/service/log.cpp:11
#5  0x00007ffff643eee6 in call_init (env=<optimized out>, argv=0x7fffffffc048, argc=1) at ../csu/libc-start.c:145
        j = 0
        jm = <optimized out>
        addrs = <optimized out>
        l = <optimized out>
        init_array = <optimized out>
#6  __libc_start_main_impl (main=0x555555619b42 <main(int, char**)>, argc=1, argv=0x7fffffffc048, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7fffffffc038)
    at ../csu/libc-start.c:347
#7  0x00005555555e3d81 in _start ()

this reveals the problem to be on line 6 of log.cpp:

static bool allEnabled = std::string("all") == std::getenv("G_MESSAGES_DEBUG");

it tries to read the environment variable G_MESSAGES_DEBUG, but since that variable doesn't exist, it's referencing a null pointer, which leads to a segmentation fault. Setting that environment variable, such as G_MESSAGES_DEBUG=1 ./easy-gestured makes it work again. Changing the log_utils function in log.cpp to check for a null pointer before assigning the value to a variable makes the program compile and run flawlessly:

namespace log_utils {
    static char *g_messages_debug_env = std::getenv("G_MESSAGES_DEBUG");
    static bool allEnabled = 0;

    bool isEnabled(GLogLevelFlags level) {
        if (g_messages_debug_env != nullptr ) {
            allEnabled = std::string("all") == g_messages_debug_env;
        }
        return allEnabled;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants