View Issue Details

IDProjectCategoryView StatusLast Update
00003841003.1(2008)/Issue 7Base Definitions and Headerspublic2016-07-28 15:10
Reportereblake Assigned Toajosey  
PrioritynormalSeverityObjectionTypeOmission
Status ClosedResolutionRejected 
NameEric Blake
OrganizationRed Hat
User Referenceebb.va_end
Sectionstdarg.h
Page Number339
Line Number11403
Interp Status---
Final Accepted Text
Summary0000384: the stdarg macros should not modify errno
DescriptionLine 25639 [XSH errno] is explicit that "The setting of errno after a
successful call to a function is unspecified unless the description of
that function specifies that errno shall not be modified." However, none
of the stdarg macros (va_start, va_copy, va_arg, va_end) mention their
interaction with errno, which renders common code like this undefined,
all because the successful va_end() invocation occurs between the point
of the failure and the actual error reporting:

// error-checking variant of snprintf
int xsnprintf(char *str, size_t size, const char *fmt, ...)
{
    va_list ap;
    int ret;

    va_start(ap, fmt);
    ret = vsprintf(str, size, fmt, ap);
    va_end(ap);
    if (ret < 0) {
        perror("vsprintf failed");
        exit(EXIT_FAILURE);
    }
    return ret;
}

Typically, all va_* macros have no effect on errno, so we might as well
require that, which would make the above example conforming.
Desired ActionAfter line 11403 [XCU <stdarg.h> DESCRIPTION], add a sentence with CX shading:

The four macros defined in this header shall not change the value of errno.
TagsNo tags attached.

Relationships

related to 0000401 Closedajosey ferror should not modify errno 
related to 0000385 Closedajosey free should not change errno on success 
related to 0000447 Closedajosey strerror_r and strerror_l error checking 
related to 0000397 Closedajosey setbuf and errno 
related to 0000511 Closedajosey getuid and friends should not modify errno 

Activities

eblake

2011-03-10 16:39

manager   bugnote:0000691

The intention is to match the C Standard, where the wording is:

(7.5 para 3) "The value of errno may be set to nonzero by a library
function call whether or not there is an error, provided the use of
errno is not documented in the description of the function in this
International Standard."

The use of "library function call" here makes it clear that it
does not apply to macros such as va_start().

It is worth creating a new bug that cleans up the use of the word
"function" throughout the standard (in some instances, such as htonl
on page 1097, the word "function" was used in the mathematical sense
of an interface that defines a mapping even though that interface
is only a C macro, rather than in the C sense of external linkage).

Issue History

Date Modified Username Field Change
2011-02-22 18:52 eblake New Issue
2011-02-22 18:52 eblake Status New => Under Review
2011-02-22 18:52 eblake Assigned To => ajosey
2011-02-22 18:52 eblake Name => Eric Blake
2011-02-22 18:52 eblake Organization => Red Hat
2011-02-22 18:52 eblake User Reference => ebb.va_end
2011-02-22 18:52 eblake Section => stdarg.h
2011-02-22 18:52 eblake Page Number => 339
2011-02-22 18:52 eblake Line Number => 11403
2011-02-22 18:52 eblake Interp Status => ---
2011-03-10 16:39 eblake Note Added: 0000691
2011-03-10 16:40 eblake Status Under Review => Closed
2011-03-10 16:40 eblake Resolution Open => Rejected
2016-07-28 15:06 eblake Relationship added related to 0000401
2016-07-28 15:06 eblake Relationship added related to 0000385
2016-07-28 15:07 eblake Relationship added related to 0000447
2016-07-28 15:08 eblake Relationship added related to 0000397
2016-07-28 15:10 eblake Relationship added related to 0000511