T
Thomas Baier
Hi there,
I'v got a little program generating coincidental lists. It crashes with
memory access failure, but not always at the same time.
If I start the programm using valgrind it always crashes after sorting the
first list with the following messages:
thomas@linux:~/Info/C++> valgrind list
/usr/bin/valgrind: line 106: exec: list: not found
thomas@linux:~/Info/C++> valgrind ./list
==7888== Memcheck, a.k.a. Valgrind, a memory error detector for x86-linux.
==7888== Copyright (C) 2002, and GNU GPL'd, by Julian Seward.
==7888== Using valgrind-1.9.5pre, a program instrumentation system for
x86-linux.
==7888== Copyright (C) 2000-2002, and GNU GPL'd, by Julian Seward.
==7888== Estimated CPU clock rate is 1809 MHz
==7888== For more details, rerun with: -v
==7888==
liste...ok //Ausgabe
des Programms
==7888== Invalid write of size 4
==7888== at 0x8048A28: List<int>::append(int) (lib/list.h:107)
==7888== by 0x80488B7: main (list.cpp:28)
==7888== by 0x4030D8AD: __libc_start_main (in /lib/libc.so.6)
==7888== by 0x8048710: (within /home/thomas/Info/C++/list)
==7888== Address 0x4112F060 is 0 bytes after a block of size 4 alloc'd
==7888== at 0x40162F43: malloc (in /usr/lib/valgrind/valgrind.so)
==7888== by 0x40163448: realloc (in /usr/lib/valgrind/valgrind.so)
==7888== by 0x80489F5: List<int>::append(int) (lib/list.h:103)
==7888== by 0x80488B7: main (list.cpp:28)
Append...ok
==7888==
==7888== Invalid read of size 4
==7888== at 0x8048A66: List<int>:ut() (lib/list.h:113)
==7888== by 0x80488E1: main (list.cpp:30)
==7888== by 0x4030D8AD: __libc_start_main (in /lib/libc.so.6)
==7888== by 0x8048710: (within /home/thomas/Info/C++/list)
==7888== Address 0x4112F060 is 0 bytes after a block of size 4 alloc'd
==7888== at 0x40162F43: malloc (in /usr/lib/valgrind/valgrind.so)
==7888== by 0x40163448: realloc (in /usr/lib/valgrind/valgrind.so)
==7888== by 0x80489F5: List<int>::append(int) (lib/list.h:103)
==7888== by 0x80488B7: main (list.cpp:28)
98 55 0 10 7 17 97 85 75 87 9 24 4 36 28 76 58 45 37 47 62 60 82 43 62 87 48
51 56 50 34 55 7 34 63 12 49 61 95 26 50 6 48 52 42 74 30 98 21 67 46 81 27
29 25 89 15 71 39 71 23 74 26 28 7 89 40 57 50 36 81 98 40 28 51 81 4 79 80
23 48 26 5 75 53 28 63 69 1 4 39 22 76 65 48 83 54 86 39 3
0________
Speicherzugriffsfehler
The methods of the list class is in short:
List <T>::List()
{
elements = NULL; //Array for saving the list elements
length = 0;
}
void List <T>::append(T newElement)
{
if((elements = (T*) realloc(elements, sizeof(T))) == NULL) {
printf("\n!!!Error!!!\n");
//Doesn't appear anytime
}
elements[length++] = newElement;
}
The code of my little program is:
main()
{
srand((unsigned) time(NULL));
for(int i=0;i<100;i++) {
cout << "liste...";
List <int> *a = new List<int>;
cout << "ok\n";
cout << "Append...";
for(int j=0;j<100;j++)
a->append(rand()%99);
cout << "ok\n";
a->out();
cout << "\n" << i << "________\n";
delete(a);
}
}
Thanks for any help
Thomas
I'v got a little program generating coincidental lists. It crashes with
memory access failure, but not always at the same time.
If I start the programm using valgrind it always crashes after sorting the
first list with the following messages:
thomas@linux:~/Info/C++> valgrind list
/usr/bin/valgrind: line 106: exec: list: not found
thomas@linux:~/Info/C++> valgrind ./list
==7888== Memcheck, a.k.a. Valgrind, a memory error detector for x86-linux.
==7888== Copyright (C) 2002, and GNU GPL'd, by Julian Seward.
==7888== Using valgrind-1.9.5pre, a program instrumentation system for
x86-linux.
==7888== Copyright (C) 2000-2002, and GNU GPL'd, by Julian Seward.
==7888== Estimated CPU clock rate is 1809 MHz
==7888== For more details, rerun with: -v
==7888==
liste...ok //Ausgabe
des Programms
==7888== Invalid write of size 4
==7888== at 0x8048A28: List<int>::append(int) (lib/list.h:107)
==7888== by 0x80488B7: main (list.cpp:28)
==7888== by 0x4030D8AD: __libc_start_main (in /lib/libc.so.6)
==7888== by 0x8048710: (within /home/thomas/Info/C++/list)
==7888== Address 0x4112F060 is 0 bytes after a block of size 4 alloc'd
==7888== at 0x40162F43: malloc (in /usr/lib/valgrind/valgrind.so)
==7888== by 0x40163448: realloc (in /usr/lib/valgrind/valgrind.so)
==7888== by 0x80489F5: List<int>::append(int) (lib/list.h:103)
==7888== by 0x80488B7: main (list.cpp:28)
Append...ok
==7888==
==7888== Invalid read of size 4
==7888== at 0x8048A66: List<int>:ut() (lib/list.h:113)
==7888== by 0x80488E1: main (list.cpp:30)
==7888== by 0x4030D8AD: __libc_start_main (in /lib/libc.so.6)
==7888== by 0x8048710: (within /home/thomas/Info/C++/list)
==7888== Address 0x4112F060 is 0 bytes after a block of size 4 alloc'd
==7888== at 0x40162F43: malloc (in /usr/lib/valgrind/valgrind.so)
==7888== by 0x40163448: realloc (in /usr/lib/valgrind/valgrind.so)
==7888== by 0x80489F5: List<int>::append(int) (lib/list.h:103)
==7888== by 0x80488B7: main (list.cpp:28)
98 55 0 10 7 17 97 85 75 87 9 24 4 36 28 76 58 45 37 47 62 60 82 43 62 87 48
51 56 50 34 55 7 34 63 12 49 61 95 26 50 6 48 52 42 74 30 98 21 67 46 81 27
29 25 89 15 71 39 71 23 74 26 28 7 89 40 57 50 36 81 98 40 28 51 81 4 79 80
23 48 26 5 75 53 28 63 69 1 4 39 22 76 65 48 83 54 86 39 3
0________
Speicherzugriffsfehler
The methods of the list class is in short:
List <T>::List()
{
elements = NULL; //Array for saving the list elements
length = 0;
}
void List <T>::append(T newElement)
{
if((elements = (T*) realloc(elements, sizeof(T))) == NULL) {
printf("\n!!!Error!!!\n");
//Doesn't appear anytime
}
elements[length++] = newElement;
}
The code of my little program is:
main()
{
srand((unsigned) time(NULL));
for(int i=0;i<100;i++) {
cout << "liste...";
List <int> *a = new List<int>;
cout << "ok\n";
cout << "Append...";
for(int j=0;j<100;j++)
a->append(rand()%99);
cout << "ok\n";
a->out();
cout << "\n" << i << "________\n";
delete(a);
}
}
Thanks for any help
Thomas