Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

#200 Parser::get/itpp::vec does not handle empty string correct

release_4.0.x
wont-fix
5
2013-05-23
2011-10-19
David Westlund
No

Hi

Passing the empty string as a istringstream to an itpp::vec results in an uninitialized memory read.

Example code:

include <itpp itbase.h="">

include <istream>

int main()
{
itpp::vec a = "0.0";
std::string str = "";
std::istringstream buffer(str);

buffer >> a;

return 0;
}


valgrind <binary> gives the following output:
==20073== Conditional jump or move depends on uninitialised value(s)
==20073== at 0x41BAAF: std::istream& itpp::operator>><double>(std::istream&, itpp::Vec<double>&)

This operation is done in Parser::get, see parser.h row 211:
http://itpp.sourceforge.net/stable/parser_8h_source.html

The uninitialized memory read goes away if an space is added to the string, ie:
std::string str = " ";

Discussion

  • Bogdan Cristea
    Bogdan Cristea
    2011-11-21

    I am unable to reproduce with valgrind the reported issue. Could you clarify which valgrind tool have you used and which options. Also the above snippet is equivalent to

    itpp::vec a = "0.0";
    a.set_size(0, false);

    which does exactly what it should: the internal memory of the vector is freed and the internal array is initialized to NULL.

     
  • Bogdan Cristea
    Bogdan Cristea
    2011-11-25

    the reported issue is not a bug, a local variable was not initialized and this might cause the errors detected with valgrind

     
  • Bogdan Cristea
    Bogdan Cristea
    2013-05-23

    • status: open --> wont-fix