My C program ( written for knapsack) suffers from segmentation error. Using gdb,
(gdb) ptype $_siginfo
(gdb) ptype $_siginfo._sifields._sigfault
(gdb) p $_siginfo._sifields._sigfault.si_addr
I found out that , when the program tries to refer to 0x8. It shows segmentation error. In documentation of gdb, they say that Depending on target support, $_siginfo may also be writable.
any idea, how can we include above memory address? so that program will not show segmentation error.
Also this error is shown at one printf statement in program. can we use signal 0 to make sure that program will ignore SIGSEGV at that stage?
Any insight would be helpful
Valgrind : I tried to see the problem using valgrind: The output of valgrind is as below:
The number of objects is 1200, and the capacity is 38400000.
==2297== Invalid write of size 4
==2297== at 0x400A4E: main (knap1.c:73)
==2297== Address 0x8 is not stack'd, malloc'd or (recently) free'd
==2297==
==2297==
==2297== Process terminating with default action of signal 11 (SIGSEGV)
==2297== Access not within mapped region at address 0x8
==2297== at 0x400A4E: main (knap1.c:73)
==2297== If you believe this happened as a result of a stack
==2297== overflow in your program's main thread (unlikely but
==2297== possible), you can try to increase the size of the
==2297== main thread stack using the --main-stacksize= flag.
==2297== The main thread stack size used in this run was 8388608.
==2297==
==2297== HEAP SUMMARY:
==2297== in use at exit: 14,400 bytes in 3 blocks
==2297== total heap usage: 4 allocs, 1 frees, 14,968 bytes allocated
==2297==
==2297== LEAK SUMMARY:
==2297== definitely lost: 0 bytes in 0 blocks
==2297== indirectly lost: 0 bytes in 0 blocks
==2297== possibly lost: 0 bytes in 0 blocks
==2297== still reachable: 14,400 bytes in 3 blocks
==2297== suppressed: 0 bytes in 0 blocks
==2297== Rerun with --leak-check=full to see details of leaked memory
==2297==
==2297== For counts of detected and suppressed errors, rerun with: -v
==2297== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 2 from 2)
Segmentation fault
Increasing stack size didn't help much. Any idea how to solve this problem?