ICh habe 2-3 klassen (für exceptions) geschrieben und verwende den polymorphismus zur Fehlerausgabe! ... soweit so gut ....
ich hab die files geschrieben und jetzt bringt mir valgrind andauernd "Invalid read of size 1" als error und ich komm nicht darauf warum!! (ich steh wahrscheinlich ur auf der leitung)
könnt ihr mir helfen?
Code
==10892== Memcheck, a memory error detector.
==10892== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==10892== Using LibVEX rev 1732, a library for dynamic binary translation.
==10892== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==10892== Using valgrind-3.2.3, a dynamic binary instrumentation framework.
==10892== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==10892== For more details, rerun with: -v
==10892==
==10892== Invalid read of size 1
==10892== at 0x40235C8: strlen (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==10892== by 0x40D98EB: std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_tr
aits<char> >&, char const*) (in /usr/lib/libstdc++.so.6.0.9)
==10892== by 0x80492D0: main (in /home/strenkwalder/workspace/mymath/a.out)
==10892== Address 0x42A43A4 is 12 bytes inside a block of size 52 free'd
==10892== at 0x4022156: operator delete(void*) (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==10892== by 0x40E403C: std::string::_Rep::_M_destroy(std::allocator<char> const&) (in /usr/lib/libstdc++.so.6.0.9)
==10892== by 0x40E5FB9: std::string::~string() (in /usr/lib/libstdc++.so.6.0.9)
==10892== by 0x8049579: MathException::what() const (in /home/strenkwalder/workspace/mymath/a.out)
==10892== by 0x80492C0: main (in /home/strenkwalder/workspace/mymath/a.out)
==10892==
==10892== Invalid read of size 1
==10892== at 0x40235D3: strlen (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==10892== by 0x40D98EB: std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_tr
aits<char> >&, char const*) (in /usr/lib/libstdc++.so.6.0.9)
==10892== by 0x80492D0: main (in /home/strenkwalder/workspace/mymath/a.out)==10892== Address 0x42A43A5 is 13 bytes inside a block of size 52 free'd
==10892== at 0x4022156: operator delete(void*) (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==10892== by 0x40E403C: std::string::_Rep::_M_destroy(std::allocator<char> const&) (in /usr/lib/libstdc++.so.6.0.9)
==10892== by 0x40E5FB9: std::string::~string() (in /usr/lib/libstdc++.so.6.0.9)
==10892== by 0x8049579: MathException::what() const (in /home/strenkwalder/workspace/mymath/a.out)
==10892== by 0x80492C0: main (in /home/strenkwalder/workspace/mymath/a.out)
==10892==
==10892== Syscall param write(buf) points to unaddressable byte(s)
==10892== at 0x40007F2: (within /lib/ld-2.6.1.so)
==10892== by 0x41D0F14: (within /lib/libc-2.6.1.so)
==10892== by 0x41D11C5: _IO_file_xsputn (in /lib/libc-2.6.1.so)
==10892== by 0x41C715E: fwrite (in /lib/libc-2.6.1.so)
==10892== by 0x40D6CB5: (within /usr/lib/libstdc++.so.6.0.9)
==10892== by 0x40D96FE: std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, int) (in /usr/lib/libstdc++.so.6.0.9)
==10892== by 0x40D98FB: std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*) (in /usr/lib/libstdc++.so.6.0.9)
==10892== by 0x80492D0: main (in /home/strenkwalder/workspace/mymath/a.out)
==10892== Address 0x42A43A4 is 12 bytes inside a block of size 52 free'd
==10892== at 0x4022156: operator delete(void*) (in /usr/lib/valgrind/x86-linux/vgpreload_memcheck.so)
==10892== by 0x40E403C: std::string::_Rep::_M_destroy(std::allocator<char> const&) (in /usr/lib/libstdc++.so.6.0.9)
==10892== by 0x40E5FB9: std::string::~string() (in /usr/lib/libstdc++.so.6.0.9)
==10892== by 0x8049579: MathException::what() const (in /home/strenkwalder/workspace/mymath/a.out)
==10892== by 0x80492C0: main (in /home/strenkwalder/workspace/mymath/a.out)
Error: The result is out of Range: ***
==10892==
==10892== ERROR SUMMARY: 41 errors from 3 contexts (suppressed: 3 from 1)
==10892== malloc/free: in use at exit: 0 bytes in 0 blocks.
==10892== malloc/free: 5 allocs, 5 frees, 725 bytes allocated.
==10892== For counts of detected errors, rerun with: -v
==10892== All heap blocks were freed -- no leaks are possible.
Alles anzeigen
mian.cpp
Code
int main(int argc, char *argv[] ){
[COLOR='#ff0000']try{
throw OverflowException("MSG");
}catch(MathException &e){
cerr << e.what() << "\n";
}[/COLOR]
return EXIT_SUCCESS;
}
Code
#include "MathException.h"
MathException::MathException(const char *sz) throw(){
m_msg = sz;
}
MathException::~MathException() throw(){
}
[COLOR='Red']
const char* MathException::what() const throw(){
stringstream strs;
strs << "Error: " << m_errortyp.c_str() << ": " << m_msg.c_str();
return (strs.str()).c_str();
}[/COLOR]
Alles anzeigen
im markierten text muss ich irgend einen fehler gemacht haben
kann mir einer sagen was?