Odd segfault

Marcel Keller mks.keller@gmail.com
Thu Oct 25 10:34:00 GMT 2018


Hi,

The attached code produces a segfault (on Ubuntu 18.04 with GCC 7.3) but 
not if I uncomment g() in main(). Any ideas why?

Best regards,
Marcel


$ g++ -g A.cpp ; valgrind ./a.out
==28698== Memcheck, a memory error detector
==28698== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==28698== Using Valgrind-3.13.0 and LibVEX; rerun with -h for copyright info
==28698== Command: ./a.out
==28698==
==28698== Invalid write of size 4
==28698==    at 0x10874B: B::f() (A.cpp:7)
==28698==    by 0x108788: void f<int>() (A.cpp:15)
==28698==    by 0x1086D6: main (A.cpp:26)
==28698==  Address 0x0 is not stack'd, malloc'd or (recently) free'd
==28698==
==28698==
==28698== Process terminating with default action of signal 11 (SIGSEGV)
==28698==  Access not within mapped region at address 0x0
==28698==    at 0x10874B: B::f() (A.cpp:7)
==28698==    by 0x108788: void f<int>() (A.cpp:15)
==28698==    by 0x1086D6: main (A.cpp:26)
==28698==  If you believe this happened as a result of a stack
==28698==  overflow in your program's main thread (unlikely but
==28698==  possible), you can try to increase the size of the
==28698==  main thread stack using the --main-stacksize= flag.
==28698==  The main thread stack size used in this run was 8388608.
==28698==
==28698== HEAP SUMMARY:
==28698==     in use at exit: 0 bytes in 0 blocks
==28698==   total heap usage: 1 allocs, 1 frees, 72,704 bytes allocated
==28698==
==28698== All heap blocks were freed -- no leaks are possible
==28698==
==28698== For counts of detected and suppressed errors, rerun with: -v
==28698== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
Segmentation fault (core dumped)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: A.cpp
Type: text/x-c++src
Size: 243 bytes
Desc: not available
URL: <https://gcc.gnu.org/pipermail/gcc-help/attachments/20181025/c14f8550/attachment.bin>


More information about the Gcc-help mailing list