Question Details

No question body available.

Tags

c pointers gcc overflow valgrind

Answers (2)

February 7, 2026 Score: 5 Rep: 7,365 Quality: Low Completeness: 70%

When you run your test executable under Valgrind memcheck it does not use your C or C++ standard library allocation functions. Instead it replaces them with its own allocation functions and memory manager. Valgrind's memory manager only uses mmap. As you are using Linux on amd64 with GNU libc then it is likely that it is using both brk and mmap (see In malloc, why use brk at all? Why not just use mmap? for details).

You can use Valgrind and gdb together. Use valgrind --vgdb-error=0 and then follow the instructions that it prints out.

February 8, 2026 Score: 0 Rep: 122,535 Quality: Low Completeness: 20%

use the valgrind errors to track down misbehaving pointers

Whether you use valgrind or not, there is no guarantee whatsoever that two consecutive runs of the same program will produce the same pointer values. In my practice the values are not the same even for simplest programs, so comparing pointer values from different runs is meaningless.

If you for some reason need to relate pointers from different runs, you need to instrument your code yourself. One way to do so is to wrap your allocation functions, add a global call counter to them, and log pairs (call-counter, returned-pointer-address) to a file. Pointers with the same call-counter are the "same" pointer, provided that the program behaves deterministically and reads the same exact input.