Menu

#46 Bug in string->sparse_polynom conversion

Release 2.2.9
open
None
7
2010-07-17
2010-07-17
No

Where: trunk #417, Version 2.2.9.412.

Incorrect work of initialization of sparse_polynom, sparse_multipolynom from a string literal. For example: sparse_polynom<rational<> > p1 = "x + 2*x^2" gives x in p1 instead of x + 2*x^2, or sparse_multipolynom<rational<> > p2 = "x^(0, 1) + 2*x^(1, 0)" gives only x^(0, 1) in p2 instead of entire input polynom. Note that the same polynomials are input correctly from a std::cin.

A short investigation of the problem gives that bug is likely located at src/arageli/io.cpp : 112. It is an incomplete stream state clean that works correctly when we are inputting from a console stream, but fails when we are inputting from a stringstream (that is the case for initialization by a string literal in the examples above).

Discussion

  • Alexander Pshenichnikov

    The problem is how we use function istream::putback(ch). In existing code there is an assumption that this call is always succesfull regardless the fact if ch matches the previously retrieved character or not. It's not true for istringstream, function putback has no effect if the character being put back does not match the character in the buffer.
    In this partucular example, the problem happens when we are reading second monom. We read '+', then (unsuccesfully) try to read variable 'x', then putback '2', then try to putback '+', but it fails, since '+' does not match ' ' (space).

     
  • Sergey S. Lyalin

    Added reproducer at #453.

     

Log in to post a comment.

MongoDB Logo MongoDB