Bug 204207 - getsubopt invalid parsing
Summary: getsubopt invalid parsing
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 9.3-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
Depends on:
Reported: 2015-11-02 00:16 UTC by optionally_encouraged
Modified: 2015-11-02 00:16 UTC (History)
0 users

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description optionally_encouraged 2015-11-02 00:16:52 UTC
Following code will have invalid output.

#include <stdio.h>
#include <stdlib.h>

int main()
    char text[] = "text=1 2";
    char* subopts = text;
    char* line_subopts[] = {"text", 0};
    char* subopt_value;
    int opt = ::getsubopt(&subopts, line_subopts, &subopt_value);
    printf("%d, %s\n", opt, subopt_value);
    return 0;

$ clang++ bug.cpp
$ ./a.out
0, 1

Same thing happens with g++. I've tried on other platforms and it correctly outputs "0, 1 2"