#1059873 glibc-doc-reference: 12.14.5 String Input Conversions: The ‘%[’ conversion requires 1 match

#1059873#5
Date:
2024-01-02 18:24:11 UTC
From:
To:
Dear Maintainer,

*** Reporter, please consider answering these questions, where appropriate ***

   * What led up to the situation?

I used %s conversion to print a string to a file
and %7[^] conversion to scan it back.

   * What exactly did you do (or not do) that was effective (or
     ineffective)?

fscanf (tf, "%7[^]", b) == 01

   * What was the outcome of this action?

false

   * What outcome did you expect instead?

true

*** End of the template - remove these template lines ***

#1059873#10
Date:
2024-01-03 15:13:43 UTC
From:
To:
It is not clear whether the format string "%[\0a]" matches the input
string "a" or not.  I interpret the documentation as saying that once
the selector "%[ " has been opened, the format interpreter must find a
matching "]", therefore it must not interpret the embedded "\0" as the
end of the format string. However, trying to use such a format string
causes the compiler to report the warning "format contains NUL", which
suggests that using such a format string involves undefined behaviour.

#1059873#15
Date:
2024-01-04 15:37:08 UTC
From:
To:
Hi,

%7[^] is not a valid format string. Quoting the manual, section 12.14.5:

  To read in characters that belong to an arbitrary set of your choice,
  use the ‘%[’ conversion. You specify the set between the ‘[’ character
  and a following ‘]’ character, using the same syntax used in regular
  expressions for explicit sets of characters. As special cases:

  - A literal ‘]’ character can be specified as the first character of the set.

[...]

  - If a caret character ‘^’ immediately follows the initial ‘[’, then
    the set of allowed input characters is everything except the
    characters listed.

In your case, you want to match up to 7 characters, but given there is
no character or list of characters after the caret, it's not clear what
you want to achieve. If you want to match everything but a ‘[’, you
should use %7[^]] .

Regards,
Aurelien

#1059873#20
Date:
2024-01-04 15:38:17 UTC
From:
To:
Hi,

According to the C standard, \0 or the NUL character is the end of
string. Therefore the string passed to fscanf is simply "%[", which is
invalid.

As explained above, the compiler is right about that.

Regards
Aurelien

#1059873#25
Date:
2024-01-04 16:22:58 UTC
From:
To:
Hi,

This is the basic of the C language. It has nothing to do with the GNU
libc.

I disagree there. This documentation is about the GNU C library, not a
basic C course.

Regards
Aurelien

#1059873#30
Date:
2024-01-04 19:44:57 UTC
From:
To:
Hi,

We are here talking about *string* functions of the C standard. String
functions in this context are defined as NULL terminated. The beginning
of section 12.14 makes clear that the argument of the fscanf function is
a format *string*.

The argz functions do not operate on strings. They operate on *vector of
strings*. See section 5.15.

Indeed you are allow to use your own convention for a library, but But a
string is well defined in the C standard in the context of the string
functions.

Regards
Aurelien

#1059873#35
Date:
2024-01-04 19:48:14 UTC
From:
To:
Hi,

Your definition of "empty set" is quite vague. What you want is clearly
defined in the section 12.14.3, that is %7s or %7S.

I don't see how things can be improved further. But if you have a
wording suggestion, please submit one. Otherwise, I'll just close the
bug.

Regards
Aurelien