Re: Ancient history
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


sci.crypt archive

Re: Ancient history

From: glen herrmannsfeldt <gah@ugcs.caltech.edu>
Date: Mon Jun 13 2005 - 08:19:49 CEST

Colonel Forbin wrote:

(snip)

> The main point is that if you are taking in something unknown
> from outside your reference frame, you measure it before you
> try to stuff the proverbial 50 pounds of shit into the 25 pound
> sack. Hopefully you also type and sanity check it to see that
> it really is shit before you flush the toilet.

> There is nothing in the C language to prevent doing this in
> most cases. The fact that it isn't routinely done indicates
> a problem with fundamental thinking and design which transcends
> any particular programming language.

Well, true, but the C library does tend to encourage that.

Consider strcat(). If you know the lengths of both strings then
you can verify the safety of strcat, but if you know the lengths
then strcat isn't the best function to use, anyway. strcpy()
with a pointer to the end of the first string is faster, and
if you know the length it is easy to point to the end.

So, why have strcat() at all?

(I once had to fix a program with running time quadratic in input
length. It used strcat() in a loop, which is necessarily
quadratic. The fix included keeping track of the end and using
strcpy() instead, after verifying that the result would fit.)

-- glen
Received on Thu Sep 29 21:43:26 2005