Hi.
Im trying to malloc memory so that I can create an array of characters, making a word, but when the execution gets to my malloc line, it complains hardcore. (This is C btw, not C++)

Here is the portion of code it gets too, and here is the output dump it gives. Any ideas?:

counter = 0;
nullChecker = 1;
while( nullChecker != 0 )
{
nullChecker = wordArray[codeWord+offset+counter+1];
counter++;
}
printf("counter value: %d\n",counter);
// execution gets here, setting counter to 6 (observed from printf above)
unsigned char *string = malloc(counter + 1);
// using gdb, the program gets here, and suddenly breaks after executing the previous line...
int k;
for(k = 0; k < counter; k++){
unsigned int letterTmp;
letterTmp = wordArray[codeWord+offset+k+1];
printf("string: $s", letterTmp);
string[k] = (char)letterTmp;
}





the output is:
*** glibc detected *** ./a.out: malloc(): memory corruption: 0x09eee098 ***
======= Backtrace: =========
/lib/libc.so.6[0x4f6016]
/lib/libc.so.6(__libc_malloc+0x95)[0x4f7765]
./a.out[0x8048c5f]
./a.out[0x80492aa]
/lib/libc.so.6(__libc_start_main+0xe5)[0x49a6e5]
./a.out[0x80484f1]
======= Memory map: ========
001b5000-001b6000 r-xp 001b5000 00:00 0 [vdso]
0045f000-0047f000 r-xp 00000000 08:03 1815090 /lib/ld-2.9.so
00480000-00481000 r--p 00020000 08:03 1815090 /lib/ld-2.9.so
00481000-00482000 rw-p 00021000 08:03 1815090 /lib/ld-2.9.so
00484000-005f2000 r-xp 00000000 08:03 1815105 /lib/libc-2.9.so
005f2000-005f4000 r--p 0016e000 08:03 1815105 /lib/libc-2.9.so
005f4000-005f5000 rw-p 00170000 08:03 1815105 /lib/libc-2.9.so
005f5000-005f8000 rw-p 005f5000 00:00 0
00dab000-00db8000 r-xp 00000000 08:03 1815184 /lib/libgcc_s-4.3.2-20081105.so.1
00db8000-00db9000 rw-p 0000c000 08:03 1815184 /lib/libgcc_s-4.3.2-20081105.so.1
08048000-0804a000 r-xp 00000000 08:13 16499129 /home/csu/sbb27/cs520/Prog2/a.out
0804a000-0804b000 rw-p 00001000 08:13 16499129 /home/csu/sbb27/cs520/Prog2/a.out
09eee000-09f0f000 rw-p 09eee000 00:00 0 [heap]
b7f00000-b7f21000 rw-p b7f00000 00:00 0
b7f21000-b8000000 ---p b7f21000 00:00 0
b8090000-b8092000 rw-p b8090000 00:00 0
b80a3000-b80a4000 rw-p b80a3000 00:00 0
bfb3a000-bfb4f000 rw-p bffeb000 00:00 0 [stack]
Abort




Thank you in advanced...