(Edward A. Falk) writes:
>> Can I assume that if fgets reads that line, then it won't modify any
>> characters in the buffer whose offset is greater than 8 ?
>
> Any time you're working with computers, and the word 'assume' comes up,
> I hope all the hair stands up on the back of your neck.
>
> No, you may not assume this, unless the man page explicitly says so.
> Then it wouldn't be an assumption.
I disagree.
First, what a man page says isn't necessarily relevant; fgets()
is defined by the ISO C Standard. (If a particular man page says
something that's inconsistent with the standard, it may be either
an error in the man page or an admission of non-conformance.)
My own interpretation of the C standard is, in the absence of
I/O errors, fgets() may not write past the characters that it's
specified to read -- any more than it may write to any other object.
As I mentioned elsethread, I feel perfectly comfortable *assuming*
that sqrt() doesn't write to stdout, even though there's no explicit
statement that it doesn't do so.
--
Keith Thompson (The_Other_Keith)
kst- <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"