Skip to contentSkip to conversation

scanf.3: clarify that %n supports type modifiers

PATCH In review Alyssa Ross 2 participants 2 messages Mar 28, 2021 – Mar 30, 2021 Man-pages: manual pages for Linux -- Sections 2, 3, 4, 5, and 7

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 scanf.3: clarify that %n supports type modifiers

My initial reading of this was that type modifiers were probably not supported. But they are, and this is actually documented further up, in the type modifiers documentation. But to make it clearer, let's copy the language that printf(3) has in its %n section.

---
I plan to submit a similar clarification to the glibc documentation.

 man3/scanf.3 | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
man3/scanf.3 +3 -1
index f353f1d4d..8c0a1fa84 100644
@@ -513,18 +513,20 @@ circumflex, in) set or when the field width runs out.
 .TP
 .B n
 Nothing is expected; instead, the number of characters consumed thus far
 from the input is stored through the next pointer, which must be a pointer
 to
-.IR int .
+.IR int ,
+or variant whose size matches the (optionally)
+supplied integer length modifier.
 This is
 .I not
 a conversion and does
 .I not
 increase the count returned by the function.
 The assignment can be suppressed with the
 .B *
 assignment-suppression character, but the effect on the
 return value is undefined.
 Therefore
 .B %*n
 conversions should not be used.
Signature · 1 line
2.30.0
#1 lore raw

Hello Alyssa,

Quoted 6 lines · Alyssa Ross

My initial reading of this was that type modifiers were probably not supported. But they are, and this is actually documented further up, in the type modifiers documentation. But to make it clearer, let's copy the language that printf(3) has in its %n section.

Patch applied.

Thanks,

Alex

Quoted 33 lines

---
I plan to submit a similar clarification to the glibc documentation.

  man3/scanf.3 | 4 +++-
  1 file changed, 3 insertions(+), 1 deletion(-)
man3/scanf.3 +3 -1
index f353f1d4d..8c0a1fa84 100644
@@ -513,18 +513,20 @@ circumflex, in) set or when the field width runs out.
  .TP
  .B n
  Nothing is expected; instead, the number of characters consumed thus far
  from the input is stored through the next pointer, which must be a pointer
  to
-.IR int .
+.IR int ,
+or variant whose size matches the (optionally)
+supplied integer length modifier.
  This is
  .I not
  a conversion and does
  .I not
  increase the count returned by the function.
  The assignment can be suppressed with the
  .B *
  assignment-suppression character, but the effect on the
  return value is undefined.
  Therefore
  .B %*n
  conversions should not be used.
Signature · 3 lines
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/