Problems that are in some ways endemic to C programs:
char *buf = NULL; size_t len = 0; int c; while( (c = getchar()) != EOF ) { buf = realloc( buf, ++len ); buf[len-1] = c; } buf = realloc( buf, len+1 ); buf[len] = 0;
Speaking of realloc, one that's tricky is stale pointers with that. You realloc something, you have to re-assign each pointer to it; this can be difficult in a threaded program.
NULL pointer stuff is pretty obvious, so I won't go into that. There's also the problem of never assigning a value to a pointer, then trying to dereference it. That's pretty easy to track and fix once you find it though. There's also accidentally casting an int or some such into a pointer (ouch!), but again, that's pretty easy to track. I'd say it's definitely forgetting to free(). The rest can be fixed with a good debugger.
This sort of shite is one of the reasons I use C++. It isn't perfect, and you still use pointers enough to get into trouble, but it reduces their use to the point where you spend a lot less time groveling around for that leaking memory. Got bless destructors!
if(0 == myVar)
if( a = 5 ) { do_stuff(); }
if( (a = 5) ) { do_stuff(); }
a == 5;
if
printable version chaos
Everything2 Help