Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
c/c++ buffer overrun detection tool?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
gnychis
Veteran
Veteran


Joined: 23 Mar 2005
Posts: 1004
Location: Pittsburgh, PA

PostPosted: Fri Aug 25, 2006 7:56 pm    Post subject: c/c++ buffer overrun detection tool? Reply with quote

Hey guys,

I am having problems with a program I have written, where its seg faulting in random places like malloc's or fprintf's. This to me is a signal that I have overrun somewhere earlier in the execution and overwritten a valid pointer or space somewhere else in memory. However, I've spent many hours debugging and trying to find it but I can't.

I was wondering if anyone knows any tools that will monitor the stack and detect when you try to access memory out of bounds? I have used ElectricFence in the past, linking my programs with -lefence, but I keep getting an electric fence error trying to do so with this program:
Code:

lanthanum-ini blinc_code # ./blinc 0 300

ElectricFence: Registering with atexit().
ElectricFence: If this hangs, change the library load order with LD_PRELOAD.
ElectricFence: Registration was successful.
ElectricFence Exiting:
Electric Fence: mprotect() failed: Cannot allocate memory


It's not an immediate exit, after about 1 minute it exits. Maybe this is a sign of something though?

I'd greatly appreciate any help and tool suggestions.

Thanks!
George
_________________
<---- me and Richard Stallman :)
Back to top
View user's profile Send private message
didl
Retired Dev
Retired Dev


Joined: 09 Sep 2003
Posts: 1106
Location: Pittsburgh, PA

PostPosted: Fri Aug 25, 2006 8:47 pm    Post subject: Reply with quote

You could step through your code using gdb and examine your
local variables, .. etc. at the appropriate instances, i.e. when your
code segfaults. Also, have a look at valgrind.
Back to top
View user's profile Send private message
dmitchell
Veteran
Veteran


Joined: 17 May 2003
Posts: 1159
Location: Austin, Texas

PostPosted: Fri Aug 25, 2006 8:56 pm    Post subject: Reply with quote

Since someone has already suggest valgrind, I'll just say that you should try to use the C++ standard library whenever possible, especially the containers, string, and iostreams. Using the library will go a long way towards making your program safer and correct.
_________________
Your argument is invalid.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum