View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0000412 | 2008-TC1 | System Interfaces | public | 2011-04-21 12:02 | 2013-04-16 13:12 |
Reporter | cmsmith | Assigned To | ajosey | ||
Priority | normal | Severity | Objection | Type | Error |
Status | Closed | Resolution | Accepted As Marked | ||
Product Version | Draft 1 | ||||
Name | Curtis Smith | ||||
Organization | |||||
User Reference | cms-puts | ||||
Section | puts | ||||
Page Number | 0 | ||||
Line Number | 3845-3854 | ||||
Interp Status | --- | ||||
Final Accepted Text | See 0000412:0000785 | ||||
Summary | 0000412: application note suggests impossible return value for input strings of length MAX_INT characters | ||||
Description | Anyone 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 Action | Delete 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." | ||||
Tags | No tags attached. |
|
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. |
|
This change is applied to TC1 draft 2 |
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 |