View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0001496 | 1003.1(2013)/Issue7+TC1 | System Interfaces | public | 2021-08-01 17:09 | 2024-06-11 08:54 |
Reporter | alanc | Assigned To | |||
Priority | normal | Severity | Comment | Type | Enhancement Request |
Status | Closed | Resolution | Accepted As Marked | ||
Name | Alan Coopersmith | ||||
Organization | Oracle Solaris Engineering | ||||
User Reference | |||||
Section | printf() | ||||
Page Number | (page or range of pages) | ||||
Line Number | (Line or range of lines) | ||||
Interp Status | --- | ||||
Final Accepted Text | See 0001496:0005543 | ||||
Summary | 0001496: Add asprintf() and vasprintf() | ||||
Description | The GNU C library has provided asprintf() and vasprintf() since at least 1991, and many other OS'es have added them as well since. These variants of sprintf() allocate new memory for the string, making it easier to have a safe usage without having to re-implement much of the printf format string handling logic to determine how much memory to allocate. These have been widely adopted in software trying to avoid buffer overflows: codesearch.debian.net finds 1713 software packages referencing asprintf(). GNU C library documentation: https://www.gnu.org/software/libc/manual/html_node/Dynamic-Output.html FreeBSD man page (added in 2.2 in 1997): https://www.freebsd.org/cgi/man.cgi?query=asprintf OpenBSD man page (added in 2.3 in 1998): https://man.openbsd.org/asprintf.3 NetBSD man page: https://man.netbsd.org/asprintf.3 Solaris man page (added in Solaris 10 Update 10 in 2011): https://docs.oracle.com/cd/E88353_01/html/E37843/asprintf-3c.html illumos man page: https://illumos.org/man/3c/asprintf | ||||
Desired Action | These functions should be added to the standard: #include <stdio.h> int asprintf(char **restrict strp, const char *restrict fmt, ...); int vasprintf(char **restrict strp, const char *restrict fmt, va_list ap); | ||||
Tags | issue8 | ||||
Attached Files |
|
Note that these functions (and corresponding aswprintf, vaswprintf) are in ISO/IEC TR 24731-2:2010, so care should be taken to be compatible with the versions there and to raise any issues with the interfaces through the liaison with WG14. Note also the known error handling issue (it's unspecified whether *ptr is set to NULL on error or left unchanged - apparently this is deliberate in TR 24731-2 to be compatible with multiple existing implementations that make different choices there). |
|
Thanks, I was unaware that asprintf() had been specified in that ISO TR. Of the above listed implementations, all but GNU libc document that they will set *ptr to NULL on error, while GNU libc explicitly states that you cannot rely on it to do so (and looking at its code, sometimes it does, sometimes it doesn't). |
|
I have attached the final draft of TR24731-2, and since this is an ISO document, it is sponsored by ISO. |
|
(Bugnote updated after the 2021-12-09 teleconference): Add pointer page for asprintf referencing fprintf. Add pointer page for vasprintf referencing vfprintf. On p909 line 30737 add asprintf to the title line. On P 909, before line 30740, add [CX]<tt>int asprintf(char ** restrict ptr, const char * restrict format, ...);</tt> (the next line, dprintf() is already CX shaded, so this extends the shading backwards). On line 30747, change Excluding dprintf( ): to Excluding asprintf() and dprintf(): Before line 30754 insert a new paragraph, CX shaded:
Before line 31016, Add a new paragraph, CX shaded:
At line 31021 append a sentence CX shaded:
Before line 31032 add:
Add CX shading to lines 31032-33. On page 920, APPLICATION USAGE, after line 31260 add a new paragraph:
On page 2212, line 70651 add vasprintf to the title line. Insert before line 70655 (extending the CX shading backwards a line) [CX] At line 70666, change
to
At line 70667, change
to
Note: Though the ISO TR includes aswprintf, no current implementations appear to provide this, so it is not included here. Additionally, such functionality is available using open_wmemstream, so invention here is really unecessary. |
Date Modified | Username | Field | Change |
---|---|---|---|
2021-08-01 17:09 | alanc | New Issue | |
2021-08-01 17:09 | alanc | Name | => Alan Coopersmith |
2021-08-01 17:09 | alanc | Organization | => Oracle Solaris Engineering |
2021-08-01 17:09 | alanc | Section | => printf() |
2021-08-01 17:09 | alanc | Page Number | => (page or range of pages) |
2021-08-01 17:09 | alanc | Line Number | => (Line or range of lines) |
2021-08-02 16:31 | jsm28 | Note Added: 0005427 | |
2021-08-03 19:19 | alanc | Note Added: 0005428 | |
2021-12-02 16:17 | nick | File Added: tr24731-2.pdf | |
2021-12-02 16:19 | nick | Note Added: 0005540 | |
2021-12-05 12:48 | nick | Note Added: 0005543 | |
2021-12-05 12:49 | nick | Note Edited: 0005543 | |
2021-12-05 12:49 | nick | Note Edited: 0005543 | |
2021-12-05 12:50 | nick | Note View State: 5543: public | |
2021-12-05 12:50 | nick | Note Edited: 0005543 | |
2021-12-09 16:39 | nick | Note Edited: 0005543 | |
2021-12-09 16:40 | nick | Interp Status | => --- |
2021-12-09 16:40 | nick | Final Accepted Text | => See 0001496:0005543 |
2021-12-09 16:40 | nick | Status | New => Resolved |
2021-12-09 16:40 | nick | Resolution | Open => Accepted As Marked |
2021-12-09 16:40 | nick | Tag Attached: issue8 | |
2022-01-13 10:05 | geoffclare | Status | Resolved => Applied |
2024-06-11 08:54 | agadmin | Status | Applied => Closed |