From: Lennart Jablonka <vol@ljabl.com>
To: Alejandro Colomar <alx@kernel.org>,
libc-alpha@sourceware.org, Eric Blake <eblake@redhat.com>
Cc: linux-man@vger.kernel.org
Subject: Re: LINE_MAX
Date: Mon, 20 May 2024 22:35:14 +0000 [thread overview]
Message-ID: <ZkvQIlVNJ-aYs9RI@fluorine> (raw)
In-Reply-To: <qjp55g4oisyltajr4hckjgqjfbfwx7w5jwfgpeuqhdghppxrft@khoxlratj7kl>
Quoth Alejandro Colomar:
>I think I found a bug in POSIX.1-2017 (and probably, previous ones too,
>but didn't check).
>
><https://pubs.opengroup.org/onlinepubs/009695399/basedefs/limits.h.html>:
> {LINE_MAX}
> Unless otherwise noted, the maximum length, in bytes, of a
> utility’s input line (either standard input or another
> file), when the utility is described as processing text
> files. The length includes room for the trailing <newline>.
> Minimum Acceptable Value: {_POSIX2_LINE_MAX}
>
>It doesn't say anything about the trailing null byte for the buffer that
>holds it, but I assume it doesn't include it, from the context.
>
>However:
><https://pubs.opengroup.org/onlinepubs/009695399/functions/fgets.html>:
>The following sections are informative.
>EXAMPLES
>
> Reading Input
>
> The following example uses fgets() to read each line of input. {LINE_MAX}, which defines the maximum size of the input line, is defined in the <limits.h> header.
>
> #include <stdio.h>
> ...
> char line[LINE_MAX];
> ...
> while (fgets(line, LINE_MAX, fp) != NULL) {
> ...
> }
> ...
>
>
>This example seems to contradict my understanding of what limits.h says.
>
>So, either limits.h should be explicit that the trailing null byte is
>also included in LINE_MAX, or the example is bogus and should be fixed.
>I guess it's the latter, although I wish it was the former, so we can
>avoid a +1 in the code.
>
>In any case, could you please forward this to the Austin group?
Good find. You aren’t the first one to find it:
https://austingroupbugs.net/view.php?id=182 discusses that
example a little. The desired action written there appears
verbatim (bar formatting) in the 4.1 draft of POSIX.1-202x.
next prev parent reply other threads:[~2024-05-20 22:35 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-20 21:49 LINE_MAX Alejandro Colomar
2024-05-20 22:26 ` LINE_MAX Vincent Lefevre
2024-05-21 10:08 ` LINE_MAX Alejandro Colomar
2024-05-21 11:40 ` LINE_MAX Vincent Lefevre
2024-05-20 22:35 ` Lennart Jablonka [this message]
2024-05-21 10:14 ` LINE_MAX Alejandro Colomar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=ZkvQIlVNJ-aYs9RI@fluorine \
--to=vol@ljabl.com \
--cc=alx@kernel.org \
--cc=eblake@redhat.com \
--cc=libc-alpha@sourceware.org \
--cc=linux-man@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).