View Issue Details

IDProjectCategoryView StatusLast Update
00004122008-TC1System Interfacespublic2013-04-16 13:12
Reportercmsmith Assigned Toajosey  
PrioritynormalSeverityObjectionTypeError
Status ClosedResolutionAccepted As Marked 
Product VersionDraft 1 
NameCurtis Smith
Organization
User Referencecms-puts
Sectionputs
Page Number0
Line Number3845-3854
Interp Status---
Final Accepted TextSee 0000412:0000785
Summary0000412: application note suggests impossible return value for input strings of length MAX_INT characters
DescriptionAnyone adopting this application note would have a problem handling
the case where the input string length is MAX_INT which would result
in MAX_INT+1 bytes being written (because of the appended '\n'),
yet tha value of MAX_INT+1 cannot be represented in the int return value.

This application note and the proposed note for its companion fputs()
seem to suggest that there is a new preferred embodiment for selecting
the return value of this function, which seems beyond the scope of
a technical corrigendum. Adding the notes to puts() and fputs()
without adding a note to fputws() seems inappropriately inconsistent.
Desired ActionDelete lines 3845-3854 and lines 2291-2300 (similar change in fputs which does not have the impossible return value problem but done for consistency).

Alternatively, change 2298 "for strings of up to INT_MAX bytes" to
"strings of up to INT_MAX-2 bytes". And add additional text: In
other implementations puts() returned a positive value of the last
byte written (always '\n' for puts) or
a fixed non-negative value; these conventions are
fine and do not need to be changed. Application writers should
treat all non-negative return values the same and not assume
additional semantics for the value without first having verified
the convention used by the particular execution environment. Also,
for parallelism, change fputws() to have s similar application note
with the limit "For wide strings of up to ((MAX_INT-1)/sizeof(wchar_t)) characters,...". Also add to the rationale for each of fputs(),
"The fputs() function is one whose source code was specified in
_The C Programming Language_ by Brian W. Kernighan and Dennis M.
Ritchie. In the original edition, the function had no defined
return value, yet many practical implementations would, as a
side effect, return the value of the last character written as that
was the value remaining in the accumulator used as a return value.
In the second edition of the book, either the fixed value 0 or EOF
would be returned depending upon the return value of ferror();
however, for compatibility with extant implementations, several
implementations would, upon success, return, upon success, a
positive value representing last byte written."
TagsNo tags attached.

Relationships

related to 0000174 Closedajosey 1003.1(2008)/Issue 7 puts for strings longer than INT_MAX 

Activities

nick

2011-05-19 15:41

manager   bugnote:0000785

Last edited: 2011-05-19 15:43

Append to the APPLICATION USAGE for puts (page 1723, line 55077),
fputs (p908 l30373), and fputws (p912 l30489) as follows:

This volume of POSIX.1-2008 requires that successful completion simply
return a non-negative integer. There are at least three known different
implementation conventions for this requirement:
 * Return a constant value.
 * Return the last character written.
 * Return the number of bytes written. Note that this implementation
   convention cannot be adhered to for strings longer than {INT_MAX}
   bytes as the value would not be representable in the return type of
   the function. For backwards compatibility, implementations can return
   the number of bytes for strings of up to INT_MAX bytes, and return
   INT_MAX for all longer strings.



Add to the RATIONALE for fputs:
The fputs() function is one whose source code was specified in
_The C Programming Language_ by Brian W. Kernighan and Dennis M.
Ritchie. In the original edition, the function had no defined
return value, yet many practical implementations would, as a
side effect, return the value of the last character written as that
was the value remaining in the accumulator used as a return value.
In the second edition of the book, either the fixed value 0 or EOF
would be returned depending upon the return value of ferror();
however, for compatibility with extant implementations, several
implementations would, upon success, return a
positive value representing last byte written.

ajosey

2011-06-10 09:58

manager   bugnote:0000814

This change is applied to TC1 draft 2

Issue History

Date Modified Username Field Change
2011-04-21 12:02 cmsmith New Issue
2011-04-21 12:02 cmsmith Status New => Under Review
2011-04-21 12:02 cmsmith Assigned To => ajosey
2011-04-21 12:02 cmsmith Name => Curtis Smith
2011-04-21 12:02 cmsmith User Reference => cms-puts
2011-04-21 12:02 cmsmith Section => puts
2011-04-21 12:02 cmsmith Page Number => 0
2011-04-21 12:02 cmsmith Line Number => 3845-3854
2011-04-21 16:37 eblake Relationship added related to 0000174
2011-05-19 15:41 nick Note Added: 0000785
2011-05-19 15:43 nick Note Edited: 0000785
2011-05-19 15:45 nick Interp Status => ---
2011-05-19 15:45 nick Final Accepted Text => See 0000412:0000785
2011-05-19 15:45 nick Status Under Review => Resolved
2011-05-19 15:45 nick Resolution Open => Accepted As Marked
2011-06-10 09:58 ajosey Note Added: 0000814
2011-06-10 09:58 ajosey Status Resolved => Applied
2013-04-16 13:12 ajosey Status Applied => Closed