CFanatic

Go Back   CFanatic > Programming > C++ Programming

Join CFanatic Forum Now

Bugs fixing-dangling pointer topic posted under C++ Programming which is a part of Programming category in CFanatic Forum
Reply
 
Thread Tools Display Modes
  #1  
Old 02-27-2008, 02:19 AM
Junior Member
 
Join Date: Feb 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
tommy_24 is on a distinguished road
| More
Bugs fixing-dangling pointer

Hi,
I find very difficult to fix the dangling pointer bug occurred in my new open source office application developed in C++ language. I need some information to resolve this bug?
Reply With Quote
  #2  
Old 02-27-2008, 02:20 AM
Junior Member
 
Join Date: Feb 2008
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
antony is on a distinguished road
| More
Coverity Prevent- static source code analysis tool

Hi,
Usually dangling pointers arises when an object is deleted or deallocated , without modifying the value of the pointer, so that the pointer still points to the memory location of the deallocated memory. As the system may reallocate the previously freed memory to another process, if the original program then dereferences the (now) dangling pointer, unpredictable behavior may result, as the memory may now contain completely different data. This is especially the case if the program writes data to memory pointed by a dangling pointer, as silent corruption of unrelated data may result, leading to subtle bugs that can be extremely difficult to find, or cause segmentation faults. You didn’t mention the code for resolving the bug. For resolving this bug easily you can use Coverity prevent, a Static analysis code inspection tool for resolving defects in C++,C or Java source code. Coverity has customers like Symbian, RIM (Blackberry), Juniper networks, Cisco, Texas instruments and is also used by the Department of Homeland security to scan lots of open source projects.

Last edited by shabbir; 02-28-2008 at 11:24 PM. Reason: Confine links to signatures
Reply With Quote
  #3  
Old 07-25-2008, 04:22 AM
Senior Member
 
Join Date: Jul 2008
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
xpi0t0s is on a distinguished road
| More
Re: Coverity Prevent- static source code analysis tool

One useful trick for handling dangling pointers is to initialise a pointer to NULL (before it is set to point to something), e.g. instead of int *x;, use int *x=NULL; Then when it's no longer pointing at something set it back to NULL, e.g. instead of just "free(x);", use "free(x); x=NULL;". That way all pointers will be NULL or valid, and any access to a NULL pointer will result in an immediate segfault rather than the software thinking it's pointing at something valid and continuing regardless.

Or you can use a smart pointer class, which handles all this for you.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Please, help me to find sites to fix some bugs on my PC. brierieTago Introduce yourself 2 01-25-2009 02:39 AM
How to pass a pointer through a named pipe Spogliani C++ Programming 1 09-01-2008 12:28 PM

 

Advertisement

CFanatic Search
Custom Search

Advertisement

All times are GMT -5. The time now is 03:24 PM.



Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO ©2010, Crawlability, Inc.
Cfanatic.com is a premier member of the IDG TechNetwork. For advertising opportunities contact here
Get Paid for Working on Projects Matching Your Expertise at Go4Expert's Jobs Board