Austin Group Defect Tracker

Aardvark Mark IV


Viewing Issue Simple Details Jump to Notes ] Issue History ] Print ]
ID Category Severity Type Date Submitted Last Update
0000196 [1003.1(2008)/Issue 7] System Interfaces Editorial Error 2009-12-21 22:19 2013-04-16 13:06
Reporter eblake View Status public  
Assigned To ajosey
Priority normal Resolution Accepted As Marked  
Status Closed  
Name Eric Blake
Organization NA
User Reference ebb.getsubopt
Section getsubopt
Page Number 1079
Line Number 35965
Interp Status Approved
Final Accepted Text See Note: 0000409
Summary 0000196: improved getsubopt example
Description The getsubopt description is missing normative text on the value of *valuep when the function returns -1. It is unclear whether this is intentional, but it works well in light of the fact that there are at least two common implementations with different semantics: Solaris and GNU set *valuep to the entire suboption that did not match (whether or not the unrecognized suboption included an '=' to start a value); while BSD treats *valuep as if there was a match (it is set to either the first character after '=' or NULL) then uses an external variable suboptarg to track the entire suboption that did not match.

The getsubopt example has a use of getopt() and optarg, but fails to include <unistd.h> for their declarations. It also assumes the Solaris behavior, which will end up dereferencing a null pointer if getsubopt has the BSD behavior and the unrecognized suboption did not have a value. Fixing this without relying on the value of *valuep requires a temporary variable (in the desired action, optarg is reused for this purpose). Finally, the second example is effectively a subset of the first, while the first example lacks some explanatory text.

An alternative solution would be to add normative text that either mandates the contents of *valuep when getsubopt() returns -1 (Solaris behavior), or to standardize the external variable suboptarg (BSD behavior). If changes to normative wording is considered, then it should also be decided whether the BSD behavior of stripping spaces and tabs from the *optionp argument is deemed compliant.
Desired Action Consolidate the EXAMPLES section into one code snippet, by moving lines 36034-36036 (the subheading Parsing Suboptions and following paragraph) prior to the code example at 35965, and deleting lines 36037-36053 (the second code snippet).

After line 35966, insert another line:

#include <unistd.h>

After line 36003, insert two lines (creating a scoping block for the while statement):

{
    optarg = subopts;

After line 36026, insert a new line:

}

Adjust the indentation of lines 36004-36026 to reflect the new block.

Change line 36024 from:

printf("Unknown suboption `%s'\n", value);

to:

printf("Unknown suboption `%s'\n", optarg);

After line 36033, insert a new paragraph describing the previous example:

If the above example is invoked with:

program -o ro,rsize=512

then after option parsing, the variable do_all will be 0, type will be a null pointer, read_size will be 512, write_size will be 0, and read_only will be 1. If it is invoked with:

program -o oops

it will print "Unknown suboption `oops'" before aborting.

At line 36055 (APPLICATION USAGE), change:

None.

to:

The value of *valuep when getsubopt( ) returns -1 is unspecified. Historical implementations provide various incompatible extensions to allow an application to access the suboption text that was not found in the keylistp array.
Tags tc1-2008
Attached Files

- Relationships

-  Notes
(0000330)
eblake (manager)
2009-12-21 22:50

Additionally, there is a mismatch in const-ness between mount_opts and what getsubopt expects. One possibility is to change line 35979 from:

const char *mount_opts[] =

to:

char *mount_opts[] =

although this initializes char* from string literals and gives the false impression that the strings are modifyable; another possibility is to change line 36004 from:

switch(getsubopt(&subopts, mount_opts, &value))

to two lines:

/* Cast is safe, since getsubopt does not modify keylistp. */
switch(getsubopt(&subopts, (char**)mount_opts, &value))

Unfortunately, due to historical practice, it is probably a bit late to make a normative change to the signature of getsubopt, even if no existing implementations modify strings in keylistp.
(0000371)
drepper (reporter)
2010-01-07 16:38

The group thinks the replacement text should not misuse the variable optarg. You shouldn't assign a value to it. Instead create a separate variable.

As for the const issue: the group considers the cast in the getsubopt call more desirable.

