| Deutsch English Français Italiano |
|
<vog3lp$1sd7k$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: James Kuyper <jameskuyper@alumni.caltech.edu> Newsgroups: comp.lang.c Subject: Re: Buffer contents well-defined after fgets() reaches EOF ? Date: Tue, 11 Feb 2025 13:07:53 -0500 Organization: A noiseless patient Spider Lines: 20 Message-ID: <vog3lp$1sd7k$1@dont-email.me> References: <vo9g74$fu8u$1@dont-email.me> <vo9hlo$g0to$1@dont-email.me> <vo9khf$ggd4$1@dont-email.me> <vobf3h$sefh$2@dont-email.me> <vobjdt$t5ka$1@dont-email.me> <vobro1$u9fa$1@dont-email.me> <vobu9b$12bi8$1@dont-email.me> <voc9d7$13pam$2@dont-email.me> <vodi7t$1b6at$1@dont-email.me> <voe7kp$1f0us$3@dont-email.me> <voegdf$1hbn6$1@dont-email.me> <voel5v$1kp3m$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Injection-Date: Tue, 11 Feb 2025 19:08:06 +0100 (CET) Injection-Info: dont-email.me; posting-host="01ec9aaf418c6526623fa5ef7a4174c2"; logging-data="1979636"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18u4nhIO80J+bZnnd3DFN9RxPpJpRJcHbw=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:a4u5Fvr36oFqCZXeBPkwZ8w4CAU= Content-Language: en-US In-Reply-To: <voel5v$1kp3m$1@dont-email.me> Bytes: 2378 On 2/10/25 23:54, Lawrence D'Oliveiro wrote: > On Mon, 10 Feb 2025 22:33:03 -0500, James Kuyper wrote: .... >> "The fgets function reads at most one less than the number of characters >> specified by n from the stream pointed to by stream into the array >> pointed to by s." (7.32.7.2p2) >> >> If the buffer length is 1, "at most one less than the number ... >> specified" is 0. Therefore, fgets() cannot read any characters into the >> buffer, no matter what the contents of the input stream are. Again, >> since there is no "last byte read into the array", there is no location >> where a null byte should be written. > > Have you tried it? I have. I just tried it, using gcc and found that fgets() does set the first byte of the buffer to a null character. Therefore, it doesn't conform to the requirements of the standard. That's not particularly surprising - calling fgets with useless arguments isn't something that I'd expect to be a high priority on their pre-delivery tests.