need C help, passing char buffer[] by-value....

Gary Kline kline at thought.org
Mon Oct 19 05:16:07 UTC 2009


On Mon, Oct 19, 2009 at 05:43:44AM +0200, Polytropon wrote:
> On Sun, 18 Oct 2009 22:23:43 -0500, David Kelly <dkelly at hiwaay.net> wrote:
> > When not using a count to indicate how much data is in a char* you  
> > should always test for null. Testing for null is not a sure fire way  
> > to prevent buffer over runs but its better than nothing.
> 
> There are means like
> 
> 	#include <assert.h>
> 	...
> 	assert(s);
> 
> to make sure s is not NULL, or testing for it explicitely like
> 
> 	if(!s)
> 		... error handling here ...
> 
> is possible. Furthermore, it is a proven way to give a length
> argument along with the (char *) argument, such as the "new"
> l-functions for strings, e. g. strlcat() and strlcpy(), do.
> 
> 	char *skiptags(char *s, int l);
> 
> You can even double-check for l begin != 0. Or you employ a
> test with strlen() function-internally.
> 
> 

	right; i will add error checking once i've got things working.
	but i think i meant to say that i was calling by-reference, sing 
	fgets was reading the file from a 

	char buffer[256];

	or whatever.  so, given this, shouldn't i need to step past some N bytes of 
	"buffer[]?

	i'll experiement and see, again, but in my one compile that worked, by-value,
	left in the <TAGS> </TAGS>

	gary


> 
> -- 
> Polytropon
> Magdeburg, Germany
> Happy FreeBSD user since 4.0
> Andra moi ennepe, Mousa, ...
> _______________________________________________
> freebsd-questions at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-questions
> To unsubscribe, send any mail to "freebsd-questions-unsubscribe at freebsd.org"

-- 
 Gary Kline  kline at thought.org  http://www.thought.org  Public Service Unix
        http://jottings.thought.org   http://transfinite.thought.org
    The 7.31a release of Jottings: http://jottings.thought.org/index.php



More information about the freebsd-questions mailing list