Can you please update the issue and have one note explaining all the changes?
(0000406)
eblake (manager)
2010-03-25 20:13
edited on: 2010-09-28 15:15

At line 35941, extend the paragraph on keylistp with a new sentence:

The getsubopt( ) function shall not modify the keylistp vector.

Consolidate the EXAMPLES section into one code snippet, by moving lines 36034-36036 (the subheading Parsing Suboptions and following paragraph) prior to the code example at 35965; then delete lines 36037-36053 (the second code snippet).

After line 35966, insert another line:

#include <unistd.h>

At line 36003, replace:

while (*subopts != '\0')
    switch(getsubopt(&subopts, mount_opts, &value))

with this (creating a scoping block for the while statement, and adding a cast):

while (*subopts != '\0')
{
    char *saved = subopts;
    switch(getsubopt(&subopts, (char **)mount_opts, &value))

Change two lines at 36024 from:

printf("Unknown suboption `%s'\n", value);
break;

to:

printf("Unknown suboption `%s'\n", saved);
abort();

After line 36026, insert a new line:

}

Adjust the indentation of lines 36004-36026 to reflect the new block.

After line 36033, insert a new paragraph describing the previous example:

If the above example is invoked with:

program -o ro,rsize=512

then after option parsing, the variable do_all will be 0, type will be a null pointer, read_size will be 512, write_size will be 0, and read_only will be 1. If it is invoked with:

program -o oops

it will print "Unknown suboption `oops'" before aborting.

At line 36055 (APPLICATION USAGE), change:

None.

to:

The value of *valuep when getsubopt( ) returns -1 is unspecified. Historical implementations provide various incompatible extensions to allow an application to access the suboption text that was not found in the keylistp array.

At line 36057 (RATIONALE), change:

None.

to:

The keylistp argument of getsubopt( ) is typed as char * const * to match historical practice. However, the standard is clear that implementations will not modify either the array or the strings contained in the array, as if the argument had been typed const char * const *.

(0000409)
Don Cragun (manager)
2010-04-15 15:12
edited on: 2010-05-27 15:11

Interpretation response
------------------------

The standard does not speak to the issue of whether getsubopt() can modify the
keylistp vector, and as such no conformance distinction can be made between alternative implementations based on this. This is being referred to the sponsor.

Rationale:
-------------
None.

Notes to the Editor (not part of this interpretation):
-------------------------------------------------------
Implement the changes listed in Note: 0000406


- Issue History
Date Modified Username Field Change
2009-12-21 22:19 eblake New Issue
2009-12-21 22:19 eblake Status New => Under Review
2009-12-21 22:19 eblake Assigned To => ajosey
2009-12-21 22:19 eblake Name => Eric Blake
2009-12-21 22:19 eblake Organization => NA
2009-12-21 22:19 eblake User Reference => ebb.getsubopt
2009-12-21 22:19 eblake Section => getsubopt
2009-12-21 22:19 eblake Page Number => 1079
2009-12-21 22:19 eblake Line Number => 35965
2009-12-21 22:50 eblake Note Added: 0000330
2010-01-07 16:38 drepper Note Added: 0000371
2010-03-25 20:13 eblake Note Added: 0000406
2010-04-15 15:12 Don Cragun Interp Status => Pending
2010-04-15 15:12 Don Cragun Note Added: 0000409
2010-04-15 15:12 Don Cragun Status Under Review => Interpretation Required
2010-04-15 15:12 Don Cragun Resolution Open => Accepted As Marked
2010-04-15 15:13 Don Cragun Final Accepted Text => See Note: 0000409
2010-04-16 10:17 ajosey Interp Status Pending => Proposed
2010-05-27 15:11 ajosey Note Edited: 0000409
2010-05-28 14:02 ajosey Interp Status Proposed => Approved
2010-09-24 16:51 Don Cragun Tag Attached: issue8
2010-09-28 15:15 eblake Note Edited: 0000406
2010-10-07 15:09 Don Cragun Tag Detached: issue8
2010-10-07 15:09 Don Cragun Tag Attached: tc1-2008
2013-04-16 13:06 ajosey Status Interpretation Required => Closed


Mantis 1.1.6[^]
Copyright © 2000 - 2008 Mantis Group
Powered by Mantis Bugtracker