Skip to contentSkip to conversation

sscanf.3: Document exact matching for %c

PATCH In review Florian Weimer 3 participants 3 messages Nov 28, 2025 – Dec 1, 2025 Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sscanf.3: Document exact matching for %c

The glibc manual has always documented this behavior, but the implementation differed, treating the field width as an upper limit.

---
 man/man3/sscanf.3 | 7 +++++++
 1 file changed, 7 insertions(+)
man/man3/sscanf.3 +7 -0
index f0b248518..fa4cd0db7 100644
@@ -172,6 +172,9 @@ and these discarded characters don't count toward the maximum field width.
 String input conversions store a terminating null byte (\[aq]\[rs]0\[aq])
 to mark the end of the input;
 the maximum field width does not include this terminator.
+Some conversions require exactly
+the number of characters specified in the maximum field width,
+or they fail.
 .TP
 \[bu]
 An optional
@@ -480,6 +483,10 @@ and there must be enough room for all the characters
 (no terminating null byte is added).
 The usual skip of leading white space is suppressed.
 To skip white space first, use an explicit space in the format.
+.\" glibc commit 2b16c76609350ec887d49afd4447743da38f7fab
+This conversion only succeeds
+if the number of characters specified by the maximum field
+can be matched.
 .TP
 .B \&[
 Matches a nonempty sequence of characters from the specified set of

base-commit: 081d4f6779ac39da0265cac6e67d1c9a281e6990

Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Florian Weimer

The glibc manual has always documented this behavior, but the implementation differed, treating the field width as an upper limit.

LGTM and is better than before.

Quoted 9 lines
---
  man/man3/sscanf.3 | 7 +++++++
  1 file changed, 7 insertions(+)
man/man3/sscanf.3 +0 -0
index f0b248518..fa4cd0db7 100644

man/man3/sscanf.3 and these discarded characters don't count toward the maximum field width. · line 177

Quoted 6 lines
man/man3/sscanf.3 +3 -0
@@ -172,6 +172,9 @@ and these discarded characters don't count toward the maximum field width.
  String input conversions store a terminating null byte (\[aq]\[rs]0\[aq])
  to mark the end of the input;
  the maximum field width does not include this terminator.
+Some conversions require exactly
+the number of characters specified in the maximum field width,
+or they fail.

OK. Correct, in particular "%c" operates this way.

man/man3/sscanf.3 and there must be enough room for all the characters · line 489

Quoted 11 lines
man/man3/sscanf.3 +4 -0
  .TP
  \[bu]
  An optional
@@ -480,6 +483,10 @@ and there must be enough room for all the characters
  (no terminating null byte is added).
  The usual skip of leading white space is suppressed.
  To skip white space first, use an explicit space in the format.
+.\" glibc commit 2b16c76609350ec887d49afd4447743da38f7fab
+This conversion only succeeds
+if the number of characters specified by the maximum field
+can be matched.

OK. Adds clarifying text to the "c" specificer text later in the page.

Quoted 7 lines
man/man3/sscanf.3 +0 -0
  .TP
  .B \&[
  Matches a nonempty sequence of characters from the specified set of

base-commit: 081d4f6779ac39da0265cac6e67d1c9a281e6990

Signature · 2 lines
Cheers,
Carlos.
#2 lore raw

Hi Florian, Carlos,

Quoted 9 lines · Carlos O'Donell
Quoted 4 lines · Florian Weimer

The glibc manual has always documented this behavior, but the implementation differed, treating the field width as an upper limit.

LGTM and is better than before.

Thanks! I've applied the patch, and appended the tag.

Have a lovely day!
Alex

Quoted 47 lines
Quoted 10 lines
---
  man/man3/sscanf.3 | 7 +++++++
  1 file changed, 7 insertions(+)
man/man3/sscanf.3 +0 -0
index f0b248518..fa4cd0db7 100644

man/man3/sscanf.3 and these discarded characters don't count toward the maximum field width. · line 177

Quoted 6 lines
man/man3/sscanf.3 +3 -0
@@ -172,6 +172,9 @@ and these discarded characters don't count toward the maximum field width.
  String input conversions store a terminating null byte (\[aq]\[rs]0\[aq])
  to mark the end of the input;
  the maximum field width does not include this terminator.
+Some conversions require exactly
+the number of characters specified in the maximum field width,
+or they fail.

OK. Correct, in particular "%c" operates this way.

man/man3/sscanf.3 and there must be enough room for all the characters · line 489

Quoted 11 lines
man/man3/sscanf.3 +4 -0
  .TP
  \[bu]
  An optional
@@ -480,6 +483,10 @@ and there must be enough room for all the characters
  (no terminating null byte is added).
  The usual skip of leading white space is suppressed.
  To skip white space first, use an explicit space in the format.
+.\" glibc commit 2b16c76609350ec887d49afd4447743da38f7fab
+This conversion only succeeds
+if the number of characters specified by the maximum field
+can be matched.

OK. Adds clarifying text to the "c" specificer text later in the page.

Quoted 7 lines
man/man3/sscanf.3 +0 -0
  .TP
  .B \&[
  Matches a nonempty sequence of characters from the specified set of

base-commit: 081d4f6779ac39da0265cac6e67d1c9a281e6990

Signature · 2 lines
Cheers,
Carlos.
Signature · 2 lines
<https://www.alejandro-colomar.es>
Use port 80 (that is, <...:80/>).