1

I have a shared library that contains global variable

    int ***carg;

This variable is initialized at function

    __attribute__((constructor)) void init(void) {
        carg = generator->get_carg();
    }

where

    int*** get_carg();

just returns preinitialized carg array.

If this library is loading there is segmentation fault

Program received signal SIGSEGV, Segmentation fault. 0x00007fffebe05fea in init () at /path/to/project/main.cpp:814

In this frame

    (gdb) print carg
    $1 = (int ***) 0x0
    (gdb) call generator->get_carg()
    $2 = (int ***) 0xf12410

Why this assignment (one pointer is assigned to other pointer) is the cause of segmentation fault? And how can I initialize this variable?

UPD: I still don't know answer, but when carg variable was renamed, there is no errors. I thought that there is one more variable with this name, but that's not so.

1 Answer 1

1

Probably the generator variable is not initialized yet and doesn't point to a valid object.

Calling get_cargs() then results in a segmentation fault.

Sign up to request clarification or add additional context in comments.

1 Comment

No, get_cargs() it's ok, because in this frame (gdb) print generator->get_carg()[0][0][0] is working. It's surprisingly for me that I can (gdb) call generator->get_cargs() (gdb) $5 (gdb) set carg = $ and there is no errors

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.