Valgrind detects invalid values ​​in strlen

I use Valgrind to detect memory leaks / errors in my library, and this is the first time I have ever used it. This seems to indicate that there are some invalid values ​​in std::string .

Here is the beginning of the error message

 ==16214== Invalid read of size 1 ==16214== at 0x402701D: strlen (mc_replace_strmem.c:282) ==16214== by 0x40E53AA: std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&) (in /usr/lib/i386-linux-gnu/libstdc++.so.6.0.14) ==16214== by 0x42FD03E: LHAPDF::Fortran_PDF_Base::initAlphasPDF() (Fortran_PDF_Base.C:290) 

The rest is just feedback. The line that is my code is the constructor of a structure that takes two std::string as arguments.

I do not believe that std::string can do something wrong, so what could be a possible problem?

Edit structure constructor:

 AlphaS_Info() {} AlphaS_Info(bool fixed, Order order, std::string method, std::string symbol, double alfasQ, int alfasQParm, double Q0, double mc, double mb, double mt) : m_fixed(fixed), m_order(order), m_method(method), m_symbol(symbol), m_mc(mc), m_mb(mb), m_mt(mt), m_alfasQ(alfasQ), m_Q0(Q0), m_alfasQParm(alfasQParm) {} 

Constructor call:

 p_info->p_asinfo = new LHAPDFTOOLS::AlphaS_Info(fixed, evoOrder, method, symbol, alfasQ, alfasQParm, Q0, cmass, bmass, tmass); 
+4
source share
1 answer

You probably passed an invalid string to your constructor, for example, using a pointer / link to a string that has already been deleted.

+8
source

All Articles