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



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:

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


  • 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

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks