Boston Linux & Unix (BLU) Home | Calendar | Mail Lists | List Archives | Desktop SIG | Hardware Hacking SIG
Wiki | Flickr | PicasaWeb | Video | Maps & Directions | Installfests | Keysignings
Linux Cafe | Meeting Notes | Linux Links | Bling | About BLU

BLU Discuss list archive


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

using gdb



In the 20+ years I have been using C and C++, pointers have always been 
troublesome for many of my associates. I have been programming in assembler 
languages for 30+ years, and have a reasonably good understanding. 

But, some other problems can occur. Take this example:
char *getline()
{
	char line[SIZE];
	/* read a line into line using gets or fgets, etc */
	return line;
}

In this case, getline returns a pointer to line, which is an automatic 
variable. Any function that is subsequently called may corrupt the string 
contained the stack region pointed to be line. 

char *getline()
{
	static char line[SIZE];
	/* read a line into line using gets or fgets, etc */
	return line;
}
This version of getline is safer since line is on the initialized data 
section of the heap. But, this gets clobbered on the next call to 
getline(). However, there are several libc functions (such as ctime, 
localtime(), etc) which exhibit the same side effect. This type of function 
is also NOT threadsafe in that another thread can easily step on line. 

As I mentioned, you really need to set up watchpoints. 

 
On 15 Jul 2002 at 12:25, Brad Noyes wrote:

> Jerry,
> yes, i was refering to pointers. Some how a value is getting changed and i'm
> trying to track it down.
> 
> Thanks for the DDD tip, i completely forgot about that. I have used it in the
> past, and hopefully it will give the ability to examin the data better.
\
--
Jerry Feldman <gaf at blu.org>
Associate Director
Boston Linux and Unix user group
http://www.blu.org PGP key id:C5061EA9
PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9





BLU is a member of BostonUserGroups
BLU is a member of BostonUserGroups
We also thank MIT for the use of their facilities.

Valid HTML 4.01! Valid CSS!



Boston Linux & Unix / webmaster@blu.org