Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 19 Oct 2009 05:43:44 +0200
From:      Polytropon <freebsd@edvax.de>
To:        freebsd-questions@freebsd.org
Subject:   Re: need C help, passing char buffer[] by-value....
Message-ID:  <20091019054344.bb4822ca.freebsd@edvax.de>
In-Reply-To: <72213BBF-5E05-430D-BF9A-FCD2666951C6@hiwaay.net>
References:  <20091019013337.GA9522@thought.org> <72213BBF-5E05-430D-BF9A-FCD2666951C6@hiwaay.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Sun, 18 Oct 2009 22:23:43 -0500, David Kelly <dkelly@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.



-- 
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20091019054344.bb4822ca.freebsd>