Email List: Xaustin-group-lX
[All Lists]

[1003.1(2008)/Issue 7 0000090]: fscanf stds contradiction

To: austin-group-l@xxxxxxxxxxxxx
Subject: [1003.1(2008)/Issue 7 0000090]: fscanf stds contradiction
From: Austin Group Bug Tracker <noreply@xxxxxxxxxxxxx>
Date: Wed, 1 Jul 2009 17:56:28 +0000
Keywords: [1003.1(2008)/Issue 7] System Interfaces
The following issue has been UPDATED. 
====================================================================== 
http://austingroupbugs.net/view.php?id=90 
====================================================================== 
Reported By:                geoffclare
Assigned To:                ajosey
====================================================================== 
Project:                    1003.1(2008)/Issue 7
Issue ID:                   90
Category:                   System Interfaces
Type:                       Error
Severity:                   Objection
Priority:                   normal
Status:                     Interpretation Required
Name:                       Geoff Clare 
Organization:               The Open Group 
User Reference:              
Section:                    fscanf 
Page Number:                934 
Line Number:                31304 
Final Accepted Text:        http://austingroupbugs.net/view.php?id=90#c135 
====================================================================== 
Date Submitted:             2009-06-29 17:38 UTC
Last Modified:              2009-07-01 17:56 UTC
====================================================================== 
Summary:                    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 Action: 
Change

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

---------------------------------------------------------------------- 
 (0000135) msbrown (manager) - 2009-06-29 17:39
 http://austingroupbugs.net/view.php?id=90#c135 
---------------------------------------------------------------------- 
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.

<Prev in Thread] Current Thread [Next in Thread>