[Info-vax] Whither VMS?

glen herrmannsfeldt gah at ugcs.caltech.edu
Sun Oct 4 23:36:45 EDT 2009


Michael Kraemer <M.Kraemer at gsi.de> wrote:
< Bob Koehler schrieb:
 
<>    This is a common problem with C library routines such as strcat.
 
< No, it's a common problem of programming which predates C:
< if you write to a buffer, make sure that:
< a) you own it,
< b) it's always large enough.
 
< strcat() simply assumes that you have calloc'ed the target
< buffer large enough before you use it.

< Which is easy because one can query the string lengths before.

Much easier (and faster) to keep track of the string lengths
while they are being created.

< It's not so easy with fgets() because one can't guess
< what's coming down the line.

fgets() is the one with a length argument, its gets() that
doesn't have one.

< Likewise with sprintf(), one doesn't know how much space
< the formatted stuff would need.

I have wondered about using %f on machines with large exponents
like some Cray machines.  %f expands the field to the number of 
digits needed, which could be thousands on some machines.

< snprintf() is sort of a security patch for that problem,
< but not a real solution.
< So these two functions are about the only "dangereous" ones
< I can remember because you can't really use them safely in their
< usual context.

-- glen 



More information about the Info-vax mailing list