View Issue Details

IDProjectCategoryView StatusLast Update
00000901003.1(2008)/Issue 7System Interfacespublic2013-04-16 13:06
Reportergeoffclare Assigned Toajosey  
PrioritynormalSeverityObjectionTypeError
Status ClosedResolutionAccepted As Marked 
NameGeoff Clare
OrganizationThe Open Group
User Reference
Sectionfscanf
Page Number934
Line Number31304
Interp StatusApproved
Final Accepted Text0000090:0000135
Summary0000090: fscanf stds contradiction
Description _____________________________________________________________________________
 OBJECTION Enhancement Request Number 20
 gwc:xxxxxxxxxxxxx Defect in XSH fscanf (rdvk# 5)
 [gwc fscanf return] Fri, 16 Jan 2009 10:55:11 +0000
 _____________________________________________________________________________

In austin-group-l 11809, Vincent Lefvre identified a conflict with
 the C Standard:

 ---- begin quote ----

 I think there is a contradiction between POSIX.1-2008 and the
 ISO C standard concerning fscanf when an input failure occurs
 after the first conversion.

 The ISO C standard (at least N1124 and N1336) says:


 7.19.6.2 The fscanf function

   4 The fscanf function executes each directive of the format in turn.
      If a directive fails, as detailed below, the function returns.
      Failures are described as input failures (due to the occurrence
      of an encoding error or the unavailability of input characters),
      or matching failures (due to inappropriate input).

  16 The fscanf function returns the value of the macro EOF if an
      input failure occurs before any conversion. Otherwise, the
      function returns the number of input items assigned, which can
      be fewer than provided for, or even zero, in the event of an
      early matching failure.

 For instance, let us consider

   n = fscanf (stdin, "%d %d", &x, &y);

 where an input failure occurs *after* the first %d conversion (and
 before the second one). According to the C standard, n should be
 equal to 1 because
   * the input failure occurred *after* the first conversion,
   * 1 input item (exactly) has been assigned.

 However POSIX.1-2008 says (page 934):

   Upon successful completion, these functions shall return the number
   of successfully matched and assigned input items; this number can be
   zero in the event of an early matching failure. If the input ends
   before the first matching failure or conversion, EOF shall be returned.
   If any error occurs, EOF shall be returned, and errno shall be set to
   indicate the error. If a read error occurs, the error indicator for
   the stream shall be set.

 I wonder what POSIX really means by "If any error occurs, EOF shall be
 returned [...]". I suppose this means "input failure" in C (as opposed
 to "matching failure"). But, as shown above, the C standard does the
 difference between these two kinds of failure only when the failure
 occurs before the first conversion (indeed one gets EOF in case of an
 input failure, and 0 in case of a matching failure).

 ---- end quote ----

 An interpretation should be issued stating that POSIX defers to the
 C Standard here, and conforming implementations must behave as
 described in the C Standard. The POSIX text should be corrected in
 TC1 to remove the conflict.

 During discussions it emerged that, by a strict reading, the
 phrase "before any conversion" is ambiguous, although the intention
 is clear (at least, it is to native English speakers). It was
 proposed to use the phrase "before the first successful conversion"
 instead, but this has a couple of problems:

 1. If the error occurs before the first conversion, then that
 conversion never happens and cannot be thought of as "successful".

 2. Even if the word "successful" is removed, it is still not clear


 whether the error has to occur before reading the first byte of
 input that would be used in the conversion, or if the requirement
 also applies after at least one such byte has been read but with
 more bytes needed to finish the conversion.

 I propose to use "without any successful conversions having been
 made" instead.
Desired ActionChange

     "If the input ends before the first matching failure or conversion,
     EOF shall be returned. If any error occurs, EOF shall be returned,
     [CX]and errno shall be set to indicate the error[/CX]. If a read
     error occurs, the error indicator for the stream shall be set."

 to

     "If the input ends without any successful conversions having been
     made, and without a matching failure having occurred, EOF shall be
     returned. If an error occurs without any successful conversions
     having been made, and without a matching failure having occurred,
     EOF shall be returned [CX]and errno shall be set to indicate the
     error[/CX]. If a read error occurs, the error indicator for the
     stream shall be set."

 Make the same change to the fwscanf() page (P988 L33162).
Tagsc99, tc1-2008

Activities

msbrown

2009-06-29 17:39

manager   bugnote:0000135

Last edited: 2009-10-12 05:45

Interpretation response
------------------------
The required behaviour of fscanf for this standard is dependent on the
requirements of the ISO C standard and conforming implementations must
behave as described in the C Standard. Concerns
have been raised about the fscanf function which are being referred to the sponsor.

Rationale:
-------------
This is a conflict with the C Standard.

Notes to the Editor (not part of this interpretation):
-------------------------------------------------------

Nick has progressed a proposal with WG14 which they appear
to have accepted as an editorial. We agreed that since its
been classified by WG14 as an editorial we can close this item.

Change from
     "If the input ends before the first matching failure or conversion,
     EOF shall be returned. If any error occurs, EOF shall be returned,
     [CX]and errno shall be set to indicate the error[/CX]. If a read
     error occurs, the error indicator for the stream shall be set."
to
    "If the input ends before the first conversion (if any) has
    completed, and without a matching failure having occurred, EOF
    shall be returned. If an error occurs before the first conversion (if any)
     has completed , and without a matching failure having occurred,
     EOF shall be returned [CX]and errno shall be set to indicate the
     error[/CX]. If a read error occurs, the error indicator for the
     stream shall be set."

Add to Change History :
A change to the second sentence in RETURN VALUE
is made to align with expected wording
changes in the next revision of the C standard.

(recommended for TC1)

nick

2010-11-05 14:26

manager   bugnote:0000605

Nick has progressed a proposal with WG14 which they appear
to have accepted as an editorial: this change is included in the Committee Draft of the C1x standard now entering ballot.

Issue History

Date Modified Username Field Change
2009-06-29 17:38 msbrown New Issue
2009-06-29 17:38 msbrown Status New => Under Review
2009-06-29 17:38 msbrown Assigned To => ajosey
2009-06-29 17:38 msbrown Name => Mark Brown
2009-06-29 17:38 msbrown Organization => IBM
2009-06-29 17:38 msbrown Section => fscanf
2009-06-29 17:38 msbrown Page Number => 934
2009-06-29 17:38 msbrown Line Number => 31304
2009-06-29 17:39 msbrown Note Added: 0000135
2009-06-29 17:39 msbrown Status Under Review => Interpretation Required
2009-06-29 17:39 msbrown Resolution Open => Accepted As Marked
2009-06-29 17:40 msbrown Final Accepted Text => 0000090:0000135
2009-07-01 17:56 Don Cragun Name Mark Brown => Geoff Clare
2009-07-01 17:56 Don Cragun Organization IBM => The Open Group
2009-07-01 17:56 Don Cragun Reporter msbrown => geoffclare
2009-08-06 16:33 nick Tag Attached: c99
2009-08-11 16:37 Don Cragun Interp Status => Pending
2009-09-17 15:41 nick Interp Status Pending => Proposed
2009-10-12 05:45 ajosey Note Edited: 0000135
2009-10-12 05:45 ajosey Interp Status Proposed => Approved
2010-09-20 09:26 geoffclare Tag Attached: tc1-2008
2010-11-05 14:26 nick Note Added: 0000605
2013-04-16 13:06 ajosey Status Interpretation Required => Closed