Here is the code, which just creates a dynamic array? fills it? and prints.
At the end-point? when doing 'free(digits);' I get a debug messge. But the programm continues to work, or it crashes only on free?
How do I need to change the source-code, not to recieve a message from debugger?
Sorry for bad English.
Thanks in advance.
SOURCE:
#include <stdio.h>
#include <stdlib.h>
using namespace std;
int main() {
unsigned int N;
unsigned int M;
int *digits;
unsigned int i=0;
unsigned int k=0;
printf("\n Type in the number of Numbers: N=");
scanf("%u", &N);
printf(" Type in the number of moves: M=");
scanf("%u", &M);
digits = (int *)(calloc(M, sizeof(int)));
for(i=0; i<N; i++) {
printf(" Type in the %u-th digit: D=", i);
scanf("%d", &digits[i]);
}
printf("You see following digits:");
for (k=0, i=M; k<10; k++, i++) {
i=i%N;
printf(" %u", digits[i]);
}
free(digits);
return 0;
}
WHAT I GET:
[sergey@localhost
ebug]$ ./Wonder
Type in the number of Numbers: N=12
Type in the number of moves: M=7
Type in the 0-th digit: D=1
Type in the 1-th digit: D=2
Type in the 2-th digit: D=3
Type in the 3-th digit: D=4
Type in the 4-th digit: D=5
Type in the 5-th digit: D=6
Type in the 6-th digit: D=7
Type in the 7-th digit: D=8
Type in the 8-th digit: D=9
Type in the 9-th digit: D=0
Type in the 10-th digit: D=7
Type in the 11-th digit: D=7
*** glibc detected *** ./Wonder: free(): invalid next size (fast): 0x0804a008 ***
======= Backtrace: =========
/lib/i686/cmov/libc.so.6[0xb7658624]
/lib/i686/cmov/libc.so.6(cfree+0x96)[0xb765a826]
./Wonder(__gxx_personality_v0+0x23f)[0x80488db]
/lib/i686/cmov/libc.so.6(__libc_start_main+0xe5)[0xb7600455]
./Wonder(__gxx_personality_v0+0x35)[0x80486d1]
======= Memory map: ========
08048000-08049000 r-xp 00000000 08:05 810018 /home/sergey/workspace/Wonder/Debug/Wonder
08049000-0804a000 rw-p 00000000 08:05 810018 /home/sergey/workspace/Wonder/Debug/Wonder
0804a000-0806b000 rw-p 00000000 00:00 0 [heap]
b7400000-b7421000 rw-p 00000000 00:00 0
b7421000-b7500000 ---p 00000000 00:00 0
b75e9000-b75ea000 rw-p 00000000 00:00 0
b75ea000-b773f000 r-xp 00000000 08:06 312640 /lib/i686/cmov/libc-2.7.so
b773f000-b7740000 r--p 00155000 08:06 312640 /lib/i686/cmov/libc-2.7.so
b7740000-b7742000 rw-p 00156000 08:06 312640 /lib/i686/cmov/libc-2.7.so
b7742000-b7745000 rw-p 00000000 00:00 0
b7745000-b7751000 r-xp 00000000 08:06 303148 /lib/libgcc_s.so.1
b7751000-b7752000 rw-p 0000b000 08:06 303148 /lib/libgcc_s.so.1
b7752000-b7753000 rw-p 00000000 00:00 0
b7753000-b7777000 r-xp 00000000 08:06 312644 /lib/i686/cmov/libm-2.7.so
b7777000-b7779000 rw-p 00023000 08:06 312644 /lib/i686/cmov/libm-2.7.so
b7779000-b785c000 r-xp 00000000 08:06 1746050 /usr/lib/libstdc++.so.6.0.10
b785c000-b785f000 r--p 000e2000 08:06 1746050 /usr/lib/libstdc++.so.6.0.10
b785f000-b7861000 rw-p 000e5000 08:06 1746050 /usr/lib/libstdc++.so.6.0.10
b7861000-b7867000 rw-p 00000000 00:00 0
b788b000-b788f000 rw-p 00000000 00:00 0
b788f000-b7890000 r-xp 00000000 00:00 0 [vdso]
b7890000-b78aa000 r-xp 00000000 08:06 303106 /lib/ld-2.7.so
b78aa000-b78ac000 rw-p 0001a000 08:06 303106 /lib/ld-2.7.so
bfe1e000-bfe33000 rw-p 00000000 00:00 0 [stack]
You see following digits: 8 9 0 7 7 1 2 3 4 5Аварийный останов
"Аварийный останов" -- is "Emergency stop" but in Russian. (I'm russian).