Hallo.
Ein kleines Problem bei einem Programm.
Habe valgrind mal laufen lassen und folgenden Fehler, bei dem ich nicht
ganz verstehe, was er meint.
“Invalid read/write of size 8”. Vermutlich eine double Variable?
Was genau habe ich falsch gemacht? Das Programm selbst läuft wie es
sollte.
1 | valgrind ./a.out --leak-check=yes
|
2 | ==29373== Memcheck, a memory error detector
|
3 | ==29373== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
|
4 | ==29373== Using Valgrind-3.20.0 and LibVEX; rerun with -h for copyright info
|
5 | ==29373== Command: ./a.out --leak-check=yes
|
6 | ==29373==
|
7 |
|
8 | Array 1
|
9 | ==29373== Invalid read of size 8
|
10 | ==29373== at 0x4007F0: shift_array (in /home/michael/Documents/test/a.out)
|
11 | ==29373== by 0x400A5B: main (in /home/michael/Documents/test/a.out)
|
12 | ==29373== Address 0x4a6e090 is 0 bytes after a block of size 0 alloc'd
|
13 | ==29373== at 0x4838744: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
|
14 | ==29373== by 0x400A01: main (in /home/michael/Documents/test/a.out)
|
15 | ==29373==
|
16 | ==29373== Invalid write of size 8
|
17 | ==29373== at 0x40086A: shift_array (in /home/michael/Documents/test/a.out)
|
18 | ==29373== by 0x400A5B: main (in /home/michael/Documents/test/a.out)
|
19 | ==29373== Address 0x4a6e088 is 8 bytes before a block of size 0 alloc'd
|
20 | ==29373== at 0x4838744: malloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
|
21 | ==29373== by 0x400A01: main (in /home/michael/Documents/test/a.out)
|
22 | ==29373==
|
23 |
|
24 | Shift Array 1 left by 1
|
25 |
|
26 | Array 2 average
|
27 | ==29373==
|
28 | ==29373== HEAP SUMMARY:
|
29 | ==29373== in use at exit: 0 bytes in 0 blocks
|
30 | ==29373== total heap usage: 5 allocs, 5 frees, 1,056 bytes allocated
|
31 | ==29373==
|
32 | ==29373== All heap blocks were freed -- no leaks are possible
|
33 | ==29373==
|
34 | ==29373== For lists of detected and suppressed errors, rerun with: -s
|
35 | ==29373== ERROR SUMMARY: 2 errors from 2 contexts (suppressed: 0 from 0)
|