public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* LINE_MAX
@ 2024-05-20 21:49 Alejandro Colomar
  2024-05-20 22:26 ` LINE_MAX Vincent Lefevre
  2024-05-20 22:35 ` LINE_MAX Lennart Jablonka
  0 siblings, 2 replies; 6+ messages in thread
From: Alejandro Colomar @ 2024-05-20 21:49 UTC (permalink / raw)
  To: libc-alpha, Eric Blake; +Cc: linux-man

[-- Attachment #1: Type: text/plain, Size: 1621 bytes --]

Hi Eric!

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?

Have a lovely night!
Alex

-- 
<https://www.alejandro-colomar.es/>

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-05-21 11:40 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` LINE_MAX Lennart Jablonka
2024-05-21 10:14   ` LINE_MAX Alejandro Colomar

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).