View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0000174 | 1003.1(2008)/Issue 7 | System Interfaces | public | 2009-10-29 18:21 | 2013-04-16 13:06 |
Reporter | drepper | Assigned To | ajosey | ||
Priority | normal | Severity | Objection | Type | Enhancement Request |
Status | Closed | Resolution | Accepted As Marked | ||
Name | Ulrich Drepper | ||||
Organization | Red Hat, Inc. | ||||
User Reference | ud-puts-overflow | ||||
Section | puts() | ||||
Page Number | 1723 | ||||
Line Number | 55058 | ||||
Interp Status | --- | ||||
Final Accepted Text | 0000174:0000298 | ||||
Summary | 0000174: puts for strings longer than INT_MAX | ||||
Description | Strings do not have a length limit and on systems with, say, 64-bit address space and int being 32-bit, the result of calls to puts with strings as parameter of length > INT_MAX is unspecified. We cannot return the number of written bytes because all successful calls must return a non-negative value. The same applies to fputs. | ||||
Desired Action | There are two ways out: - forbid such calls outright. In this case: 1. copy the ERRORS section for fputc to puts() and fputs(). 2. add new error case [EOVERFLOW] The string /s/ is too long. - truncate the write at INT_MAX characters and have the app handle this. | ||||
Tags | c99, tc1-2008 |
|
Discussed with some members of the C meeting after we adjourned ... general feeling is that this is undefined, and the EOVERFLOW error is an appropriate POSIX CX extension. |
|
The return value for fputs() and puts() is "a non-negative number" upon success. The description does not indicate that the value needs to be related to the number of characters written. |
|
Agreed, the value need not be the number of written bytes. But it'll break existing code to change that. Of course we can just return INT_MAX for all strings > INT_MAX. I guess this makes this a non-issue here. |
|
I agree no change to the normative text is needed, but I think we should add some rationale or app usage about this issue. Perhaps something like: "Traditionally puts() returned the number of bytes written. However, this 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 the following to the Application Usage section of puts(), p1723 after line 55077: "In some implementations puts() returned the number of bytes written. However, this 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." Also the same on page 908 after line 30373, with puts() changed to fputs(). |
Date Modified | Username | Field | Change |
---|---|---|---|
2009-10-29 18:21 | drepper | New Issue | |
2009-10-29 18:21 | drepper | Status | New => Under Review |
2009-10-29 18:21 | drepper | Assigned To | => ajosey |
2009-10-29 18:21 | drepper | Name | => Ulrich Drepper |
2009-10-29 18:21 | drepper | Organization | => Red Hat, Inc. |
2009-10-29 18:21 | drepper | User Reference | => ud-puts-overflow |
2009-10-29 18:21 | drepper | Section | => puts() |
2009-10-29 18:21 | drepper | Page Number | => 1723 |
2009-10-29 18:21 | drepper | Line Number | => 55058 |
2009-10-29 18:30 | nick | Tag Attached: c99 | |
2009-10-29 18:32 | nick | Note Added: 0000271 | |
2009-10-29 21:09 | cmsmith | Note Added: 0000272 | |
2009-10-29 22:58 | drepper | Note Added: 0000273 | |
2009-10-30 09:51 | geoffclare | Note Added: 0000274 | |
2009-11-12 16:38 | msbrown | Interp Status | => --- |
2009-11-12 16:38 | msbrown | Note Added: 0000298 | |
2009-11-12 16:38 | msbrown | Status | Under Review => Resolved |
2009-11-12 16:38 | msbrown | Resolution | Open => Accepted As Marked |
2009-11-12 16:39 | msbrown | Final Accepted Text | => 0000174:0000298 |
2010-08-27 13:05 | ajosey | Tag Attached: tc1-2008 | |
2011-04-21 16:37 | eblake | Relationship added | related to 0000412 |
2013-04-16 13:06 | ajosey | Status | Resolved => Closed |