I am getting a rediculous console error I dont understand on the following code
I have a structure that looks like this
Code:
struct courses{
int courseNumber;
char courseCode[5];
double rating_interest;
double rating_teaching;
double rating_evaluation;
double rating_birdFactor;
int voteCast_Count;
double rating_total_interest;
double rating_total_teaching;
double rating_total_evaluation;
double rating_total_birdfactor;
}courses[__COURSE__AMOUNT__];
Where __COURSE__AMOUNT__ is a macro.
I have a function with the code
Code:
courses[i].voteCast_Count += 1;
This will produce the core dump message
Code:
*** glibc detected *** ./srate: free(): invalid pointer: 0x0804b008 ***
======= Backtrace: =========
/lib/tls/i686/cmov/libc.so.6[0xb7ed17cd]
/lib/tls/i686/cmov/libc.so.6(cfree+0x90)[0xb7ed4e30]
/lib/tls/i686/cmov/libc.so.6(fclose+0x134)[0xb7ec0844]
./srate[0x8048d71]
./srate[0x8049984]
/lib/tls/i686/cmov/libc.so.6(__libc_start_main+0xdc)[0xb7e7febc]
./srate[0x8048b31]
======= Memory map: ========
08048000-0804a000 r-xp 00000000 08:01 8390941 /home/aaron/C/
0804a000-0804b000 rw-p 00001000 08:01 8390941 /home/aaron/C/
0804b000-0806c000 rw-p 0804b000 00:00 0 [heap]
b7d00000-b7d21000 rw-p b7d00000 00:00 0
b7d21000-b7e00000 ---p b7d21000 00:00 0
b7e5d000-b7e68000 r-xp 00000000 08:01 8339520 /lib/libgcc_s.so.1
b7e68000-b7e69000 rw-p 0000a000 08:01 8339520 /lib/libgcc_s.so.1
b7e69000-b7e6a000 rw-p b7e69000 00:00 0
b7e6a000-b7fa5000 r-xp 00000000 08:01 8342756 /lib/tls/i686/cmov/libc-2.5.so
b7fa5000-b7fa6000 r--p 0013b000 08:01 8342756 /lib/tls/i686/cmov/libc-2.5.so
b7fa6000-b7fa8000 rw-p 0013c000 08:01 8342756 /lib/tls/i686/cmov/libc-2.5.so
b7fa8000-b7fab000 rw-p b7fa8000 00:00 0
b7fb8000-b7fba000 rw-p b7fb8000 00:00 0
b7fba000-b7fd3000 r-xp 00000000 08:01 8339477 /lib/ld-2.5.so
b7fd3000-b7fd5000 rw-p 00019000 08:01 8339477 /lib/ld-2.5.so
bfa79000-bfa8f000 rw-p bfa79000 00:00 0 [stack]
ffffe000-fffff000 r-xp 00000000 00:00 0 [vdso]
Aborted (core dumped)
Whereas the following code after the code above in the same function works
Code:
courses[i].rating_total_interest = courses[i].rating_total_interest + (double)atoi(token);
courses[i].rating_interest = courses[i].rating_total_interest / courses[i].voteCast_Count;
has no crash and performs as expected.
Why is this and how can I resolve it?