Menu

Array >> operator, infinite loop bug

2011-11-11
2012-09-15
  • paintbucket

    paintbucket - 2011-11-11

    So I am investigating a bug in a project here at work. This perticular problem
    having to do with parsing using IT++.

    I was trying to parse a sequence of type itpp::Array< itpp::Vec< int > >
    having the form

    "{ [1 2 3] [4 5 6] [7 8 9] }"
    

    and it seems like having an extra whitespace character just before the last
    "}" will cause the array to end up as

    {[1 2 3] [4 5 6] [7 8 9] [0]}
    

    Not quite what I expected, but not the most disastrous bug I found...

    Now, I set up an independent dummy project to test this out ran some tests,
    only to find out that I wound up in an infinite loop in the Array::operator>>
    method... And looking at the code, I can see how it happens: when the next
    character is not a comma, the istream is putback, and then re-read at the same
    character, over and over again, causing the loop!

    Am I onto something disastrous here or am I missing something? Seeing that it
    is late on a friday afternoon I am starting to suspect that last option...

    my small test program:

    int main() {
    
        std::stringstream stream;
        stream << "{ [1 2 3] [4 5 6] [7 8 9] }";
    
        itpp::Array<int> arr;
        stream >> arr;
    
        std::cout << arr << std::endl;
    }
    
     
  • paintbucket

    paintbucket - 2011-11-11

    Heh, late in the afternoon indeed. 1 minute after posting I realized that my
    type I was trying to parse to wasn't Array<Vec<int>> at all, but Array<int>...

    Move along, nothing to see here...! :D

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.