problem of a program.

lijr07

Hi, I wrote a program to do some computation of complicated polynomials. But there are some problems. I use gdb to debug the program. When the input are small, there is no problem.

When the input are large or many factors have the same subscript (for example, input 5 for m, then input 7 8 9 6 8 9 5 8 9 4 7 8 9 3 4 5, then 5 for n, then 4 5 6 7 8 9 6 7 8 5 6 7 4 8 9, then first part of the program can work, m=Y^{9}_{3,4}Y^{4}_{7,8}Y^{5}_{8,9}Y^{6}_{8,9}Y^{7}_{8,9}
simplify(m)=Y^{9}_{3,4}Y^{4}_{7,8}Y^{11}_{8,9}
n=Y^{4}_{5,6}Y^{5}_{6,7}Y^{6}_{7,8}Y^{4}_{8,9}Y^{7}_{8,9}
FM=Y^{9}_{3,4}Y^{4}_{7,8}Y^{11}_{8,9}
), the following segmentation fault occurs. I do not know how to fix it. Thank you very much.

Program received signal SIGSEGV, Segmentation fault.
0x0019d98a in ?? () from /lib/libc.so.6
(gdb) backtrace
#0 0x0019d98a in ?? () from /lib/libc.so.6
#1 0x0019ff33 in malloc () from /lib/libc.so.6
#2 0x08048a89 in initial_polynomial () at test18.c:38
#3 0x080497ba in add_polynomials (a=0x804d148, b=0x804d128) at test18.c:708
#4 0x08049b01 in main (argc=1, argv=0xbffff3f4) at test18.c:823
(gdb) frame 3
#3 0x080497ba in add_polynomials (a=0x804d148, b=0x804d128) at test18.c:708
(gdb) l
703
704
705
706 polynomial add_polynomials(polynomial a, polynomial b)
707 {
709 polynomial_node *c=NULL, *p=NULL, *s=NULL;
710
712
\$1 = (polynomial) 0x804d148
\$2 = (monomial) 0x804d008
\$3 = {l = 0, i = 0, k = 0}
(gdb) print s->m->next->y
(gdb) print s->m->next
(gdb) print s->m

Last edited:

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.