home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!olivea!mintaka.lcs.mit.edu!bloom-picayune.mit.edu!news
- From: scs@adam.mit.edu (Steve Summit)
- Newsgroups: comp.lang.c
- Subject: Re: Allocate memory to typed in string, How?
- Message-ID: <1992Aug15.201359.3601@athena.mit.edu>
- Date: 15 Aug 92 20:13:59 GMT
- References: <MJN.92Aug9012538@pseudo.uucp> <1992Aug13.184911.376@wyvern.twuug.com>
- Sender: news@athena.mit.edu (News system)
- Organization: none, at the moment
- Lines: 55
- Nntp-Posting-Host: adam.mit.edu
-
- In article <1992Aug13.184911.376@wyvern.twuug.com>, alpha@wyvern.twuug.com (Joe Wright) writes:
- > Attempts to allocate memory, char at a time, to an arbitrary 'string'
- > is silly even if it is possible. If a string is assumed to be a line
- > of a text file or arbitrary keyboard input, we can easily declare that
- > it must not be longer than (let's say) 256 bytes.
-
- I agree that it's easy to "declare that it must not be longer,"
- but the ease of stating something is not necessarily correlated
- with its wisdom.
-
- Attempting to deal with arbitrarily-long input lines, using
- dynamic memory allocation or other techniques, is most certainly
- not silly. If you must write a routine which imposes a fixed
- limit on input line length, let it be for one of these two
- reasons:
-
- 1. "I am too lazy and/or stupid to do any better."
-
- 2. "I have complete control over the input."
-
- Operating-system-imposed limits on interactive input line length
- are red herrings, for several reasons: they generally do *not*
- apply to disk files; they are not the same from system to system,
- and they may change between releases of the same system. (If the
- next release of the operating system advertised new, longer
- keyboard input buffers, I'd hate to have to tell my customers
- that my application couldn't make use of them, because I had
- wired in an assumption that the previous, smaller limit held.)
-
- Arbitrary, fixed, (small) limits on input line length ought to be
- a thing of the past. It's not all that difficult to write an
- input routine which accepts arbitrarily-long lines; indeed, we've
- seen several posted recently in the context of this and other
- related threads. The fact that old Unix utilities tended to
- (silently, and more-or-usually-less gracefully) impose
- 512-character limits should *not* be used as justification to
- continue the practice; those limits are one of the more glaring
- blights on the ubiquitous "Unix philosophy."
-
- Steve Summit
- scs@adam.mit.edu
-
- P.S. Please, don't anyone get too steamed if it seems like I'm
- branding you as "too lazy and/or stupid to do any better."
- I frequently write little throwaway utilities with
- arbitrary limits, because I'm lazy, too. You can perform a
- cost/benefit analysis which may show that it's not
- worthwhile to accept arbitrarily-large inputs: in a way,
- that's just institutionalized laziness, but if the analysis
- is accurate and well-founded it may well be perfectly
- reasonable and nothing to be ashamed of. But make very
- very sure that you document the limit(s) well, and deal
- with overflows gracefully (and that you include the costs
- of dealing gracefully, and of putting up with the limits,
- in your analysis).
-