Anonymous | Login | 2025-01-22 18:27 UTC |
Main | My View | View Issues | Change Log | Docs |
Viewing Issue Simple Details [ Jump to Notes ] | [ Issue History ] [ Print ] | ||||||
ID | Category | Severity | Type | Date Submitted | Last Update | ||
0000526 | [1003.1(2008)/Issue 7] System Interfaces | Objection | Clarification Requested | 2011-12-12 10:26 | 2019-06-10 08:55 | ||
Reporter | geoffclare | View Status | public | ||||
Assigned To | ajosey | ||||||
Priority | normal | Resolution | Accepted | ||||
Status | Closed | ||||||
Name | Geoff Clare | ||||||
Organization | The Open Group | ||||||
User Reference | |||||||
Section | calloc() | ||||||
Page Number | 627 | ||||||
Line Number | 21395, 21399 | ||||||
Interp Status | --- | ||||||
Final Accepted Text | |||||||
Summary | 0000526: Adopt C99 wording for zero size calloc(), malloc() et al. | ||||||
Description |
While correcting the application of 0000400 in the TC1 draft it was noticed that the wording related to the zero size case for calloc(), malloc() and realloc() is different in C99, which says: If the size of the space requested is zero, the behavior is implementation-defined: either a null pointer is returned, or the behavior is as if the size were some nonzero value, except that the returned pointer shall not be used to access an object. The C99 wording is better because it avoids explicit mention of passing the returned pointer to free(), thus ensuring there can be no doubt about whether the pointer can also be deallocated by realloc(). In fact, 0000400 already changes the realloc() DESCRIPTION wording to match C99 but does not remove the now-redundant mention of free() in the RETURN VALUE section. The proposed changes also make the errno handling for calloc() and malloc() more consistent with the realloc() change in 0000400, although using "may" because they don't have the same need for errno to indicate that the space was not freed. In addition they tidy up an editorial problem with duplicate statements in the 0000400 text about the returned pointer being used to access an object. (The statement is made once as "shall not be used" as in C99, and once as "the application shall ensure ..."; the changes turn the first one into a statement about undefined behaviour, since the second is the appropriate POSIX wording.) For consistency, similar changes should be made for posix_memalign(). |
||||||
Desired Action |
At page 627 line 21395 section calloc() page 1268 line 41713 section malloc() change: If the size of the space requested is 0, the behavior is implementation-defined: the value returned shall be either a null pointer or a unique pointer. to: If the size of the space requested is 0, the behavior is implementation-defined: either a null pointer shall be returned, or the behavior shall be as if the size were some nonzero value, except that the behavior is undefined if the returned pointer is used to access an object. At page 627 line 21399 section calloc() page 1268 line 41718 section malloc() change: either a null pointer or a unique pointer that can be successfully passed to free() shall be returned. to: either: * a null pointer shall be returned <CX>and errno may be set to an implementation-defined value</CX>, or * a pointer to the allocated space shall be returned. The application shall ensure that the pointer is not used to access an object. For realloc() ... After applying the page 1754 line 56030 change from 0000400, change: except that the returned pointer shall not be used to access an object. to: except that the behavior is undefined if the returned pointer is used to access an object. After applying the line 56047-8 change from 0000400, change: [a] unique pointer that can be successfully passed to free() shall be returned to: a pointer to the allocated space shall be returned At page 1418 line 46423 section posix_memalign() change: If the size of the space requested is 0, the behavior is implementation-defined; the value returned in memptr shall be either a null pointer or a unique pointer. to: If the size of the space requested is 0, the behavior is implementation-defined: either a null pointer shall be returned in memptr, or the behavior shall be as if the size were some nonzero value, except that the behavior is undefined if the the value returned in memptr is used to access an object. At page 1418 line 46429 section posix_memalign() after: an error number shall be returned to indicate the error. add the following new text: If size is 0, either: * posix_memalign() shall not attempt to allocate any space, in which case either an implementation-defined error number shall be returned, or zero shall be returned with a null pointer returned in memptr * posix_memalign() shall attempt to allocate some space and if the allocation succeeds, zero shall be returned and a pointer to the allocated space shall be returned in memptr. The application shall ensure that the pointer is not used to access an object. (Note that 0000520 proposes a change to the text that precedes this. I have worded this change in a way that ensures the two changes can be made independently.) |
||||||
Tags | c99, tc2-2008 | ||||||
Attached Files | |||||||
|
![]() |
|||||||||||||||||||||||||
|
Mantis 1.1.6[^] Copyright © 2000 - 2008 Mantis Group |