Issue Details (XML | Word | Printable)

Key: STDCXX-640
Type: Bug Bug
Status: Open Open
Priority: Minor Minor
Assignee: Unassigned
Reporter: Farid Zaripov
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
C++ Standard Library

std::num_get::do_get() parses no more than 128 characters

Created: 02/Nov/07 06:15 PM   Updated: 14/May/08 04:45 PM
Return to search
Component/s: 22. Localization
Affects Version/s: 4.1.2, 4.1.3, 4.1.4, 4.2.0
Fix Version/s: 4.2.2

Time Tracking:
Original Estimate: 4h
Original Estimate - 4h
Remaining Estimate: 4h
Remaining Estimate - 4h
Time Spent: Not Specified
Remaining Estimate - 4h

File Attachments:
  Size
Text File Licensed for inclusion in ASF works stdcxx-640.patch 2008-04-17 07:49 PM Farid Zaripov 11 kB
Environment: All
Issue Links:
Dependants
 

Patch Info: Patch Available
Severity: Incorrect Behavior


 Description  « Hide
The following program fails on assert.
#include <cassert>
#include <sstream>
#include <string>

int main ()
{
    typedef std::num_get<char> NumGet;
    typedef std::istreambuf_iterator<char> Iter;

    std::locale loc;

    for (unsigned i = 0; i < 10000; ++i) {
        std::string s (i, '0');
        s.push_back ('1');

        std::istringstream is (s);

        std::ios::iostate state = std::ios::goodbit;
        long val = 0;

        std::use_facet<NumGet> (loc).get (Iter (is), Iter (), is, state, val);
        assert (1 == val && std::ios::eofbit == state);
    }

    return 0;
}


 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Farid Zaripov added a comment - 02/Nov/07 06:19 PM
The reason is the fixed size buffer in num_get<_CharT, _InputIter>::_C_get(), _num_get.cc, line 253.

Travis Vitek added a comment - 02/Nov/07 10:16 PM
I don't necessarily think this is a problem with the fixed buffer size. It seems more like a problem of not skipping unnecessary zeros.

Martin Sebor added a comment - 02/Nov/07 11:41 PM
In this specific case we could just skip the leading zeros but there are other cases it wouldn't work (e.g., 1<N random digits>e-<N> should parse and evaluate to 1 for any value of N).

Farid Zaripov added a comment - 03/Apr/08 06:57 PM
Disabled formatting.
Set Fix Version's to 4.2.1.

Farid Zaripov added a comment - 03/Apr/08 07:29 PM
Martin, are you sure that 10e-1 should be parsed into 1 instead of 10?

I've tested on MSVC with native STL and STLport and both returned 10 instead of 1.

From the standard (22.2.2.1.2 p3):

Stage 3: The result of stage 2 processing can be one of
— A sequence of chars has been accumulated in stage 2 that is converted (according to the rules of scanf)
to a value of the type of val . This value is stored in val and ios_base::goodbit is stored in err .

The following code assigns lvar to 10 on MSVC:

long lvar;
scanf ("10e-1", "%ld", &lvar);

Martin Sebor added a comment - 03/Apr/08 07:41 PM
That depends if it's being parsed as an integer or floating point number. If the former, it should be 10, otherwise 1.

Farid Zaripov added a comment - 17/Apr/08 07:49 PM - edited
The patch is attached.

ChangeLog:

	STDCXX-640
	* include/loc/_num_get.cc (_C_get): Increase size of the __buf and __grpbuf using __rw::__rw_tmpbuf() if needed.
	* include/rw/_tmpbuf.h: New header file with a declaration of the __rw::__rw_tmpbuf().
	* include/rw/_rawiter.h: #include <rw/_tmpbuf.h> for declaring __rw::__rw_tmpbuf().
	* src/tmpbuf.cpp: Ditto.

Martin Sebor added a comment - 23/Apr/08 05:18 AM
Too late to fix in 4.2.1 but should consider for 4.2.2 if appropriate due to binary compatibility constraints.