Base64 decode function: SIGSEGV, , Segmentation fault?

Up vote 0 down vote favorite share g+ share fb share tw.

This is a function decode the base64. SIGSEGV(sometimes it is SIGABORT) occurs at the line of the malloc called. It almost drive me crazy!

Thanks in advance. Static char base64_table255 = {'\0'}; static void base64_tableinit() { int i,j; bzero(base64_table,255); for(j=0,i='A';i0; clen--) { *res = base64_table(int)*cptr++>4 ; /* Use the 2th char(2) */ /// Construct the first char *res = base64_table(int)*cptr++>2 ; /* Use the 3th char(4) */ /// Construct the second char *res = base64_table(int)*cptr++ Switching to Thread 0xb71a2b70 (LWP 5432) 0xb7d450a6 in _int_malloc () from /lib/libc.so" rel="nofollow">libc.so" rel="nofollow">libc.so" rel="nofollow">libc.so.6 (gdb) bt 0 0xb7d450a6 in _int_malloc () from /lib/libc.so" rel="nofollow">libc.so" rel="nofollow">libc.so" rel="nofollow">libc.so.6 1 0xb7d4746c in malloc () from /lib/libc.so" rel="nofollow">libc.so" rel="nofollow">libc.so" rel="nofollow">libc.so.6 2 0x0804b04c in decode ( cptr=0x806dce8 "PGRpdiBzdHlsZT0ibGluZS1oZWlnaHQ6MS43O2NvbG9yOiMwMDAwMDA7Zm9udC1zaXplOjE0cHg7Zm9udC1mYW1pbHk6YXJpYWwiPuato+W4uCA8YnI+PC9kaXY+PGJyPjxicj48c3BhbiB0aXRsZT0ibmV0ZWFzZWZvb3RlciI+PHNwYW4gaWQ9Im5ldGVhc2VfbWFp"..., rptr=0xb71a1fa8) at base64. C:78 3 0x0804d5af in email_decode (email_old=0xb71a1ffc, email_new=0xb71a1d50) at email_handle.

C:421 4 0x0804a9c2 in PacketAnalyze () at packet_analyze. C:800 5 0xb7fa1cf2 in start_thread () from /lib/libpthread.so.0 6 0xb7da584e in clone () from /lib/libc.so" rel="nofollow">libc.so" rel="nofollow">libc.so" rel="nofollow">libc.so.6 c link|improve this question edited Dec 12 '11 at 12:21Joachim Pileborg13.3k1825 asked Dec 12 '11 at 11:45LouXiu9326 100% accept rate.

This: *(res+len-clen) = '\0'; seems wrong, since you've already incremented res all through the loop, it should probably just be *res = '\0.

Thanks a million times! :-) – LouXiu Dec 12 '11 at 12:21.

A segmentation fault in malloc is a fairly sure sign that either some wild memory corruption occurs or that someone frees a pointer to non-dynamically-allocated memory. Both errors did not necessarily happen in the code you show or the code that triggers the SIGSEGV. However, both errors are often detected by valgrind.

– LouXiu Dec 12 '11 at 11:57 @LouXiou: gcc reports no error here. Gcc finished its work when it finished compiling, it has nothing to do with running the program. The program crashes, it has broken memory allocation, and the broken allocation is probably at a wholly different place in the code.

– thiton Dec 12 '11 at 12:08 Sorry.. I mean the backtrace message reported by gdb. – LouXiu Dec 12 '11 at 12:16.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions