.
Last update: 1997-05-20
9945-1-90 #19 Classification: Editorial defect _____________________________________________________________________________ Topic: static data - how volatile? Relevant Sections: 4.2.4.3 Defect Report: ----------------------- A number of interfaces (getlogin, getenv, ctermid, ttyname, getgid [sic, should be getgrgid], getgrnam, getpwuid, getpwnam) may be implemented to "point to static data [which], therefore, may be overwritten by each call." A naive interpretation would be that this applies to subsequent calls to the same interface. Another interpretation is that the data returned is completely volatile, and must be copied immediately after it's returned. Some existing implementations share the same static storage between different interfaces, so calling one interface can change the data pointed to by a pointer previously returned by a different interface. Do such implementations conform to the Standard? WG15 response for ISO/IEC 9945-1:1990 (IEEE Std 1003.1-1990) -------------------------------------------------- No, such implementations do not conform. However, it would be conforming for functions described within the same subclause to use the same static area. getgrgid() and getgruid() may use the same area, and getpwuid() and getpwnam() may use the same area, but getgrgid() and getpwuid() may not use the same area. Rationale for Interpretation: ----------------------------- Each of the sections in question contains text similar to that in subclause 9.2.1.3 (Returns for getgrgid() and getgrnam()): The return values may point to static data that is overwritten by each call. This is clearly referring to the functions described in 9.2.1, and does not mean that the data can be overwitten by each call to any function. The fact that getenv() and getgrgid() (for example) each return a pointer to a static area that may be overwritten by a subsequent call to the same function cannot be interpreted to mean that they may overwrite each others' data. The only ambiguity is in 9.2.1 and 9.2.2 (the get gr* and getpw* functions) where two functions are described together in one subclause. Does this mean that the data may be overwritten by the next call to either function, or the just next call to the same function? Must each function have its own static area? Since the standard does not clearly specify, it is conforming for the two to share a static area. (This is what was intended, since it is existing practice.) Editorial note for future revision of standard (not part of the interpretation) ------------------------------------------------------------------------------- Consider changing the existing wording to use similar wording to that in ISO C, making it clear that the application shall not modify the returned data, and specify which functions may share the static area. _____________________________________________________________________________