nixCraft Linux Forum

nixCraft

Linux / UNIX Tech Support Forum

what is dangling pointers under GCC?

This is a discussion on what is dangling pointers under GCC? within the Coding in General forums, part of the Development/Scripting category; Hi Anyone know what is dangling pointers? If possible give me some example… I’m using FreeBSD with GCC Thx...

Register free or login to your existing account and remove all advertisements.


Go Back   nixCraft Linux Forum > Development/Scripting > Coding in General

Linux answers from nixCraft.


Coding in General Discussion on PHP/Perl/Python/Ruby/GNU C or C++. MySQL, PgSQL and (X)HTML or any other programming languages you want.

Reply

 

LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-25-2005, 12:42 PM
Guest
 
Posts: n/a
Default what is dangling pointers under GCC?

Hi

Anyone know what is dangling pointers? If possible give me some example… I’m using FreeBSD with GCC

Thx
Reply With Quote
  #2 (permalink)  
Old 05-25-2005, 08:17 PM
rockdalinux's Avatar
Is that all you got?
User
 
Join Date: May 2005
Location: Planet Vegeta
OS: Redhat
Posts: 691
Thanks: 15
Thanked 17 Times in 16 Posts
Rep Power: 9
rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light rockdalinux is a glorious beacon of light
Default

Pointers that point to invalid addresses is called dangling pointers.

Some Examples that causes dangling pointers:
  • Casting arbitrary integers to pointers
    Adjusting pointers beyond the bounds of arrays
    Deallocating storage that one or more pointers still reference

C code/example of dangling pointers:
Code:
somefunc(){
x=(int *)malloc(sizeof(int));
...
free(x);
return (x); /* x is dangling pointer */
}
To avoid dangling pointers always assign NULL in C after freeing memory:
Code:
...
free(x);
x=NULL;
....
Reply With Quote
  #3 (permalink)  
Old 05-26-2005, 11:54 AM
Guest
 
Posts: n/a
Default

Thanks a lot

It is clear now...
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
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 On
Pingbacks are On
Refbacks are Off



All times are GMT +5.5. The time now is 10:46 AM.


Powered by vBulletin® Version 3.8.4 - Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2
©2005-2009 nixCraft. All rights reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38